简体   繁体   中英

Why the drawn coordinate points do not disappear

I draw human body coordinate points on a black window, but the coordinate points will remain even if there is no human body in that place.How to make these points disappear normally.This is code.

import cv2
import numpy as np
import mediapipe as mp
# Create a VideoCapture object and read from input file
# If the input is the camera, pass 0 instead of the video file name
cap = cv2.VideoCapture('show.mp4')
height,width=480,852
blank_image = np.zeros((height,width,3), np.uint8)

mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
    while (cap.isOpened()):

        ret, frame = cap.read()
        if ret :
            image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            image.flags.writeable = False
            results=pose.process(image)
            image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
            mp_drawing.draw_landmarks(blank_image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
                                      mp_drawing.DrawingSpec(color=(245, 117, 66), thickness=2, circle_radius=2),
                                      mp_drawing.DrawingSpec(color=(245, 66, 230), thickness=2, circle_radius=2)
                                      )
            cv2.imshow("",image)
            cv2.imshow(" ",blank_image)
            if cv2.waitKey(25) & 0xFF == ord('q'):
                break

        # Break the loop
        else:
            break

# When everything done, release the video capture object
cap.release()

# Closes all the frames
cv2.destroyAllWindows()

this is the image

图片

I found that when I draw points on the body,points can disappear normally, but not on a black image.

What you want to do with this is to draw a page and within a second refresh it again or after each draw refresh the background image, so you might want to add a line of code which adds the black background again.

the code does not know when you want to refresh the background. Try experimenting after how many draws you would like to show the background again.

if the draw arrows / landmarks? are saved on your image or in an array, you might need a flush array function to clear the drawn object out of the array before putting the image back on again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM