我正在尝试使用PyQt使用以下代码获取实时网络摄像头视图
class LoadImageThread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
def __del__(self):
self.wait()
def run(self):
c = cv2.VideoCapture(0)
while True:
return_val, img = c.read()
w, h =320, 240
data = img.tostring(("raw", "BGRX"))
qimage = QtGui.QImage(img, w, h, QtGui.QImage.Format_RGB32)
qpixmap = QtGui.QPixmap(w,h)
pix = QtGui.QPixmap.fromImage(qimage)
#ui.label.setPixmap(pix)
self.emit(QtCore.SIGNAL('showImage(QPixmap, int, int)'), pix, 320, 240)
#########################################
def showImage(p, w, h):
ui.label.setPixmap(p)
ui.connect(thread, QtCore.SIGNAL("showImage(QPixmap, int, int)"), showImage)
但我得到了以下错误
QPixmap: It is not safe to use pixmaps outside the GUI thread
任何解决方案?感谢