Trouble with Python multiprocessing and OpenCV

asked 2016-01-29 18:03:35 -0600

bfc_opencv gravatar image

I'm using python 2.7 and opencv 2.4.11 and am having some trouble using the multiprocessing module for a very simple purpose. Here's a sample of my code with a consumer-producer framework employed.

class Consumer(multiprocessing.Process):

    def __init__(self, task_queue, result_queue):
        multiprocessing.Process.__init__(self)
        self.task_queue = task_queue
        self.result_queue = result_queue

    def run(self):
        #Creating window and starting video camputer from camera
        cv2.namedWindow("preview")
        vc = cv2.VideoCapture(0)
        vc.set(cv.CV_CAP_PROP_FRAME_WIDTH, 640)
        vc.set(cv.CV_CAP_PROP_FRAME_HEIGHT, 480)

        if vc.isOpened(): 
            rval, frame = vc.read()
        else:
            rval = False

        while rval:
            #Showing the frame with all the applied modifications
            cv2.imshow("preview", frame)
            rval, frame = vc.read()
            key = cv2.waitKey(20)
            if key == 27: 
                break
        cv2.destroyWindow("preview")
        return

##################################
#MAIN PROGAM
##################################

#SETTING UP MULTIPROCESSING STUFF
tasks = multiprocessing.JoinableQueue()
results = multiprocessing.Queue()

consumer = Consumer(tasks,results)
consumer.start()
#Rest of main program

However, the process hangs on the line

cv2.namedWindow("preview")

Any advice for how to proceed?

edit retag flag offensive close merge delete