Why the drawn coordinate points do not disappear

65 views Asked by At

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

img

When I draw points on the body, points disappeared, but not on a black image.

1

There are 1 answers

0
Jasper Lankhorst On

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.