简体   繁体   English

使用PIL逐帧分析视频

[英]Using PIL to analyze a video frame by frame

I'm working on using PIL to average the pixel intensities over a subarea of a video. 我正在使用PIL对视频分区中的像素强度进行平均。 What I want to do is: 我想做的是:

-Use ffmpeg to turn the video into several frames -使用ffmpeg将视频分成几帧
-Use PIL to choose a window in each frame (this is the step I'd like help with) -使用PIL在每个框架中选择一个窗口(这是我需要帮助的步骤)
-Do some sort of analysis on that window in each frame, and aggregate the data (like, say, average color vs. time) -在每一帧的窗口上进行某种分析,然后汇总数据(例如平均颜色与时间的对比)

I'm at quite a loss as to how to do the middle step -- does anyone have suggestions? 我对如何执行中间步骤很困惑-有人有建议吗?

Found a solution using Tkinter: 使用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()

And this does almost everything I want! 这几乎满足了我想要的一切! However, I can't get the ellipses to show up on the image -- any suggestions? 但是,我无法将椭圆形显示在图像上-有什么建议吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM