From 88b4d9f62fe8dc933c11c674cee90ceb6794545f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 29 Oct 2011 16:45:27 +0200 Subject: [PATCH] only open timelines needed to computed average color for clips --- pandora/annotation/models.py | 2 +- pandora/archive/extract.py | 11 ++++++----- pandora/item/models.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index bdca993d9..0322057d4 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -161,5 +161,5 @@ class Annotation(models.Model): return j def __unicode__(self): - return u"%s/%s-%s" %(self.item, self.start, self.end) + return u"%s %s-%s" %(self.public_id, self.start, self.end) diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index 8133946e3..1c952ffe0 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -294,11 +294,12 @@ def average_color(prefix, start=0, end=0): timelines = sorted(filter(lambda t: t!= '%s%sp.png'%(prefix,height), glob("%s%sp*.png"%(prefix, height)))) for image in timelines: start_offset = 0 - timeline = Image.open(image).convert('RGB') - frames += timeline.size[0] - if start and frames < start: + if start and frames + 1500 < start: + frames += 1500 continue - elif start and frames > start > frames-timeline.size[0]: + timeline = Image.open(image) + frames += timeline.size[0] + if start and frames > start > frames-timeline.size[0]: start_offset = start - (frames-timeline.size[0]) box = (start_offset, 0, timeline.size[0], height) timeline = timeline.crop(box) @@ -307,7 +308,7 @@ def average_color(prefix, start=0, end=0): box = (0, 0, end_offset, height) timeline = timeline.crop(box) - p = np.asarray(timeline, dtype=np.float32) + p = np.asarray(timeline.convert('RGB'), dtype=np.float32) p = np.sum(p, axis=0) / height #average color per frame pixels.append(p) diff --git a/pandora/item/models.py b/pandora/item/models.py index 1b79a700e..c7d8bf27d 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -935,7 +935,7 @@ class Item(models.Model): def make_timeline(self): streams = self.streams() - if len(streams) > 1: + if streams.count() > 1: timelines = [s.timeline_prefix for s in self.streams()] join_timelines(timelines, self.timeline_prefix)