I am developing a pose estimation application using opencv and movenet.
I am recording people's poses using camera and I want to display a graph in real time indicating the x and y co-ordinates of people's joints.
I have tried using FuncAnimation of matplotlib, but I am not getting a real-time graph. Moreover, I keep getting the following error:
UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g.
anim
, that exists until you have outputted the Animation usingplt.show()
oranim.save()
.
For now, I have tried plotting real time graph of coordinates of one of the joints of 1st person with help of below code, but I am only able to get separate graphs and not a real-time graph.
x_points=[]
y_points=[]
def draw_graph(x,y):
x_points.append(x)
y_points.append(y)
plt.cla()
plt.scatter(x,y)
plt.pause(0.5)
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
# Resize image
img = frame.copy()
img = tf.image.resize_with_pad(tf.expand_dims(img, axis=0), 384,640)
input_img = tf.cast(img, dtype=tf.int32) #input image is represented as int 32
# Detection section
results = movenet(input_img)
keypoints_with_scores = results['output_0'].numpy()[:,:,:51].reshape((6,17,3))
#real time graph
anima = anim.FuncAnimation(plt.gcf(),draw_graph(keypoints_with_scores[0][0][1],keypoints_with_scores[0][0][0]),interval=0.5)
plt.show()
# Render keypoints
loop_through_people(frame, keypoints_with_scores, EDGES, 0.1) #confidence threshold is 0.1
cv2.imshow('MoveNet Lightning',frame) #rendering the img (frame)
if cv2.waitKey(10) & 0xFF==ord('q'): #if we press a key during the frame and the key is q then pose estimation of video/webcam is halted.
break
cap.release() #release webcam
cv2.destroyAllWindows() #close frame
These are the graphs that I am getting:
I want a single real time graph instead of these multiple graphs.