diff --git a/gui_cvs/hello.py b/gui_cvs/hello.py index 4e74c80..3c22f63 100644 --- a/gui_cvs/hello.py +++ b/gui_cvs/hello.py @@ -4,10 +4,8 @@ def __init__(self, *args): super(MyApp, self).__init__(*args) def main(self): - lbl = gui.Label("Hello world!", width=100, height=30) - # return of the root widget - return lbl + return gui.Label("Hello world!", width=100, height=30) initcv(cvs.openwin) startcv(MyApp) \ No newline at end of file diff --git a/gui_cvs/table.py b/gui_cvs/table.py index 7650f52..1dd4279 100755 --- a/gui_cvs/table.py +++ b/gui_cvs/table.py @@ -54,8 +54,8 @@ def on_column_count_change(self, emitter, value, table): table.set_column_count(int(value)) def fill_table(self, emitter, table): - for ri in range(0, table.row_count()): - for ci in range(0, table.column_count()): + 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))) def on_use_title_change(self, emitter, value, table): diff --git a/gui_wizard/helloworld.py b/gui_wizard/helloworld.py index ed11d0d..77e35b3 100644 --- a/gui_wizard/helloworld.py +++ b/gui_wizard/helloworld.py @@ -11,7 +11,7 @@ class untitled(App): def __init__(self, *args, **kwargs): #DON'T MAKE CHANGES HERE, THIS METHOD GETS OVERWRITTEN WHEN SAVING IN THE EDITOR - if not 'editing_mode' in kwargs.keys(): + if 'editing_mode' not in kwargs.keys(): super(untitled, self).__init__(*args, static_file_path={'my_res':'./res/'}) def idle(self): @@ -43,7 +43,6 @@ def construct_ui(self): def onclick_button(self, emitter): self.mainContainer.children['label'].set_text('hello world') - pass diff --git a/src/cvs/webcam.py b/src/cvs/webcam.py index 413050a..be7b29c 100644 --- a/src/cvs/webcam.py +++ b/src/cvs/webcam.py @@ -7,7 +7,7 @@ class untitled(App): def __init__(self, *args, **kwargs): #DON'T MAKE CHANGES HERE, THIS METHOD GETS OVERWRITTEN WHEN SAVING IN THE EDITOR - if not 'editing_mode' in kwargs.keys(): + if 'editing_mode' not in kwargs.keys(): super(untitled, self).__init__(*args, static_file_path={'my_res':'./res/'}) def idle(self): diff --git a/src/facencnn/facepose.py b/src/facencnn/facepose.py index 6594ded..2e47b22 100644 --- a/src/facencnn/facepose.py +++ b/src/facencnn/facepose.py @@ -10,28 +10,28 @@ def main(): fcount=0 start = time.time() - + while True: sleep(30) img =cvs.read() if img is None : continue - - fcount=fcount+1 + + fcount += 1 # global lbs lbs = 'Average FPS: '+ str(fcount / (time.time() - start)) cvs.setLbs(lbs) - + if camid==1: img=cv2.flip(img,1) - + #img=cv2.resize(img,(112,112)) image_char = img.astype(np.uint8).tostring() rets = facerecog.getfacepose(img.shape[0], img.shape[1], image_char) #print 'rets:',rets - for ret in rets: + for ret in rets: #for ret in each: print ('draw bounding box for the face') #cvs.infoshow('draw bounding box for the face') @@ -45,10 +45,10 @@ def main(): #print keypoint p1 = (int(rect[0]), int(rect[1])) p2 = (int(rect[0]+rect[2]), int(rect[1]+rect[3])) - + #draw_name(img, rect, ret['name']) cvs.rectangle(img, p1,p2, (0, 255, 0) , 3, 1) - for p in range(0,106): + for p in range(106): #print p*2,' = ',keypoint[p*2] #print p*2+1,' = ',keypoint[p*2+1] k1=int(rect[0]+keypoint[p*2]) @@ -65,7 +65,6 @@ def __init__(self, *args): def idle(self): #idle function called every update cycle self.lbl.set_text(cvs.getLbs()) - pass def main(self): #creating a container VBox type, vertical (you can use also HBox or Widget) diff --git a/src/handtf/utils/detector_utils.py b/src/handtf/utils/detector_utils.py index c7ae2a8..6b546e6 100644 --- a/src/handtf/utils/detector_utils.py +++ b/src/handtf/utils/detector_utils.py @@ -67,9 +67,7 @@ def draw_box_on_image(num_hands_detect, score_thresh, scores, boxes, classes, im id ='closed' avg_width = 3.0 # To compensate bbox size change - if i == 0: color = color0 - else: color = color1 - + color = color0 if i == 0 else color1 (left, right, top, bottom) = (boxes[i][1] * im_width, boxes[i][3] * im_width, boxes[i][0] * im_height, boxes[i][2] * im_height) p1 = (int(left), int(top)) diff --git a/src/handtf/webcam.py b/src/handtf/webcam.py index 9dbad79..b6509c1 100644 --- a/src/handtf/webcam.py +++ b/src/handtf/webcam.py @@ -38,7 +38,7 @@ def main(): continue frame = cv2.resize(frame, (640, 480)) - if im_height == None: + if im_height is None: im_height, im_width = frame.shape[:2] # Convert image to rgb since opencv loads images in bgr, if not accuracy will decrease @@ -50,8 +50,8 @@ def main(): # Run image through tensorflow graph boxes, scores, classes = detector_utils.detect_objects( frame, detection_graph, sess) - - + + # Draw bounding boxeses and text detector_utils.draw_box_on_image( num_hands_detect, score_thresh, scores, boxes, classes, im_width, im_height, frame) @@ -61,21 +61,21 @@ def main(): elapsed_time = (datetime.datetime.now() - start_time).total_seconds() fps = num_frames / elapsed_time - + # Display FPS on frame lbs = "FPS : " + str("{0:.2f}".format(fps)) cvs.setLbs(lbs) if args['display']: - + detector_utils.draw_text_on_image("FPS : " + str("{0:.2f}".format(fps)), frame) cvs.imshow(cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)) - + print("Average FPS: ", str("{0:.2f}".format(fps))) - + except KeyboardInterrupt: print("Average FPS: ", str("{0:.2f}".format(fps))) @@ -88,7 +88,6 @@ def __init__(self, *args): def idle(self): #idle function called every update cycle self.lbl.set_text(cvs.getLbs()) - pass def main(self): # initcv(process) diff --git a/src/mutilpose/posenet/converter/config.py b/src/mutilpose/posenet/converter/config.py index a3b4736..8a61c1b 100644 --- a/src/mutilpose/posenet/converter/config.py +++ b/src/mutilpose/posenet/converter/config.py @@ -6,5 +6,4 @@ def load_config(config_name='config.yaml'): cfg_f = open(os.path.join(BASE_DIR, config_name), "r+") - cfg = yaml.load(cfg_f) - return cfg + return yaml.load(cfg_f) diff --git a/src/mutilpose/posenet/decode_multi.py b/src/mutilpose/posenet/decode_multi.py index cdcb60e..87a92da 100644 --- a/src/mutilpose/posenet/decode_multi.py +++ b/src/mutilpose/posenet/decode_multi.py @@ -5,10 +5,10 @@ def within_nms_radius(poses, squared_nms_radius, point, keypoint_id): - for _, _, pose_coord in poses: - if np.sum((pose_coord[keypoint_id] - point) ** 2) <= squared_nms_radius: - return True - return False + return any( + 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): diff --git a/src/mutilpose/posenet/model.py b/src/mutilpose/posenet/model.py index 2b55ba5..da992a4 100644 --- a/src/mutilpose/posenet/model.py +++ b/src/mutilpose/posenet/model.py @@ -25,11 +25,10 @@ def load_config(model_ord): output_stride = converter_cfg['outputStride'] checkpoint_name = checkpoints[model_ord] - model_cfg = { + return { 'output_stride': output_stride, 'checkpoint_name': checkpoint_name, } - return model_cfg def load_model(model_id, sess, model_dir=MODEL_DIR): diff --git a/src/mutilpose/posenet/utils.py b/src/mutilpose/posenet/utils.py index aff4d24..fdc6631 100644 --- a/src/mutilpose/posenet/utils.py +++ b/src/mutilpose/posenet/utils.py @@ -48,8 +48,7 @@ def draw_keypoints( if ks < min_part_confidence: continue cv_keypoints.append(cv2.KeyPoint(kc[1], kc[0], 10. * ks)) - out_img = cv2.drawKeypoints(img, cv_keypoints, outImage=np.array([])) - return out_img + return cv2.drawKeypoints(img, cv_keypoints, outImage=np.array([])) def get_adjacent_keypoints(keypoint_scores, keypoint_coords, min_confidence=0.1): diff --git a/src/mutilpose/webcam_demo.py b/src/mutilpose/webcam_demo.py index 639fb2a..213be37 100644 --- a/src/mutilpose/webcam_demo.py +++ b/src/mutilpose/webcam_demo.py @@ -86,7 +86,6 @@ def __init__(self, *args): def idle(self): #idle function called every update cycle,we show the FPS self.lbl.set_text(cvs.getLbs()) - pass def main(self): #creating a container VBox type, vertical (you can use also HBox or Widget) diff --git a/src/singlepose/webpose.py b/src/singlepose/webpose.py index 7490877..49d0294 100644 --- a/src/singlepose/webpose.py +++ b/src/singlepose/webpose.py @@ -40,7 +40,7 @@ def main(): 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() while True: @@ -50,8 +50,8 @@ def main(): sleep(50) continue - - fcount=fcount+1 + + fcount += 1 # global lbs lbs = 'Average FPS: '+ str(fcount / (time.time() - start)) cvs.setLbs(lbs) @@ -60,8 +60,8 @@ def main(): input_image = resizeimg(img,width,height) tmpimg = img tmpimg = cv2.resize(tmpimg, (width,height)) - - + + input_image = np.array(input_image,dtype=np.float32) input_image = input_image.reshape(1,width,height,3) heatmaps_result,offsets_result,displacementFwd_result,displacementBwd_result = sess.run( @@ -71,7 +71,7 @@ def main(): [255, 0, 255], [255, 0, 255]] - + pairs = [[5,6],[5,7],[6,8],[7,9],[8,10],[5,11],[6,12],[11,12],[11,13],[12,14],[13,15],[14,16]] keypoint = [] ckeypoint = [] @@ -81,18 +81,18 @@ def main(): offsets_result=offsets_result[0] bbb= np.transpose(offsets_result,(2, 0, 1)) - for k in range(0,17): + for k in range(17): heatmaps_result=aaaa[k] maxheat=np.max(heatmaps_result) re=np.where(heatmaps_result==maxheat) - + ry=re[0][0] rx=re[1][0] offsets_resulty=bbb[0+k] offsets_resultx=bbb[17+k] ofx=int(offsets_resultx[ry][rx]+0.5) ofy=int(offsets_resulty[ry][rx]+0.5) - + px=(rx)*16+ofx py=(ry)*16+ofy if maxheat>0.7 : @@ -102,7 +102,7 @@ def main(): else : keypoint.append(-1); keypoint.append(-1); - + ckeypoint.append(keypoint[0]) ckeypoint.append(keypoint[1]) @@ -118,11 +118,11 @@ def main(): ckeypoint.append(keypoint[2*i+1]) ckeypoint.append(keypoint[2*i+2]) ckeypoint.append(keypoint[2*i+2+1]) - + for pair in pairs: 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]),(0,0,255),1) - + cvs.imshow(tmpimg) print ('frames:',fcount) @@ -134,8 +134,7 @@ def __init__(self, *args): def idle(self): #idle function called every update cycle - self.lbl.set_text(cvs.getLbs()) - pass + self.lbl.set_text(cvs.getLbs()) def main(self): #creating a container VBox type, vertical (you can use also HBox or Widget)