Home > Software engineering >  How to draw threshold on original frame
How to draw threshold on original frame

Time:11-16

I am very new to opencv and with some tutorials I am able todo a Motion Detection, I can draw contors but I want to draw the threshold between frames on my orignial frame as on the image below, how can I do this?

When I try to use the function addWeighted I get an error because the shape of the arrays are not equal.

Orig: (1080, 1920, 3) Thrash:(180, 320)

thanks

Example

CodePudding user response:

I've seen a video before. The codes are below. Choose the one you need. I think you are talking about:

while True: _, frame = cap.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
bodies = face_cascade.detectMultiScale(gray, 1.3, 5)


if len(faces)   len(bodies) > 0:
    if detection:
        timer_started = False
    else:
        detection = True
        current_time = datetime.datetime.now().strftime("%d-%m-%Y-%H-%M-%S")
        out = cv2.VideoWriter(
            f"{current_time}.mp4", fourcc, 20, frame_size)    
        print("Started recording!")
elif detection:
    if timer_started:
        if time.time() - detection_stopped_time >= SECONDS_TO_RECORD_AFTER_DETECTION:
            detection = False
            timer_started = False
            out.release()
            print('Stop Recording!')
    else:       
        timer_started = True
        detection_stopped_time = time.time()        

if detection:
    out.write(frame)    

for (x, y, width, height) in faces:
    cv2.rectangle(frame, (x, y), (x   width, y   height), (255, 0, 0), 2)
  • Related