def draw_result_img(img_disp, ith_img, humans, dict_id2skeleton, skeleton_detector, multiperson_classifier): ''' Draw skeletons, labels, and prediction scores onto image for display ''' # Resize to a proper size for display r, c = img_disp.shape[0:2] desired_cols = int(1.0 * c * (img_disp_desired_rows / r)) img_disp = cv2.resize(img_disp, dsize=(desired_cols, img_disp_desired_rows)) # Draw all people's skeleton skeleton_detector.draw(img_disp, humans) # Draw bounding box and label of each person if len(dict_id2skeleton): for id, label in dict_id2label.items(): skeleton = dict_id2skeleton[id] # scale the y data back to original skeleton[1::2] = skeleton[1::2] / scale_h # print("Drawing skeleton: ", dict_id2skeleton[id], "with label:", label, ".") lib_plot.draw_action_result(img_disp, id, skeleton, label) # Add blank to the left for displaying prediction scores of each class #img_disp = lib_plot.add_white_region_to_left_of_image(img_disp) ################################################################################################################################## #cv2.putText(img_disp, "Frame:" + str(ith_img), # (20, 20), fontScale=1.5, fontFace=cv2.FONT_HERSHEY_PLAIN, # color=(0, 0, 0), thickness=2) ############################################################################################################## # Draw predicting score for only 1 person if len(dict_id2skeleton): classifier_of_a_person = multiperson_classifier.get_classifier( id='min') classifier_of_a_person.draw_scores_onto_image(img_disp) return img_disp
def draw_result_img(img_disp, ith_img, humans, dict_id2skeleton, skeleton_detector, multiperson_classifier, img_disp_desired_rows, dict_id2label, scale_h): ''' Draw skeletons, labels, and prediction scores onto image for display img_disp => copy of the input image ''' # Resize to a proper size for display r, c = img_disp.shape[ 0:2] # find the size of image, height 480 and width 640 desired_cols = int(1.0 * c * (img_disp_desired_rows / r)) # resize to 640*480 => unchange img_disp = cv2.resize(img_disp, dsize=(desired_cols, img_disp_desired_rows)) # Draw all people's skeleton skeleton_detector.draw(img_disp, humans) # Draw bounding box and label of each person if len(dict_id2skeleton): for id, label in dict_id2label.items(): skeleton = dict_id2skeleton[id] # scale the y data back to original skeleton[ 1::2] = skeleton[1::2] / scale_h # y 在擷取特徵的時候有乘scale_h,要除回來 lib_plot.draw_action_result(img_disp, id, skeleton, label) # add text "fps" cv2.putText(img_disp, "Frame:" + str(ith_img), (10, 25), fontScale=1, fontFace=cv2.FONT_HERSHEY_PLAIN, color=(0, 0, 0), thickness=2) # Draw predicting score for only 1 person # 取最小的id if len(dict_id2skeleton): classifier_of_a_person = multiperson_classifier.get_classifier( id='min') classifier_of_a_person.draw_scores_onto_image(img_disp) return img_disp