Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

please AVOID multithreading with opencv code, esp. with the gui parts

(those HAVE TO stay on the main thread !).

global vars are EVIL, too.

again you should use a single loop only:

import cv2
import time

camip = 0

def main():
    cam = cv2.VideoCapture(0) # if you *wanted* to open2 webcams, you need 2 of those !
    if not cam.isOpened():
        return # only fools do not check !
    while True:
        ret,frame = cam.read()
        if not ret:
             return # again, only fools ...

        temp_frame = frame.copy() # else it's *really* a reference only !
        cv2.rectangle(temp_frame,(130,130),(430,430),(0,255,0),2)
        cv2.imshow("Camera 0",frame)
        cv2.imshow("Camera 1",temp_frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
main()