我想在等待相机捕获时向用户显示加载消息。
程序在python中(使用opencv库和pyqt5 gui)
def monitoringActivity(self):
print("monitoringActivity")
self.monitoringToogle = not self.monitoringToogle
if(self.monitoringToogle == True):
qImg = QImage("loading.png")
self.label.setPixmap(QtGui.QPixmap(qImg))
self.pushButton_4.setText("Stop Monitoring")
cap = cv2.VideoCapture(0)
while (self.monitoringToogle == True):
ret, frame = cap.read()
frame = imutils.resize(frame, width=400)
height, width, channel = frame.shape
bytesPerLine = width*channel
qImg = QImage(frame.copy().data, width, height, bytesPerLine, QImage.Format_RGB888)
qImg = qImg.rgbSwapped()
self.label.setPixmap(QtGui.QPixmap(qImg))
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
breakpoint
cap.release()
else:
self.pushButton_4.setText("Monitoring")
qImg = QImage("white_background.png")
self.label.setPixmap(QtGui.QPixmap(qImg))
此处的代码使图片成为“ loading.png”
qImg = QImage("loading.png")
self.label.setPixmap(QtGui.QPixmap(qImg))
但在显示摄像机框架之前不执行:
self.label.setPixmap(QtGui.QPixmap(qImg))