From e1d3bd4becc9e063430d8ad87d1b70513930e0e9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 9 Aug 2020 14:45:41 +0000 Subject: [PATCH] Restyled by yapf --- gui_cvs/table.py | 19 +++-- gui_wizard/helloworld.py | 117 ++++++++++++-------------- src/cvs/webcam.py | 23 +++-- src/facencnn/facepose.py | 11 ++- src/handtf/utils/detector_utils.py | 30 +++---- src/handtf/webcam.py | 19 +++-- src/mutilpose/posenet/decode_multi.py | 87 +++++++++---------- src/mutilpose/posenet/model.py | 6 +- src/mutilpose/posenet/utils.py | 94 ++++++++++----------- src/mutilpose/webcam_demo.py | 15 ++-- src/singlepose/webpose.py | 30 ++++--- 11 files changed, 231 insertions(+), 220 deletions(-) diff --git a/gui_cvs/table.py b/gui_cvs/table.py index dbcf76a..6d0c91f 100755 --- a/gui_cvs/table.py +++ b/gui_cvs/table.py @@ -6,15 +6,17 @@ def __init__(self, *args): super(MyApp, self).__init__(*args) def main(self): - wid = gui.VBox( - width=500, height=500, style={"margin": "5px auto", "padding": "10px"} - ) - - lbl_description = gui.Label( - """Example about TableWidget usage. + wid = gui.VBox(width=500, + height=500, + style={ + "margin": "5px auto", + "padding": "10px" + }) + + lbl_description = gui.Label("""Example about TableWidget usage. Change rows and columns count in order to see the behaviour. After changing the size, 'Fill the table' content by means of the button.""" - ) + ) wid.append(lbl_description) @@ -62,7 +64,8 @@ def on_column_count_change(self, emitter, value, table): def fill_table(self, emitter, table): for ri in range(table.row_count()): for ci in range(table.column_count()): - table.item_at(ri, ci).set_text("row:%s,column:%s" % (str(ri), str(ci))) + table.item_at(ri, ci).set_text("row:%s,column:%s" % + (str(ri), str(ci))) def on_use_title_change(self, emitter, value, table): value = value == "true" diff --git a/gui_wizard/helloworld.py b/gui_wizard/helloworld.py index b3da34a..82ed273 100644 --- a/gui_wizard/helloworld.py +++ b/gui_wizard/helloworld.py @@ -7,7 +7,8 @@ class untitled(App): def __init__(self, *args, **kwargs): # DON'T MAKE CHANGES HERE, THIS METHOD GETS OVERWRITTEN WHEN SAVING IN THE EDITOR if "editing_mode" not in kwargs.keys(): - super(untitled, self).__init__(*args, static_file_path={"my_res": "./res/"}) + super(untitled, + self).__init__(*args, static_file_path={"my_res": "./res/"}) def idle(self): # idle function called every update cycle @@ -20,72 +21,60 @@ def main(self): def construct_ui(self): # DON'T MAKE CHANGES HERE, THIS METHOD GETS OVERWRITTEN WHEN SAVING IN THE EDITOR mainContainer = Widget() - mainContainer.attributes.update( - { - "editor_baseclass": "Widget", - "editor_tag_type": "widget", - "editor_newclass": "False", - "editor_constructor": "()", - "class": "Widget", - "editor_varname": "mainContainer", - } - ) - mainContainer.style.update( - { - "width": "266px", - "position": "absolute", - "top": "61px", - "left": "16px", - "margin": "0px", - "overflow": "auto", - "height": "257px", - } - ) + mainContainer.attributes.update({ + "editor_baseclass": "Widget", + "editor_tag_type": "widget", + "editor_newclass": "False", + "editor_constructor": "()", + "class": "Widget", + "editor_varname": "mainContainer", + }) + mainContainer.style.update({ + "width": "266px", + "position": "absolute", + "top": "61px", + "left": "16px", + "margin": "0px", + "overflow": "auto", + "height": "257px", + }) button = Button("Say Hello") - button.attributes.update( - { - "editor_baseclass": "Button", - "editor_tag_type": "widget", - "editor_newclass": "False", - "editor_constructor": "('Say Hello')", - "class": "Button", - "editor_varname": "button", - } - ) - button.style.update( - { - "width": "149px", - "position": "absolute", - "top": "80px", - "left": "37px", - "margin": "0px", - "overflow": "auto", - "height": "29px", - } - ) + button.attributes.update({ + "editor_baseclass": "Button", + "editor_tag_type": "widget", + "editor_newclass": "False", + "editor_constructor": "('Say Hello')", + "class": "Button", + "editor_varname": "button", + }) + button.style.update({ + "width": "149px", + "position": "absolute", + "top": "80px", + "left": "37px", + "margin": "0px", + "overflow": "auto", + "height": "29px", + }) mainContainer.append(button, "button") label = Label("My label") - label.attributes.update( - { - "editor_baseclass": "Label", - "editor_tag_type": "widget", - "editor_newclass": "False", - "editor_constructor": "('My label')", - "class": "Label", - "editor_varname": "label", - } - ) - label.style.update( - { - "width": "98px", - "position": "absolute", - "top": "20px", - "left": "20px", - "margin": "0px", - "overflow": "auto", - "height": "25px", - } - ) + label.attributes.update({ + "editor_baseclass": "Label", + "editor_tag_type": "widget", + "editor_newclass": "False", + "editor_constructor": "('My label')", + "class": "Label", + "editor_varname": "label", + }) + label.style.update({ + "width": "98px", + "position": "absolute", + "top": "20px", + "left": "20px", + "margin": "0px", + "overflow": "auto", + "height": "25px", + }) mainContainer.append(label, "label") mainContainer.children["button"].onclick.do(self.onclick_button) diff --git a/src/cvs/webcam.py b/src/cvs/webcam.py index 116fa07..11a2858 100644 --- a/src/cvs/webcam.py +++ b/src/cvs/webcam.py @@ -6,7 +6,8 @@ class untitled(App): def __init__(self, *args, **kwargs): # DON'T MAKE CHANGES HERE, THIS METHOD GETS OVERWRITTEN WHEN SAVING IN THE EDITOR if "editing_mode" not in kwargs.keys(): - super(untitled, self).__init__(*args, static_file_path={"my_res": "./res/"}) + super(untitled, + self).__init__(*args, static_file_path={"my_res": "./res/"}) def idle(self): # idle function called every update cycle @@ -21,17 +22,15 @@ def construct_ui(self): aidcam = OpencvVideoWidget(self) # aidcam.attributes.update({"src":"/528175722896/get_image_data","editor_newclass":"False","editor_baseclass":"OpencvVideoWidget","editor_constructor":"()","class":"OpencvVideoWidget","editor_tag_type":"widget","editor_varname":"aidcam"}) aidcam.set_identifier("myimage_receiver") - aidcam.style.update( - { - "width": "190px", - "position": "absolute", - "top": "20px", - "left": "20px", - "margin": "0px", - "overflow": "auto", - "height": "177px", - } - ) + aidcam.style.update({ + "width": "190px", + "position": "absolute", + "top": "20px", + "left": "20px", + "margin": "0px", + "overflow": "auto", + "height": "177px", + }) self.aidcam = aidcam return self.aidcam diff --git a/src/facencnn/facepose.py b/src/facencnn/facepose.py index b002295..c4a75aa 100644 --- a/src/facencnn/facepose.py +++ b/src/facencnn/facepose.py @@ -68,14 +68,21 @@ def idle(self): def main(self): # creating a container VBox type, vertical (you can use also HBox or Widget) - main_container = gui.VBox(width=360, height=680, style={"margin": "0px auto"}) + main_container = gui.VBox(width=360, + height=680, + style={"margin": "0px auto"}) self.aidcam = OpencvVideoWidget(self, width=340, height=480) self.aidcam.style["margin"] = "10px" self.aidcam.set_identifier("myimage_receiver") main_container.append(self.aidcam) - self.lbl = gui.Label("This show fps!", width=360, height=30, margin="50px",) + self.lbl = gui.Label( + "This show fps!", + width=360, + height=30, + margin="50px", + ) main_container.append(self.lbl) return main_container diff --git a/src/handtf/utils/detector_utils.py b/src/handtf/utils/detector_utils.py index 3d1a1cc..e359b1a 100644 --- a/src/handtf/utils/detector_utils.py +++ b/src/handtf/utils/detector_utils.py @@ -22,8 +22,7 @@ # load label map using utils provided by tensorflow object detection api label_map = label_map_util.load_labelmap(PATH_TO_LABELS) categories = label_map_util.convert_label_map_to_categories( - label_map, max_num_classes=NUM_CLASSES, use_display_name=True -) + label_map, max_num_classes=NUM_CLASSES, use_display_name=True) category_index = label_map_util.create_category_index(categories) @@ -54,14 +53,14 @@ def load_inference_graph(): # Drawing bounding boxes and distances onto image def draw_box_on_image( - num_hands_detect, - score_thresh, - scores, - boxes, - classes, - im_width, - im_height, - image_np, + num_hands_detect, + score_thresh, + scores, + boxes, + classes, + im_width, + im_height, + image_np, ): # Determined using a piece of paper of known length, code can be found in distance to camera focalLength = 875 @@ -90,7 +89,8 @@ def draw_box_on_image( p1 = (int(left), int(top)) p2 = (int(right), int(bottom)) - dist = distance_to_camera(avg_width, focalLength, int(right - left)) + dist = distance_to_camera(avg_width, focalLength, + int(right - left)) cv2.rectangle(image_np, p1, p2, color, 3, 1) @@ -127,9 +127,8 @@ def draw_box_on_image( # Show fps value on image. def draw_text_on_image(fps, image_np): - cv2.putText( - image_np, fps, (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (77, 255, 9), 2 - ) + cv2.putText(image_np, fps, (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, + (77, 255, 9), 2) # compute and return the distance from the hand to the camera using triangle similarity @@ -150,7 +149,8 @@ def detect_objects(image_np, detection_graph, sess): # Each score represent how level of confidence for each of the objects. # Score is shown on the result image, together with the class label. detection_scores = detection_graph.get_tensor_by_name("detection_scores:0") - detection_classes = detection_graph.get_tensor_by_name("detection_classes:0") + detection_classes = detection_graph.get_tensor_by_name( + "detection_classes:0") num_detections = detection_graph.get_tensor_by_name("num_detections:0") image_np_expanded = np.expand_dims(image_np, axis=0) diff --git a/src/handtf/webcam.py b/src/handtf/webcam.py index ed940ba..d1f919f 100644 --- a/src/handtf/webcam.py +++ b/src/handtf/webcam.py @@ -15,7 +15,6 @@ ) args = vars(ap.parse_args()) - detection_graph, sess = detector_utils.load_inference_graph() @@ -54,8 +53,7 @@ def main(): # Run image through tensorflow graph boxes, scores, classes = detector_utils.detect_objects( - frame, detection_graph, sess - ) + frame, detection_graph, sess) # Draw bounding boxeses and text detector_utils.draw_box_on_image( @@ -71,7 +69,8 @@ def main(): # Calculate Frames per second (FPS) num_frames += 1 - elapsed_time = (datetime.datetime.now() - start_time).total_seconds() + elapsed_time = (datetime.datetime.now() - + start_time).total_seconds() fps = num_frames / elapsed_time # Display FPS on frame @@ -81,8 +80,7 @@ def main(): if args["display"]: detector_utils.draw_text_on_image( - "FPS : " + str("{0:.2f}".format(fps)), frame - ) + "FPS : " + str("{0:.2f}".format(fps)), frame) cvs.imshow(cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)) @@ -103,7 +101,9 @@ def idle(self): def main(self): # initcv(process) # creating a container VBox type, vertical (you can use also HBox or Widget) - main_container = gui.VBox(width=360, height=680, style={"margin": "0px auto"}) + main_container = gui.VBox(width=360, + height=680, + style={"margin": "0px auto"}) self.aidcam = OpencvVideoWidget(self, width=340, height=480) self.aidcam.style["margin"] = "10px" @@ -112,7 +112,10 @@ def main(self): main_container.append(self.aidcam) # Display FPS on frame - self.lbl = gui.Label("This is a LABEL!", width=360, height=30, margin="10px") + self.lbl = gui.Label("This is a LABEL!", + width=360, + height=30, + margin="10px") main_container.append(self.lbl) return main_container diff --git a/src/mutilpose/posenet/decode_multi.py b/src/mutilpose/posenet/decode_multi.py index 18dce5b..40970b5 100644 --- a/src/mutilpose/posenet/decode_multi.py +++ b/src/mutilpose/posenet/decode_multi.py @@ -7,50 +7,45 @@ def within_nms_radius(poses, squared_nms_radius, point, keypoint_id): return any( - np.sum((pose_coord[keypoint_id] - point) ** 2) <= squared_nms_radius - for _, _, pose_coord in poses - ) + np.sum((pose_coord[keypoint_id] - point)**2) <= squared_nms_radius + for _, _, pose_coord in poses) def within_nms_radius_fast(pose_coords, squared_nms_radius, point): if not pose_coords.shape[0]: return False - return np.any(np.sum((pose_coords - point) ** 2, axis=1) <= squared_nms_radius) + return np.any( + np.sum((pose_coords - point)**2, axis=1) <= squared_nms_radius) -def get_instance_score( - existing_poses, squared_nms_radius, keypoint_scores, keypoint_coords -): +def get_instance_score(existing_poses, squared_nms_radius, keypoint_scores, + keypoint_coords): not_overlapped_scores = 0.0 for keypoint_id in range(len(keypoint_scores)): if not within_nms_radius( - existing_poses, - squared_nms_radius, - keypoint_coords[keypoint_id], - keypoint_id, + existing_poses, + squared_nms_radius, + keypoint_coords[keypoint_id], + keypoint_id, ): not_overlapped_scores += keypoint_scores[keypoint_id] return not_overlapped_scores / len(keypoint_scores) -def get_instance_score_fast( - exist_pose_coords, squared_nms_radius, keypoint_scores, keypoint_coords -): +def get_instance_score_fast(exist_pose_coords, squared_nms_radius, + keypoint_scores, keypoint_coords): if exist_pose_coords.shape[0]: - s = ( - np.sum((exist_pose_coords - keypoint_coords) ** 2, axis=2) - > squared_nms_radius - ) + s = (np.sum((exist_pose_coords - keypoint_coords)**2, axis=2) > + squared_nms_radius) not_overlapped_scores = np.sum(keypoint_scores[np.all(s, axis=0)]) else: not_overlapped_scores = np.sum(keypoint_scores) return not_overlapped_scores / len(keypoint_scores) -def score_is_max_in_local_window( - keypoint_id, score, hmy, hmx, local_max_radius, scores -): +def score_is_max_in_local_window(keypoint_id, score, hmy, hmx, + local_max_radius, scores): height = scores.shape[0] width = scores.shape[1] @@ -78,9 +73,8 @@ def build_part_with_score(score_threshold, local_max_radius, scores): score = scores[hmy, hmx, keypoint_id] if score < score_threshold: continue - if score_is_max_in_local_window( - keypoint_id, score, hmy, hmx, local_max_radius, scores - ): + if score_is_max_in_local_window(keypoint_id, score, hmy, hmx, + local_max_radius, scores): parts.append((score, keypoint_id, np.array((hmy, hmx)))) return parts @@ -99,21 +93,22 @@ def build_part_with_score_fast(score_threshold, local_max_radius, scores): max_loc = np.logical_and(kp_scores == max_vals, kp_scores > 0) max_loc_idx = max_loc.nonzero() for y, x in zip(*max_loc_idx): - parts.append((scores[y, x, keypoint_id], keypoint_id, np.array((y, x)))) + parts.append( + (scores[y, x, keypoint_id], keypoint_id, np.array((y, x)))) return parts def decode_multiple_poses( - scores, - offsets, - displacements_fwd, - displacements_bwd, - output_stride, - max_pose_detections=10, - score_threshold=0.5, - nms_radius=20, - min_pose_score=0.5, + scores, + offsets, + displacements_fwd, + displacements_bwd, + output_stride, + max_pose_detections=10, + score_threshold=0.5, + nms_radius=20, + min_pose_score=0.5, ): pose_count = 0 @@ -121,29 +116,29 @@ def decode_multiple_poses( pose_keypoint_scores = np.zeros((max_pose_detections, NUM_KEYPOINTS)) pose_keypoint_coords = np.zeros((max_pose_detections, NUM_KEYPOINTS, 2)) - squared_nms_radius = nms_radius ** 2 + squared_nms_radius = nms_radius**2 - scored_parts = build_part_with_score_fast( - score_threshold, LOCAL_MAXIMUM_RADIUS, scores - ) + scored_parts = build_part_with_score_fast(score_threshold, + LOCAL_MAXIMUM_RADIUS, scores) scored_parts = sorted(scored_parts, key=lambda x: x[0], reverse=True) # change dimensions from (h, w, x) to (h, w, x//2, 2) to allow return of complete coord array height = scores.shape[0] width = scores.shape[1] offsets = offsets.reshape(height, width, 2, -1).swapaxes(2, 3) - displacements_fwd = displacements_fwd.reshape(height, width, 2, -1).swapaxes(2, 3) - displacements_bwd = displacements_bwd.reshape(height, width, 2, -1).swapaxes(2, 3) + displacements_fwd = displacements_fwd.reshape(height, width, 2, + -1).swapaxes(2, 3) + displacements_bwd = displacements_bwd.reshape(height, width, 2, + -1).swapaxes(2, 3) for root_score, root_id, root_coord in scored_parts: - root_image_coords = ( - root_coord * output_stride + offsets[root_coord[0], root_coord[1], root_id] - ) + root_image_coords = (root_coord * output_stride + + offsets[root_coord[0], root_coord[1], root_id]) if within_nms_radius_fast( - pose_keypoint_coords[:pose_count, root_id, :], - squared_nms_radius, - root_image_coords, + pose_keypoint_coords[:pose_count, root_id, :], + squared_nms_radius, + root_image_coords, ): continue diff --git a/src/mutilpose/posenet/model.py b/src/mutilpose/posenet/model.py index 502ef11..a58f6cc 100644 --- a/src/mutilpose/posenet/model.py +++ b/src/mutilpose/posenet/model.py @@ -35,9 +35,11 @@ def load_config(model_ord): def load_model(model_id, sess, model_dir=MODEL_DIR): model_ord = model_id_to_ord(model_id) model_cfg = load_config(model_ord) - model_path = os.path.join(model_dir, "model-%s.pb" % model_cfg["checkpoint_name"]) + model_path = os.path.join(model_dir, + "model-%s.pb" % model_cfg["checkpoint_name"]) if not os.path.exists(model_path): - print("Cannot find model file %s, converting from tfjs..." % model_path) + print("Cannot find model file %s, converting from tfjs..." % + model_path) from posenet.converter.tfjs2python import convert convert(model_ord, model_dir, check=False) diff --git a/src/mutilpose/posenet/utils.py b/src/mutilpose/posenet/utils.py index cc88653..52d1572 100644 --- a/src/mutilpose/posenet/utils.py +++ b/src/mutilpose/posenet/utils.py @@ -21,13 +21,12 @@ def _process_input(source_img, scale_factor=1.0, output_stride=16): source_img.shape[0] * scale_factor, output_stride=output_stride, ) - scale = np.array( - [source_img.shape[0] / target_height, source_img.shape[1] / target_width] - ) + scale = np.array([ + source_img.shape[0] / target_height, source_img.shape[1] / target_width + ]) - input_img = cv2.resize( - source_img, (target_width, target_height), interpolation=cv2.INTER_LINEAR - ) + input_img = cv2.resize(source_img, (target_width, target_height), + interpolation=cv2.INTER_LINEAR) input_img = cv2.cvtColor(input_img, cv2.COLOR_BGR2RGB).astype(np.float32) input_img = input_img * (2.0 / 255.0) - 1.0 input_img = input_img.reshape(1, target_height, target_width, 3) @@ -47,12 +46,12 @@ def read_imgfile(path, scale_factor=1.0, output_stride=16): def draw_keypoints( - img, - instance_scores, - keypoint_scores, - keypoint_coords, - min_pose_confidence=0.5, - min_part_confidence=0.5, + img, + instance_scores, + keypoint_scores, + keypoint_coords, + min_pose_confidence=0.5, + min_part_confidence=0.5, ): cv_keypoints = [] for ii, score in enumerate(instance_scores): @@ -65,55 +64,53 @@ def draw_keypoints( return cv2.drawKeypoints(img, cv_keypoints, outImage=np.array([])) -def get_adjacent_keypoints(keypoint_scores, keypoint_coords, min_confidence=0.1): +def get_adjacent_keypoints(keypoint_scores, + keypoint_coords, + min_confidence=0.1): results = [] for left, right in posenet.CONNECTED_PART_INDICES: - if ( - keypoint_scores[left] < min_confidence - or keypoint_scores[right] < min_confidence - ): + if (keypoint_scores[left] < min_confidence + or keypoint_scores[right] < min_confidence): continue results.append( - np.array( - [ - keypoint_coords[left][::-1] / scale_factor, - keypoint_coords[right][::-1] / scale_factor, - ] - ).astype(np.int32), - ) + np.array([ + keypoint_coords[left][::-1] / scale_factor, + keypoint_coords[right][::-1] / scale_factor, + ]).astype(np.int32), ) return results def draw_skeleton( - img, - instance_scores, - keypoint_scores, - keypoint_coords, - min_pose_confidence=0.5, - min_part_confidence=0.5, + img, + instance_scores, + keypoint_scores, + keypoint_coords, + min_pose_confidence=0.5, + min_part_confidence=0.5, ): out_img = img adjacent_keypoints = [] for ii, score in enumerate(instance_scores): if score < min_pose_confidence: continue - new_keypoints = get_adjacent_keypoints( - keypoint_scores[ii, :], keypoint_coords[ii, :, :], min_part_confidence - ) + new_keypoints = get_adjacent_keypoints(keypoint_scores[ii, :], + keypoint_coords[ii, :, :], + min_part_confidence) adjacent_keypoints.extend(new_keypoints) - out_img = cv2.polylines( - out_img, adjacent_keypoints, isClosed=False, color=(255, 255, 0) - ) + out_img = cv2.polylines(out_img, + adjacent_keypoints, + isClosed=False, + color=(255, 255, 0)) return out_img def draw_skel_and_kp( - img, - instance_scores, - keypoint_scores, - keypoint_coords, - min_pose_score=0.3, - min_part_score=0.3, + img, + instance_scores, + keypoint_scores, + keypoint_coords, + min_pose_score=0.3, + min_part_score=0.3, ): out_img = img adjacent_keypoints = [] @@ -122,22 +119,23 @@ def draw_skel_and_kp( if score < min_pose_score: continue - new_keypoints = get_adjacent_keypoints( - keypoint_scores[ii, :], keypoint_coords[ii, :, :], min_part_score - ) + new_keypoints = get_adjacent_keypoints(keypoint_scores[ii, :], + keypoint_coords[ii, :, :], + min_part_score) adjacent_keypoints.extend(new_keypoints) for ks, kc in zip(keypoint_scores[ii, :], keypoint_coords[ii, :, :]): if ks < min_part_score: continue cv_keypoints.append( - cv2.KeyPoint(kc[1] / scale_factor, kc[0] / scale_factor, 10.0 * ks) - ) + cv2.KeyPoint(kc[1] / scale_factor, kc[0] / scale_factor, + 10.0 * ks)) # out_img = cv2.drawKeypoints( # out_img, cv_keypoints, np.array([]), (0, 0, 255),flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # return out_img - out_img2 = cv2.polylines(out_img, adjacent_keypoints, False, (255, 255, 0), 2) + out_img2 = cv2.polylines(out_img, adjacent_keypoints, False, (255, 255, 0), + 2) # out_img1 = cv2.drawKeypoints( # out_img, cv_keypoints, np.array([]), (0, 0, 255),flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) if out_img2 is None: diff --git a/src/mutilpose/webcam_demo.py b/src/mutilpose/webcam_demo.py index dac2584..8028781 100644 --- a/src/mutilpose/webcam_demo.py +++ b/src/mutilpose/webcam_demo.py @@ -7,7 +7,6 @@ print("import tensorflow...wait...") - parser = argparse.ArgumentParser() parser.add_argument("--model", type=int, default=50) parser.add_argument("--cam", type=int, default=0) @@ -40,8 +39,9 @@ def main(): img = cvs.flip(img, 0) input_image, display_image, output_scale = posenet.read_cap( - img, scale_factor=args.scale_factor, output_stride=output_stride - ) + img, + scale_factor=args.scale_factor, + output_stride=output_stride) ( heatmaps_result, @@ -94,7 +94,9 @@ def idle(self): def main(self): # creating a container VBox type, vertical (you can use also HBox or Widget) - main_container = gui.VBox(width=360, height=680, style={"margin": "0px auto"}) + main_container = gui.VBox(width=360, + height=680, + style={"margin": "0px auto"}) self.aidcam = OpencvVideoWidget(self, width=340, height=480) self.aidcam.style["margin"] = "10px" @@ -103,7 +105,10 @@ def main(self): # The post request must specify in the header the widget identifier and the function name that will be used to pass the file data self.aidcam.set_identifier("myimage_receiver") main_container.append(self.aidcam) - self.lbl = gui.Label("This show FPS!", width=360, height=30, margin="10px") + self.lbl = gui.Label("This show FPS!", + width=360, + height=30, + margin="10px") main_container.append(self.lbl) return main_container diff --git a/src/singlepose/webpose.py b/src/singlepose/webpose.py index d42e4d9..f88a630 100644 --- a/src/singlepose/webpose.py +++ b/src/singlepose/webpose.py @@ -39,8 +39,10 @@ def main(): image = detection_graph.get_tensor_by_name("image:0") heatmaps = detection_graph.get_tensor_by_name("heatmap:0") offsets = detection_graph.get_tensor_by_name("offset_2:0") - displacementFwd = detection_graph.get_tensor_by_name("displacement_fwd_2:0") - displacementBwd = detection_graph.get_tensor_by_name("displacement_bwd_2:0") + displacementFwd = detection_graph.get_tensor_by_name( + "displacement_fwd_2:0") + displacementBwd = detection_graph.get_tensor_by_name( + "displacement_bwd_2:0") fcount = -1 start = time.time() @@ -128,7 +130,8 @@ def main(): px = (rx) * 16 + ofx py = (ry) * 16 + ofy if maxheat > 0.7: - cvs.circle(tmpimg, (int(px), int(py)), 3, colors[k], -1) + cvs.circle(tmpimg, (int(px), int(py)), 3, colors[k], + -1) keypoint.append(int(px)) keypoint.append(int(py)) else: @@ -152,11 +155,14 @@ def main(): ckeypoint.append(keypoint[2 * i + 2 + 1]) for pair in pairs: - if ckeypoint[2 * pair[0]] > 0 and ckeypoint[2 * pair[1]] > 0: + if ckeypoint[2 * pair[0]] > 0 and ckeypoint[2 * + pair[1]] > 0: cvs.line( tmpimg, - (ckeypoint[2 * pair[0]], ckeypoint[2 * pair[0] + 1]), - (ckeypoint[2 * pair[1]], ckeypoint[2 * pair[1] + 1]), + (ckeypoint[2 * pair[0]], + ckeypoint[2 * pair[0] + 1]), + (ckeypoint[2 * pair[1]], + ckeypoint[2 * pair[1] + 1]), (0, 0, 255), 1, ) @@ -175,7 +181,9 @@ def idle(self): def main(self): # creating a container VBox type, vertical (you can use also HBox or Widget) - main_container = gui.VBox(width=360, height=680, style={"margin": "0px auto"}) + main_container = gui.VBox(width=360, + height=680, + style={"margin": "0px auto"}) self.aidcam = OpencvVideoWidget(self, width=340, height=480) self.aidcam.style["margin"] = "10px" @@ -184,9 +192,11 @@ def main(self): main_container.append(self.aidcam) # label show fps - self.lbl = gui.Label( - "This show FPS!", width=360, height=30, left="100px", margin="10px" - ) + self.lbl = gui.Label("This show FPS!", + width=360, + height=30, + left="100px", + margin="10px") main_container.append(self.lbl) return main_container