我正在研究使用 PIL 来平均视频子区域的像素强度。我想做的是:
-使用ffmpeg把视频变成几帧
- 使用 PIL 在每一帧中选择一个窗口(这是我希望得到帮助的步骤)
- 对每一帧中的那个窗口进行某种分析,并汇总数据(比如,平均颜色与时间)
我对如何执行中间步骤一筹莫展——有人有建议吗?
请您参考如下方法:
找到了使用 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()
这几乎可以满足我的所有需求!但是,我无法让省略号显示在图像上——有什么建议吗?
