0

我的感受: draw_keypoints 函数没有被调用。请帮帮我我无法弄清楚出了什么问题我知道这可能是功能范围之外的问题,但仍然存在。

代码:

plt.imshow(frame)
cap = cv2.VideoCapture(0)
while cap.isOpened():
    ret,frame = cap.read()
    
    #Reshape Image
    img = frame.copy()
    img = tf.image.resize_with_pad(np.expand_dims(img, axis=0), 256,256)
    input_image= tf.cast(img, dtype=tf.float32)
    
    
    #setup input and output
    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()
    
    interpreter.set_tensor(input_details[0]['index'], np.array(input_image))
    interpreter.invoke
    keypoints_with_scores = interpreter.get_tensor(output_details[0]['index'])
    
    draw_keypoints(frame, keypoints_with_scores, 0.4)
    
    cv2.imshow('MoveNet Thunder', frame)
    if cv2.waitKey(10) & 0xFF==ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

def draw_keypoints(frame, keypoints, confidence_threshold):
    cv2.circle(frame, (200, 200), 7, (0,255,0), 3)
    y, x, c = frame.shape
    shaped = np.squeeze(np.multiply(keypoints,[y,x,1]))
    
    for kp in shaped:
        kx, ky, kc = kp
        if kc >  confidence_threshold:
            cv2.circle(frame, (int(kx), int(ky)), 7, (0,255,0), 3)
4

0 回答 0