Skip to content

Commit

Permalink
Update AiVirtualMouseProject.py
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamTailor committed Mar 29, 2023
1 parent d0991b8 commit a4ca3be
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions AiVirtualMouseProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,26 @@ def show(key):
x2, y2 = lmList[12][1:]
# print(x1, y1, x2, y2)


# 3. Check which fingers are up
fingers = detector.fingersUp()
if len(fingers) > 4 and fingers[1] == 1 and fingers[2] == 1 and fingers[3] == 1 and fingers[4] == 1:


# Scroll up
if len(fingers) > 4 and fingers[0] == 0 and fingers[1]==1 and fingers[2] == 1 and fingers[3] == 1 and fingers[4] == 1:
length, img, lineInfo = detector.findDistance(4, 8, img)
# print("IN FUN2")
cv2.circle(img, (lineInfo[4], lineInfo[5]),15, (0, 255, 0), cv2.FILLED)
py.scroll(50)

# drag drop item drop
if len(fingers) > 4 and fingers[0]==1 and fingers[1] == 1 and fingers[2] == 1 and fingers[3] == 1 and fingers[4] == 1:
py.mouseUp(button='left')
if (len(fingers)>3 and fingers[3] == 0) or (len(fingers)>4 and fingers[4] == 0):

# 4. Only Index Finger : Moving Mode
if len(fingers)>2 and fingers[1] == 1 and fingers[2] == 1:
if len(fingers)>4 and fingers[1] == 1 and fingers[2] == 1 and fingers[3]==0 and fingers[4]==0:
# if len(fingers)>2 and fingers[1] == 1 and fingers[2] == 1:
length, img, lineInfo = detector.findDistance(8, 12, img)

# 5. Convert Coordinates
Expand All @@ -73,7 +85,8 @@ def show(key):
plocX, plocY = clocX, clocY

# 8. Both Index and middle fingers are up : Clicking Mode Right CLick
if len(fingers) > 2 and fingers[1] == 0 and fingers[2] == 1:
# if len(fingers) > 2 and fingers[1] == 0 and fingers[2] == 1:
if len(fingers) > 4 and fingers[0] == 0 and fingers[1] == 0 and fingers[2] == 1 and fingers[3] == 0 and fingers[4] == 0:
# 9. Find distance between fingers
length, img, lineInfo = detector.findDistance(8, 12, img)
# print(length)
Expand All @@ -83,23 +96,32 @@ def show(key):
py.click(button = 'left')

# 8. Both Index and middle fingers are up : Clicking Mode Left CLick
if len(fingers) > 2 and fingers[1] == 1 and fingers[2] == 0:
# if len(fingers) > 2 and fingers[1] == 1 and fingers[2] == 0:
if len(fingers) > 4 and fingers[0] == 0 and fingers[1] == 1 and fingers[2] == 0 and fingers[3] == 0 and fingers[4] == 0:
# 9. Find distance between fingers
length, img, lineInfo = detector.findDistance(8, 12, img)
# print(length)
# 10. Click mouse if distance short
if length > 30:
cv2.circle(img, (lineInfo[4], lineInfo[5]),15, (0, 255, 0), cv2.FILLED)
py.click(button = 'right')


# Double Click
if len(fingers) > 4 and fingers[1] == 1 and fingers[2] == 1 and fingers[0]==0 and fingers[3]==0 and fingers[4]==0:
# 9. Find distance between fingers
length, img, lineInfo = detector.findDistance(8, 12, img)
# print(length)
# 10. Click mouse if distance short
if length < 25:
if length < 30:
cv2.circle(img, (lineInfo[4], lineInfo[5]),15, (0, 255, 0), cv2.FILLED)
py.doubleClick()

# Scroll Down
if len(fingers) > 4 and fingers[0] == 0 and fingers[1]==1 and fingers[2] == 1 and fingers[3] == 1 and fingers[4] == 0:
length, img, lineInfo = detector.findDistance(4, 8, img)
# print("IN FUN")
cv2.circle(img, (lineInfo[4], lineInfo[5]),15, (0, 255, 0), cv2.FILLED)
py.scroll(-50)

# Drag and Drop
if len(fingers) > 4 and fingers[0] == 0 and fingers[1] == 0 and fingers[2] == 0 and fingers[3] == 0 and fingers[4] == 0:
Expand Down Expand Up @@ -130,4 +152,6 @@ def show(key):
cv2.imshow("Image", img)
cv2.waitKey(1)
if keyboard.is_pressed('esc'):
cv2.destroyAllWindows()
cap.release()
break

0 comments on commit a4ca3be

Please sign in to comment.