有人可以解释一下为什么在修改注释掉的代码后没有更多的相机视图吗?我收到错误消息
“ self.a = Image.fromarray(self.capture)#PIL 1.6# AttributeError: class Image 没有属性‘fromarray’”
来自 x.update_video 方法。评论代码来自主题OpenCV(Python 中的 cv2)VideoCapture 删除后未释放相机 我对 Tkinter 很陌生,在教程中找不到任何帮助。我想这是由于框架和画布一样包装。但必须有任何解决方案...
class App:
def __init__(self, master,cam):
## root = tk.Tk()
## videoframe = tk.LabelFrame(root,text='Captured video')
## videoframe.grid(column=0,row=0,columnspan=1,rowspan=1,padx=5, pady=5, ipadx=5, ipady=5)
## canvas = tk.Canvas(videoframe, width=640,height=480)
## canvas.grid(column=0,row=0)
## cam = cv2.VideoCapture(2)
## x = vid(cam,root,canvas)
## root.after(0,x.update_video)
## button = tk.Button(text='Quit',master=videoframe,command=root.destroy)
## button.grid(column=0,row=1)
## root.mainloop()
## del cam
frame = LabelFrame(master,text='Captured video')
frame.pack()
canvas = Canvas(frame, width=640,height=480)
canvas.pack(side=TOP)
x = vid(cam,master,canvas)
master.after(0,x.update_video)
self.button = Button(frame, text="QUIT", fg="red", command=master.destroy)
self.button.pack(side=LEFT)
self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)
def say_hi(self):
print "hi there, everyone!"
root = Tk()
cam = cv2.VideoCapture(0)
app = App(root,cam)
root.mainloop()
del cam