tkinter没用过,不过我只是按照正常的opencv操作写了个思路仅供参考。
import cv2
class camara():
def __init__(self,windowName="1"):
self.cap=cv2.VideoCapture(0)
self.windowName=windowName
def opencamara(self):
while self.cap.isOpened():
self.ret, self.frame = self.cap.read()
cv2.imshow(self.windowName,self.frame)
if cv2.waitKey(1)==27:#模拟按键按下第二个按钮
#cv2.destroyAllWindows()
#如果不需要再开一个窗,那就先把这个窗关掉,或者,将windowname传递过去
self.dealwith(windowNmae=self.windowName)
break
self.cap.release()
cv2.destroyAllWindows()
def dealwith(self,windowNmae="2"):
while self.cap.isOpened():
self.ret, self.frame = self.cap.read()
hsv = cv2.cvtColor(self.frame, cv2.COLOR_RGB2HSV)
cv2.imshow(windowNmae, hsv)
if cv2.waitKey(1)==27:
#self.cap.release()
break
self.cap.release()
cv2.destroyAllWindows()
test=camara()
test.opencamara()
#test.dealwith()