only open timelines needed to computed average color for clips

This commit is contained in:
j 2011-10-29 16:45:27 +02:00
parent 121d2e30dc
commit 88b4d9f62f
3 changed files with 8 additions and 7 deletions

View file

@ -161,5 +161,5 @@ class Annotation(models.Model):
return j return j
def __unicode__(self): 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)

View file

@ -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)))) timelines = sorted(filter(lambda t: t!= '%s%sp.png'%(prefix,height), glob("%s%sp*.png"%(prefix, height))))
for image in timelines: for image in timelines:
start_offset = 0 start_offset = 0
timeline = Image.open(image).convert('RGB') if start and frames + 1500 < start:
frames += timeline.size[0] frames += 1500
if start and frames < start:
continue 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]) start_offset = start - (frames-timeline.size[0])
box = (start_offset, 0, timeline.size[0], height) box = (start_offset, 0, timeline.size[0], height)
timeline = timeline.crop(box) timeline = timeline.crop(box)
@ -307,7 +308,7 @@ def average_color(prefix, start=0, end=0):
box = (0, 0, end_offset, height) box = (0, 0, end_offset, height)
timeline = timeline.crop(box) 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 p = np.sum(p, axis=0) / height #average color per frame
pixels.append(p) pixels.append(p)

View file

@ -935,7 +935,7 @@ class Item(models.Model):
def make_timeline(self): def make_timeline(self):
streams = self.streams() streams = self.streams()
if len(streams) > 1: if streams.count() > 1:
timelines = [s.timeline_prefix for s in self.streams()] timelines = [s.timeline_prefix for s in self.streams()]
join_timelines(timelines, self.timeline_prefix) join_timelines(timelines, self.timeline_prefix)