我正在使用qthread来显示从USB摄像机捕获的图像。
问题出在使用以下方法终止线程之后:
th.terminate()
相机指示灯仍然亮起,表明它仍在使用中。 (跳过以释放捕获)
尝试做:
cap = cv2.VideoCapture(0)
cap.release()
终止后,问题仍然存在。
if(self.monitoringToggle == False):
self.monitoringToggle = True
self.monitoringButton.setText("Stop Monitoring")
self.th.changePixmap.connect(self.setImage)
self.th.start()
else:
self.monitoringToggle = False
self.monitoringButton.setText("Monitoring")
self.th.terminate()
cap = cv2.VideoCapture(0)
cap.release()
qImg = QImage("white_background.png")
self.videoLabel.setPixmap(QtGui.QPixmap(qImg))
class MonitoringThread(QThread):
def run(self):
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cap.release()