Select "Video Source" dialog when running code on seperate thread

asked 2013-08-01 14:59:38 -0500

JR_ gravatar image

updated 2013-08-01 15:33:13 -0500

Hello,

When I run the following code on python the main thread the pictures are displayed correctly:

def picture(self):

    self.capture = cv2.VideoCapture(0)
    cv2.namedWindow("camera")

    framecount = 30
    imagecounter = 0
    bytescounter = 0

    starttime = time.time()

    while self.picturerunning:

        result, img = self.capture.read()

        if result == True:
            cv2.imshow("camera", img)
            cv2.imwrite('temp.jpg', img, [1, 95])
            cv2.waitKey(1)

            read_bytes = open('temp.jpg', 'rb').read()

            bytescounter = bytescounter + len(read_bytes)
            imagecounter = imagecounter + 1

        if imagecounter >= framecount:
            elapsedtime = (time.time() - starttime)

            fps = (framecount / elapsedtime)
            transferspeed = (((bytescounter / 1000) / elapsedtime))

            self.logger.debug('average fps: ' + str(round(fps, 2)))
            self.logger.debug(
                'elapsed time: ' + str(round(elapsedtime, 2)))
            self.logger.debug(
                'average transfer speed (KB/s): ' + str(round(transferspeed, 2)))
            self.logger.debug('----------------------------------------')

            bytescounter = 0
            imagecounter = 0

            starttime = time.time()

However, when I run the same code running on a separate thread the Select "Video Source" dialog is displayed. When I select the correct webcam a black screen is displayed.

I use win7 and have tried following webcams but without success.

edit retag flag offensive close merge delete