[英]cv2 imshow doesnt open window again after closing and opening again, when used with threads
在下面的示例代碼中,
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()
我按以下順序進行操作,分別調用obj.start_camera(),obj.stop_camera(),cv2.imshow()打開一個窗口,但是當我再次執行obj.start_camera()和obj.stop_camera()時,它沒有打開一個窗口。 這是怎么了
您可以使用multiprocessing
模塊代替threading
模塊來緩解此問題。 但是我仍然找不到如何通過threading
解決此問題的方法。
看一個類似的問題 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.