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. What I want to do is:
-Use ffmpeg to turn the video into several frames
-Use PIL to choose a window in each frame (this is the step I'd like help with)
-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:
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?
链接地址: http://www.djcxy.com/p/41230.html上一篇: 用C生成视频
下一篇: 使用PIL逐帧分析视频