Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions AIVirtualMouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
pTime = 0
plocX, plocY = 0, 0
clocX, clocY = 0, 0
cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture(
0
)
cap.set(3, wCam)
cap.set(4, hCam)

detector = htm.handDetector(maxHands=1)
wScr, hScr = autopy.screen.size()

# print(wScr, hScr)
print(wScr, hScr)

while True:
# Step1: Find the landmarks
Expand Down Expand Up @@ -50,8 +52,11 @@
clocY = plocY + (y3 - plocY) / smoothening

# Step7: Move Mouse
autopy.mouse.move(wScr - clocX, clocY)
cv2.circle(img, (x1, y1), 15, (255, 0, 255), cv2.FILLED)
try:
autopy.mouse.move(wScr - clocX, clocY)
cv2.circle(img, (x1, y1), 15, (255, 0, 255), cv2.FILLED)
except ValueError:
pass
plocX, plocY = clocX, clocY

# Step8: Both Index and middle are up: Clicking Mode
Expand All @@ -63,7 +68,10 @@
# Step10: Click mouse if distance short
if length < 40:
cv2.circle(img, (lineInfo[4], lineInfo[5]), 15, (0, 255, 0), cv2.FILLED)
# Click mouse, continue moving mouse
autopy.mouse.click()
time.sleep(0.1)
autopy.mouse.move(wScr - clocX, clocY)

# Step11: Frame rate
cTime = time.time()
Expand All @@ -73,4 +81,6 @@

# Step12: Display
cv2.imshow("Image", img)
cv2.waitKey(1)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
2 changes: 1 addition & 1 deletion HandTrackingModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class handDetector():
def __init__(self, mode=False, maxHands=2, detectionCon=0.5, trackCon=0.5):
def __init__(self, mode=False, maxHands=2, detectionCon=1, trackCon=0.5):
self.mode = mode
self.maxHands = maxHands
self.detectionCon = detectionCon
Expand Down