|
1 |
| -# Game-controller-using-python |
| 1 | + |
| 2 | +# Game Controller using python and openCV |
| 3 | + |
| 4 | +This project is a simple implementation of a game controller using Python and OpenCV. With this controller, you can control games using hand gestures captured by a webcam. This project is a great way to learn about computer vision, gesture recognition, and game development. |
| 5 | +let's start............... |
| 6 | + |
| 7 | +To make this project you need to follow this step:- |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +Install package with pip |
| 21 | + |
| 22 | +```bash |
| 23 | +pip install cvzone==1.4.1 |
| 24 | +pip install mediapipe==0.8.3.1 |
| 25 | +``` |
| 26 | + |
| 27 | +## Deployment |
| 28 | + |
| 29 | +To deploy this project run |
| 30 | + |
| 31 | +```bash |
| 32 | +# Please Subscribe my youtube channel "Problem Solve import cv2 |
| 33 | +from cvzone.HandTrackingModule import HandDetector |
| 34 | +from pynput.keyboard import Key, Controller |
| 35 | + |
| 36 | +cap = cv2.VideoCapture(0) |
| 37 | +cap.set(3, 320) |
| 38 | +cap.set(4, 210) |
| 39 | + |
| 40 | +detector = HandDetector(detectionCon= 0.7, maxHands= 1) |
| 41 | +keyboard = Controller() |
| 42 | + |
| 43 | +while True: |
| 44 | + _, img = cap.read() |
| 45 | + hands, img = detector.findHands(img) |
| 46 | + |
| 47 | + if hands: |
| 48 | + finger = detector.fingersUp(hands[0]) |
| 49 | + if finger == [0,0,0,0,0]: |
| 50 | + keyboard.press(Key.left) |
| 51 | + keyboard.release(Key.right) |
| 52 | + |
| 53 | + elif finger == [1,1,1,1,1]: |
| 54 | + keyboard.press(Key.right) |
| 55 | + keyboard.release(Key.left) |
| 56 | + |
| 57 | + else: |
| 58 | + keyboard.release(Key.left) |
| 59 | + keyboard.release(Key.right) |
| 60 | + |
| 61 | + |
| 62 | + cv2.imshow("Problem Solve with Ridoy", img) |
| 63 | + if cv2.waitKey(1) == ord ("q"): |
| 64 | + break |
| 65 | +``` |
| 66 | +# Output |
| 67 | + |
| 68 | +
|
| 69 | +
|
| 70 | +
|
| 71 | +
|
| 72 | +
|
| 73 | +## You can follow me |
| 74 | +
|
| 75 | +Facebook:- https://www.facebook.com/problemsolvewithridoy/ |
| 76 | +
|
| 77 | +Linkedin:- https://www.linkedin.com/in/ridoyhossain/ |
| 78 | +
|
| 79 | +YouTube:- https://www.youtube.com/@problemsolvewithridoy |
| 80 | +
|
| 81 | + |
| 82 | +
|
| 83 | +If you have any confusion, please feel free to contact me. Thank you |
| 84 | +
|
| 85 | +
|
| 86 | +## License |
| 87 | +This script is released under the MIT License. Feel free to use, modify, and distribute it as you wish. If you find any bugs or have any suggestions for improvement, please submit an issue or a pull request on this repository. |
| 88 | +
|
0 commit comments