import cv2
import mediapipe as mp
import time
import handDetectorDemo as htm
# import pyautogui
import autopy
import math
import numpy as np
from SoftKeyBoard import SoftKeyBoard
from Keyboard import Window
from PyQt5.QtWidgets import QDialog, QApplication
import pynput
from pynput.keyboard import Key,Controller
import sys
import os
import win32process
import subprocess
import win32api
import win32con
import win32gui
# path='C:/Program Files/Common Files/microsoft shared/ink/TabTip.exe'
# os.system(path)
########
wCam,hCam=640,480
isOpened,isScreenhot=0,0
wScr,hScr=autopy.screen.size()
smooothening=10
plocX,plocY=0,0
locX,locY=0,0
plocX12,plocY12=0,0
locX12,locY12=0,0
plocX6,plocY6=0,0
locX6,locY6=0,0
plocX5,plocY5=0,0
locX5,locY5=0,0
plocX0,plocY0=0,0
locX0,locY0=0,0
cplocX5,cplocY5=0,0
cplocX12,cplocY12=0,0
clicktime=0
frameReduction=50
recordDistance_index=0
recordDistance=0
cindexFinger_distance=0
minrate=0
times=0
clicked,alreadytoggled,alreadyclicked=[0,0,0],0,0
screenshot=[0,0,0,0,0,0,0,0]
correct=1
cdistance=0
Records=0
moveoff=0
print(wScr,hScr)
cap = cv2.VideoCapture(0)
cap.set(3,wCam)
cap.set(4,hCam)
pTime=0
cplocX=0
cplocY=0
detector=htm.handDetector(maxHands=2)
keyboard = Controller()
mouse = pynput.mouse.Controller()
Id=[4,8,12,16,20]
records=0.1
while True:
#1.find hand landmarks
success,img=cap.read()
img=detector.findhands(img)
lmList,bbox=detector.findPosition(img)
if len(lmList)==0:
if isOpened == 1:
print('isOpened=', isOpened)
myPopenObj.kill()
isOpened = 0
if len(lmList)>0 and len(bbox)==4:
# if isOpened==1:
# print('isOpened=',isOpened)
# myPopenObj.kill()
#
# # PostThreadMessage('c:/windows/system32/osk.exe', WM_QUIT, 0, 0)
# # os.system('taskkill /f /t /im ' + 'c:/windows/system32/osk.exe')
# os.system("taskkill /F /IM c:/windows/system32/osk.exe")
# # CloseHandle('c:/windows/system32/osk.exe')
# isOpened = 0
# print('isOpened=', isOpened)
# sys.exit(app.exec_())
x1,y1=lmList[8][1:]
x2,y2=lmList[12][1:]
x6,y6=lmList[6][1:]
x9, y9 = lmList[9][1:]
x7,y7=lmList[12][1:]
x17,y17=lmList[17][1:]
x5, y5 = lmList[5][1:]
x0, y0 = lmList[0][1:]
fingers=detector.fingersup()
distance=math.sqrt((x5-x7)**2+(y5-y7)**2)
indexFinger_distance = (x1 - x5) ** 2 + (y5 - y1) ** 2
# print((cindexFinger_distance-indexFinger_distance)*(cdistance-distance))
cindexFinger_distance =indexFinger_distance
cdistance=distance
# print(length)
if fingers==[1,0,0,0,0]:
# length3, img, info = detector.findDistance(8, 12, img)
length3, img, _ = detector.findDistance(4, 20, img)
# length, img, info = detector.findDistance(4, 20, img)
# print(length)
if length3 >39:
screenshot.append(0)
screenshot.pop(0)
if length3<39:
screenshot.append(1)
screenshot.pop(0)
if np.sum(np.array(screenshot))==8 and isScreenhot==0:
keyboard.press(Key.alt_l)
keyboard.press('a')
keyboard.release('a')
keyboard.release(Key.alt_l)
isScreenhot=1
alreadyclicked=1
if np.sum(np.array(screenshot)) < 8 and isScreenhot == 1:
# autopy.mouse.click()
isScreenhot = 0
# if length < 39 and isScreenhot == 1:
# autopy.mouse.click()
# isScreenhot = 0
if abs(lmList[9][2] - lmList[0][2]) < abs(lmList[9][1] - lmList[0][1]):
if lmList[9][2] - lmList[0][2] < 0:
for i in range(1, len(Id)):
if lmList[Id[i] - 1][2] - lmList[Id[i] - 2][2] < 0:
break
if i == 4 and lmList[4][2] - lmList[3][2] < 0:
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, 100)
if i == 4 and lmList[Id[0]][2] - lmList[Id[0] - 1][2] > 0:
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, -100)
if fingers[1]==1 and fingers[2]==0:
# autopy.mouse.move(wScr - clocX, clocY)
# autopy.mouse.click(None)
# autopy.mouse.toggle(None, False)
cv2.rectangle(img,(frameReduction,frameReduction),(wCam-frameReduction,hCam-frameReduction),(255,0,255),2)
x3=np.interp(x1,(frameReduction,wCam-frameReduction),(0,wScr))
y3=np.interp(y1,(frameReduction,hCam-frameReduction),(0,hScr))
locX=plocX+(x3-plocX)/smooothening
locY = plocY + (y3 - plocY) / smooothening
locX6 = plocX6 + (x6 - plocX6) / smooothening
locY6 = plocY6 + (y6 - plocY6) / smooothening
locX5 = plocX5 + (x5 - plocX5) / smooothening
locY5 = plocY5 + (y5 - plocY5) / smooothening
locX0 = plocX0 + (x0 - plocX0) / smooothening
locY0 = plocY0 + (y0 - plocY0) / smooothening
# cplocX=plocX
# cplocY=plocY
cplocY0 = plocY0
cplocX0 = plocX0
cplocY5=plocY5
cplocX5=plocX5
cplocX12=plocX12
cplocY12=plocY12
a1=(locX-plocX)**2+(locY-plocY)**2
b1=(locX0-plocX0)**2+(locY0-plocY0)**2
# if (plocX-locX)**2+(plocY-locY)**2<2:
# print(a1/b1)
# if records-(a1/b1)>9 and records-(a1/b1)<15:
# autopy.mouse.click(None)
# print(a1,b1)
# if b1<1 and a1>1.8:
# autopy.mouse.click(None)
records=a1/b1
# print((plocX-locX)**2+(plocY-locY)**2)
autopy.mouse.move(wScr-locX,locY)
cv2.circle(img,(x1,y1),15,(255,0,255),cv2.FILLED)
plocX,plocY=locX,locY
plocX0, plocY0 = locX0, locY0
if fingers[1] == 1 and fingers[2] == 1:
# autopy.mouse.toggle(None,False)
length1,img,info=detector.findDistance(8,12,img)
x31 = np.interp(x1, (frameReduction, wCam - frameReduction), (0, wScr))
y31 = np.interp(y1, (frameReduction, hCam - frameReduction), (0, hScr))
x3 = np.interp(info[4], (frameReduction, wCam - frameReduction), (0, wScr))
y3 = np.interp(info[5], (frameReduction, hCam - frameReduction), (0, hScr))
locX = plocX + (x3- plocX) / smooothening
locY = plocY + (y3- plocY) / smooothening
clocX5 = cplocX5 + (x5 - cplocX5) / smooothening
clocY5 = cplocY5 + (y5- cplocY5) / smooothening
# clocX0 = cplocX0 + (x0 - cplocX0) / smooothening
# clocY0 = cplocY0 + (y0 - cplocY0) / smooothening
clocX12 = cplocX12 + (x7 - cplocX12) / smooothening
clocY12 = cplocY12 + (y7 - cplocY12) / smooothening
# print(length1)
# print(length1)
# print(plocY - locY)
# locX, locY = plocX, plocY
# print((locX-plocX)**2+(locY-plocY)**2)
if (locX-plocX)**2+(locY-plocY)**2<6:#防抖动
locX, locY = plocX, plocY
autopy.mouse.move(wScr - locX, locY)
# plocX, plocY = locX, locY
# if plocY<locY:
# print(((plocX-locX)**2+(plocY-locY)**2)/((plocX12-locX12)**2+(plocY12-locY12)**2))
# print(Records-(plocX-locX)**2+(plocY-locY)**2)
# print(((locX-locX5)**2+(locY-locY5)**2)/((plocX-plocX5)**2+(plocY-plocY5)**2))
# print((plocX - locX)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
AI手势识别控制键盘.rar (2个子文件)
AI键鼠
handDetectorDemo.py 6KB
cvMice.py 19KB
共 2 条
- 1
资源评论
好玩的Matlab(NCEPU)
- 粉丝: 4w+
- 资源: 31
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- apk.tw_LineLite_v8a_v.2.17.1_sign.apk
- Elasticsearch实战:构建高效搜索系统的秘诀.zip
- HTML+CSS+JS网页设计:从入门到精通.zip
- 数据库课程设计:从理论到实践的全面指南.zip
- Python闭包:深入理解与应用场景解析.zip
- Win64OpenSSL-3-3-0.exe
- 课高分程设计-基于C++实现的民航飞行与地图简易管理系统-南京航空航天大学
- 航天器遥测数据故障检测系统python源码+文档说明+数据库(课程设计)
- 北京航空航天大学操作系统课设+ppt+实验报告
- 基于Vue+Echarts实现风力发电机中传感器的数据展示监控可视化系统+源代码+文档说明(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功