Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using a webcam, how do I keep a drawing function in one window from appearing on to another window?

image description

In the picture on the right, I have a window named 'frame' which shows a green square and a cyan circle. On the left, there is a window named 'binary' which shows the square and circle in white.

The binary window shows in white objects that are moving.

What can I do so that the drawing functions do not show in the 'binary' window and only stay in the 'frame' window?

I'd greatly appreciate any help I can receive.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

ret, last_frame =

if last_frame is None:

    ret, frame =

    if frame is None:

    binary = cv2.absdiff(last_frame, frame)
    binary = cv2.cvtColor(binary, cv2.COLOR_BGR2GRAY) 
    ret, binary = cv2.threshold(binary,50,255,cv2.THRESH_BINARY) 

    frame = cv2.rectangle(frame,(0,0),(320,240),(0,255,0),3)

    vRow, vCol, vCH = frame.shape
    cirR = 30
    cirRowPos = int(vRow/2)
    cirColPos = int(vCol-cirR) - int(vCol*0.05)
    frame =,(cirColPos, cirRowPos), cirR, (255,255,0), 3)

    cv2.imshow('frame', frame)
    cv2.imshow('binary', binary)

    if cv2.waitKey(33) >= 0:

    last_frame = frame