[英]cv2 imshow doesnt open window again after closing and opening again, when used with threads
In the sample code below, 在下面的示例代码中,
import cv2
from threading import Thread
class Person_Item_Association(object):
def __init__(self):
self.stop = False
def start_camera(self):
self.stop =False
camera_thread = Thread(target=self.start_analysis)
camera_thread.start()
def stop_camera(self):
self.stop = True
def start_analysis(self):
cap = cv2.VideoCapture(0)
while not self.stop:
ret,image = cap.read()
cv2.imshow("frame",image)
cv2.waitKey(1)
cap.release()
print("resource released")
cv2.destroyAllWindows()
I do the following sequence, call obj.start_camera(), obj.stop_camera(), cv2.imshow() opens a window , but when i again do obj.start_camera() and obj.stop_camera(), it doesn't open a window. 我按以下顺序进行操作,分别调用obj.start_camera(),obj.stop_camera(),cv2.imshow()打开一个窗口,但是当我再次执行obj.start_camera()和obj.stop_camera()时,它没有打开一个窗口。 What is wrong here ? 这是怎么了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.