停止摄像头捕获线程,但无法释放

时间:2019-09-26 02:06:12

标签: python opencv pyqt

我正在使用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()

0 个答案:

没有答案