使用PIL逐帧分析视频

时间:2012-03-22 03:09:42

标签: python image-processing python-imaging-library

我正在使用PIL来平均视频子区域的像素强度。我想做的是:

- 使用ffmpeg将视频转换为多个帧
- 使用PIL在每个框架中选择一个窗口(这是我需要帮助的步骤)
- 在每个框架中对该窗口进行某种分析,并汇总数据(例如,平均颜色与时间)

我对如何做中间步骤感到十分茫然 - 有没有人有建议?

1 个答案:

答案 0 :(得分:0)

使用Tkinter找到解决方案:

import Tkinter
import Image, ImageDraw, ImageTk

window = Tkinter.Tk()
window.title('Calcium Imaging Software')

mouse_X = 0
mouse_Y = 0
ellipseBox = []
listOfCircles = []

#stuff to set up the image
image = Image.open("test.jpg")
draw = ImageDraw.Draw(image)
canvas = Tkinter.Canvas(window, width=image.size[0], height=image.size[1])
canvas.pack()
image_tk = ImageTk.PhotoImage(image)
canvas.create_image(image.size[0]//2, image.size[1]//2, image=image_tk)

#define a function to be run on the mouseclick
def drawEllipse(event):
    global ellipseBox
    print "clicked at: ", event.x, event.y
    mouse_X = event.x
    mouse_Y = event.y
    ellipseBox.append((mouse_X,mouse_Y))
    print "box corners: ",ellipseBox
    #When two corners are selected, draw the ellipse
    if len(ellipseBox) == 2:
        draw.ellipse(ellipseBox,outline=(255,255,255))
        listOfCircles.append(tuple(ellipseBox))
        ellipseBox = []
        window.update()
#bind mouse click to drawing an ellipse
canvas.bind("<Button-1>", drawEllipse)
Tkinter.mainloop()

这几乎可以满足我的一切需求!但是,我无法在图像上显示省略号 - 任何建议?