저는 간단한 GUI를 만들고 멀티 프로세싱을 배우려고합니다. 내 GUI에서 캡쳐 버튼은 프레임을 캡처하여 프레임 또는 선언 된 공간 (Qlabel) 내의 GUI 내부에 배치합니다. 나는 SO의 다른 글을 읽었지만 조용히하지 않았다. 그것을 내 프로그램에서 사용하는 방법을 이해했다. 오류가 GUI 외부에서 사용하기에 안전하지 말라고멀티 프로세싱 : GUI 스레드 외부에서 픽스맵을 사용하는 것은 안전하지 않습니다.
는, 내 QPixmap 메인 스레드에서 실행되고 있음을 나타냅니다
print(multiprocessing.current_process())
을 시도했다. 이것은 내 프로그램 나는 확실히 이미지가되고있는 실행을 위해 cv2.imshow했다
import examplegui
from PySide.QtGui import *
from PySide.QtCore import *
import sys
import multiprocessing
import numpy as np
import cv2
from multiprocessing import Queue
def image_capture():
print(multiprocessing.current_process())
print("starting img proc")
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 641)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 351)
ret, frame = cap.read()
cap.release()
if ret == True:
cv2.imwrite('frame.png', frame)
return frame
class Maindialog(QMainWindow,examplegui.Ui_MainWindow):
pass_arguments = Signal(list)
def __init__(self,parent = None):
super(Maindialog,self).__init__(parent)
self.setupUi(self)
self.pool = multiprocessing.Pool(processes=4)
self.connect(self.excel_file,SIGNAL("clicked()"),self.apply_connection)
# self.pass_arguments.connect
def apply_connection(self):
print(multiprocessing.current_process())
result = self.pool.apply_async(image_capture,callback=self.show_img)
def show_img(self,result):
print(multiprocessing.current_process())
# print(result.type)
cv2.imshow("img",result)
image = QImage(result, result.shape[1], result.shape[0], result.strides[0], QImage.Format_RGB888)
self.vidimg.setPixmap(QPixmap.fromImage(image))
cv2.waitKey(0)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Maindialog()
window.show()
sys.exit(app.exec_())
,하지만 난 내가 오류를 얻을 음식물을 실행 GUI.When 내에서 해당 이미지를 필요
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
누군가 내가 잘못 가고 있다고 말할 수 있습니까?
답변으로 문제가 해결 되었습니까? Raghavendra? – ZF007
@ ZF007별로! 하지만이 오류를 해결하기 위해 스레딩을 사용하고 내 문제가 잘 작동합니다. –