def input_control(self, count_defects, img_src):
# update position difference with previous frame (for move mouse)
d_x, d_y = 0, 0
if self.preCX is not None:
d_x = self.ROIx - self.preCX
d_y = self.ROIy - self.preCY
# checking current command, and filter out unstable hand gesture
cur_cmd = 0
if self.cmd_switch:
if self.last_cmds.count(count_defects) >= self.last_cmds.n_maj:
cur_cmd = count_defects
#print 'major command is ', cur_cmd
else:
cur_cmd = 0 # self.last_cmds.major()
else:
cur_cmd = count_defects
# send mouse input event depend on hand gesture
if cur_cmd == 1:
str1 = '2, move mouse dx,dy = ' + str(d_x*3) + ', ' + str(d_y*3)
cv2.putText(img_src, str1, (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2)
if self.cmd_switch:
pyautogui.moveRel(d_x*3, d_y*3)
self.last_cmds.push(count_defects)
#pyautogui.mouseDown(button='left')
#pyautogui.moveRel(d_x, d_y)
#else:
# pyautogui.mouseUp(button='left')
elif cur_cmd == 2:
cv2.putText(img_src, '3 Left (rotate)', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2)
if self.cmd_switch:
pyautogui.dragRel(d_x, d_y, button='left')
self.last_cmds.push(count_defects)
#pyautogui.scroll(d_y,pause=0.2)
elif cur_cmd == 3:
cv2.putText(img_src, '4 middle (zoom)', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2)
if self.cmd_switch:
pyautogui.dragRel(d_x, d_y, button='middle')
self.last_cmds.push(count_defects)
elif cur_cmd == 4:
cv2.putText(img_src, '5 right (pan)', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2)
if self.cmd_switch:
pyautogui.dragRel(d_x, d_y, button='right')
self.last_cmds.push(count_defects)
elif cur_cmd == 5:
cv2.putText(img_src, '1 fingertip show up', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2)
if self.cmd_switch:
self.last_cmds.push(count_defects)
else:
cv2.putText(img_src, 'No finger detect!', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2)
if self.cmd_switch:
self.last_cmds.push(count_defects) # no finger detect or wrong gesture
# testing pyautogui
评论列表
文章目录