improved cut detection

This commit is contained in:
rolux 2012-03-06 20:59:44 +01:00
parent 0f482ac8c4
commit afa51f7971

View file

@ -329,17 +329,21 @@ def average_color(prefix, start=0, end=0):
color = list(map(float, color)) color = list(map(float, color))
return ox.image.getHSL(color) return ox.image.getHSL(color)
def average_volume(prefix, start=0, end=0): def average_volume(prefix, start=0, end=0):
#FIXME: actually compute volume #FIXME: actually compute volume
return 0 return 0
def get_distance(rgb0, rgb1): def get_distance(rgb0, rgb1):
# rgb distance, normalized so that black/white equals 1
dst = math.sqrt(pow(rgb0[0] - rgb1[0], 2) + pow(rgb0[1] - rgb1[1], 2) + pow(rgb0[2] - rgb1[2], 2)) dst = math.sqrt(pow(rgb0[0] - rgb1[0], 2) + pow(rgb0[1] - rgb1[1], 2) + pow(rgb0[2] - rgb1[2], 2))
return dst / math.sqrt(3 * pow(255, 2)) return dst / math.sqrt(3 * pow(255, 2))
def cuts(prefix): def cuts(prefix):
cuts = [] cuts = []
distances = [0]
fps = 25 fps = 25
frames = 0 frames = 0
height = 64 height = 64
@ -350,19 +354,19 @@ def cuts(prefix):
timeline = Image.open(image) timeline = Image.open(image)
frames += timeline.size[0] frames += timeline.size[0]
pixels.append(timeline.load()) pixels.append(timeline.load())
for frame in range(0, frames): for frame in range(1, frames):
x = frame % width x = frame % width
if frame > 0: distance = 0
dst = 0 image0 = int((frame - 1) / width)
image0 = int((frame - 1) / width) image1 = int(frame / width)
image1 = int(frame / width) for y in range(height):
for y in range(0, height): rgb0 = pixels[image0][(x - 1) % width, y]
rgb0 = pixels[image0][(x - 1) % width, y] rgb1 = pixels[image1][x, y]
rgb1 = pixels[image1][x, y] distance += get_distance(rgb0, rgb1)
dst += get_distance(rgb0, rgb1) / height distances.append(distance / height)
#print frame / fps, dst for frame in range(1, frames):
if dst > 0.1: if distances[frame] >= 0.025 and abs(distances[frame] - distances[frame - 1]) >= 0.05:
cuts.append(frame / fps) cuts.append(frame / fps)
return cuts return cuts