使用PIL逐帧分析视频

3
我正在使用PIL对视频的子区域像素强度进行平均。我想要做的是:
-使用ffmpeg将视频转换成多个帧 -使用PIL在每个帧中选择一个窗口(这是我需要帮助的步骤) -对每个帧中的该窗口执行某种分析,并汇总数据(例如,时间与平均颜色之间的关系)
我对如何完成中间步骤感到非常茫然——是否有人可以提供建议?

你可能需要解释一下你所说的窗口、矩形是什么意思? - Gareth Latty
抱歉说得不够清楚 -- 矩形或圆形是我能想到最简单的形状,但任何形状都可能适用。我只是想找一个方法,在几张图片中跟踪一组像素。 - nathan lachenmyer
我不确定我理解了。您是想要每个帧的一个固定矩形(例如左上象限),还是想要一些算法来跟踪一组像素(例如跟随移动的人)?后者要__难得多__。 - Katriel
我希望它们能够在一组图像(前者)中遵循<b>固定</b>间距。我想要有能力使像素子集是可变的,并且为每组帧绘制一个新的矩形/圆形/形状,以围绕我关心的像素。 - nathan lachenmyer
看起来我可能需要一些GUI——像pygame、wxpython等来处理鼠标组件。除了matplotlib,我还没有使用过任何用于可视化Python的东西;有人有建议学习哪个Python GUI吗? - nathan lachenmyer
1个回答

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()

这几乎满足了我所有的需求!但是,我无法让省略号显示在图像上 - 有什么建议吗?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接