如何在原始帧上绘制阈值

How to draw threshold on original frame

我是 opencv 的新手,通过一些教程我可以进行运动检测, 我可以绘制轮廓,但我想在我的原始帧上绘制帧之间的阈值,如下图所示,我该怎么做?

当我尝试使用函数 addWeighted 时出现错误,因为数组的形状不相等。

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

谢谢

我以前看过一个视频。代码如下。选择您需要的那个。 我想你在谈论:

虽然正确: _, 框架 = 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)