def getSymmetries(inputFile, data): symmetries = [] symmetryList = eng.pySym(inputFile) #pySym = matlab file height, _, _ = data.shape for sym in symmetryList: line = [sym[0], sym[1], sym[2], sym[3]] slope = util.getSlope(line, height) score = sym[4] if len(sym) < 6: normScore = 1.0 else: normScore = sym[5] newSym = [line, slope, score, normScore] symmetries.append(newSym) return symmetries
if len(event_que) == 10: angle_change = int(event_que[9][1]) dist_change = int(event_que[9][0]) event_que.pop(0) if abs(dist_change) > 0 or abs(angle_change) > 30: msg = str(dist_change) gesFound = 10 if dist_change > 200: k1.tap_key('-', n=2) #msg+=' Z out' else: k1.tap_key(k1.numpad_keys['Add'], n=2) #msg+=' Z in' event_que.append((ut.getDist(l[0], l[1]), ut.getSlope(l[0], l[1]))) cv2.putText( img, 'que-> ' + str(len(event_que)) + ' ' + str(len(l)) + ' ' + str(press_count), (300, 50), font, 1, (255, 255, 255), 2, cv2.LINE_AA) if gesFound > 0: cv2.putText(img, msg, (100, 100), font, 2, (255, 255, 255), 10, cv2.LINE_AA) gesFound -= 1 #fps calc fps = int(1 / (time.time() - t)) cv2.putText(img, "FPS: " + str(fps), (50, 50), font, 1, (255, 255, 255), 2, cv2.LINE_AA) cv2.imshow('Frame', img)
_,contours,hierarchy = cv2.findContours(th1.copy(),cv2.RETR_EXTERNAL, 2) cnts=ut.getContourBiggerThan(contours,minArea=3000,maxArea=40000) line=[] for cnt in cnts: x,y,w,h = cv2.boundingRect(cnt) _,resp=ut.getGestureImg(cnt,img,th1,model) M = cv2.moments(cnt) cx = int(M['m10']/M['m00']) cy = int(M['m01']/M['m00']) line.append((cx,cy)) cv2.circle(img,(cx,cy),5,[0,255,0],-1) cv2.putText(img,resp,(x,y), font,1,(255,255,255),2,cv2.LINE_AA) if len(line)==2: pt1=line[0] pt2=line[1] ang=int(ut.getSlope(pt1,pt2)) cv2.putText(img,'Angle-> '+str(ang),(400,50), font,1,(255,255,255),2,cv2.LINE_AA) if ang>0: cv2.putText(img,'RIGHT',((pt1[0]+pt2[0])/2,(pt1[1]+pt2[1])/2), font,3,(255,255,255),2,cv2.LINE_AA) else: cv2.putText(img,'LEFT',((pt1[0]+pt2[0])/2,(pt1[1]+pt2[1])/2), font,3,(255,255,255),2,cv2.LINE_AA) cv2.line(img,line[0],line[1],[0,0,255],5) fps=int(1/(time.time()-t)) cv2.putText(img,"FPS: "+str(fps),(50,50), font,1,(255,255,255),2,cv2.LINE_AA) cv2.imshow('Frame',img) old_gray = gray.copy() k = 0xFF & cv2.waitKey(10) if k == 27: break cap.release()
def calcSlope2(data): return util.getSlope([ data['line2x1'], data['line2y1'], data['line2x2'], data['line2y2'] ], data['height'])
def calcSlope1(data): return util.getSlope([ data['line1x1'], data['line1y1'], data['line1x2'], data['line1y2'] ], data['height'])
if abs(dist_change)>0 or abs(angle_change)>30: msg=str(dist_change) gesFound=10 if dist_change>200: k1.tap_key('-',n=2) #msg+=' Z out' else: k1.tap_key(k1.numpad_keys['Add'],n=2) #msg+=' Z in' event_que.append((ut.getDist(l[0],l[1]),ut.getSlope(l[0],l[1]))) cv2.putText(img,'que-> '+str(len(event_que))+' '+str(len(l))+' '+str(press_count),(300,50), font,1,(255,255,255),2,cv2.LINE_AA) if gesFound>0: cv2.putText(img,msg,(100,100), font,2,(255,255,255),10,cv2.LINE_AA) gesFound-=1 #fps calc fps=int(1/(time.time()-t)) cv2.putText(img,"FPS: "+str(fps),(50,50), font,1,(255,255,255),2,cv2.LINE_AA) cv2.imshow('Frame',img) #key press events k = 0xFF & cv2.waitKey(10)