gesture_hci.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:CE264-Computer_Vision 作者: RobinCPC 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号