我在一个黑色的窗口上画出人体坐标点,但是那个地方即使没有人体,坐标点也会保留下来,如何让这些点正常消失,这是代码。
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()
这就是
当我在身体上画点时,点消失了,但在黑色图像上没有。
1条答案
按热度按时间u5rb5r591#
你要做的就是画一个页面,然后在一秒钟内刷新它,或者在每次画完之后刷新背景图像,所以你可能要添加一行代码,再次添加黑色背景。
代码不知道何时刷新背景。2尝试在绘制了多少次后再次显示背景。
如果绘制箭头/地标?保存在您的图像上或阵列中,您可能需要刷新阵列功能,以便在重新放置图像之前清除阵列中的绘制对象。