You are browsing as a guest. Sign up (or log in) to start making projects!

MediaPipe Hand Mouse but In java

  • 2 Devlogs
  • 8 Total hours

I built a mediapipe based mouse fully in java for my AP CSA final project. This project was fully made in java for desktop and uses DLL files compiled through bazel. In order to use this on mac one must manually compile the equivalent to dll manually.

Ship #1 Pending review

# StarkMouse - High-Performance Hand Tracking System
AP Computer Science A Final Project

StarkMouse is an advanced gesture-controlled cursor controller that allows users to operate their computer mouse hands-free. Using MediaPipe and OpenCV on a native C++ backend combined with a Java Swing overlay HUD, the application tracks hand movements, applies coordinate smoothing, and detects finger-pinch gestures to trigger mouse actions.

---

## 1. How to Use the Program

### Prerequisites
- **Java Runtime Environment (JRE) / JDK 17 or higher**
- A working **Webcam**
- Windows OS (64-bit) for native dynamic library compatibility (`stark_mouse_jni.dll` and `opencv_world3416.dll` must be in the project root directory)

### How to Build and Run
To build the project and execute the `MainApp` entry point:
1. Open a terminal in the root directory.
2. Compile and package the application:
```powershell
mvn package
```
3. Run the generated executable JAR containing all dependencies:
```powershell
java -jar target/stark-mouse-1.0.0-jar-with-dependencies.jar
```

### Controls and Gestures
- **Mouse Movement**: Hold your hand in front of the webcam. Your cursor will follow the position of the **base of your middle finger** This anchor was specifically chosen to prevent cursor jumping when fingers pinch.
- **Left Click / Click-and-Drag**: Pinch your **Thumb and Index Finger** together. Releasing the pinch releases the mouse button.
- **Right Click**: Pinch your **Thumb and Middle Finger** together.
- **Mouse Scrolling (Scroll Mode)**: Pinch your **Thumb and Pinky Finger** together. While holding the pinch, move your hand vertically:
- Moving your hand **up** scrolls up.
- Moving your hand **down** scrolls down.
- While scrolling, mouse cursor movement is locked to prevent cursor drift.
- **Toggle HUD Overlay (Ctrl+Shift+G)**: Press this global hotkey to show or hide the Swing HUD window displaying the camera feed and landmarks.
- **Repositioning HUD**: Click and drag anywhere on the HUD panel to move the floating window across your desktop screen.

---

## 2. Problems Encountered During Development

- **The "java being anti cv" bottleneck**: Initially we planned on using a method called convex hulling to detect fingers as before libraries such as mediapipe that was a common finger detection method. We then realised that convexHull was terrible and we became primary sources as to why libraries such as MediaPipe have been developed. We then tried to bend the rules of the project by calling a python script running mediapipe detection. Our idea was quickly shut down. Our final option was taking the c++ library that was wrapped for python and creating a Java Native Interface from it using a tool called bezelisk. This process took a total of 5 hours, 10 gigabites of Shaurya Mathur's hotspot and our mental stanities. Once we finally got bezel instealled and working with our library we learned that c++ itself is annoying. Initially, running the Mediapipe tracker and the JNI JVM invocation on the same thread blocked the Swing event thread, resulting in a frozen UI. We resolved this by spawning a separate native execution thread (`std::thread`) in the DLL, calling `AttachCurrentThread` to register it with the Java VM, and passing frames asynchronously.

  • 2 devlogs
  • 8h
Try project → See source code →
Open comments for this post

2h 57m 9s logged

I finally finished the project and submitted it to my teacher. I genuinely got a 95% compared to others who had just recreated games as their project. I’m not mad but rather disappointed that lack of creativity is being celebrated. Its okay tho because here are the changes

Change 1: No detecting how many fingers are held up but rather distance between fingers

Change 2: JavaSwing UI with a jarvis style bootup

Change 3: fixed double clicking and related problems

I finally finished the project and submitted it to my teacher. I genuinely got a 95% compared to others who had just recreated games as their project. I’m not mad but rather disappointed that lack of creativity is being celebrated. Its okay tho because here are the changes

Change 1: No detecting how many fingers are held up but rather distance between fingers

Change 2: JavaSwing UI with a jarvis style bootup

Change 3: fixed double clicking and related problems

Replying to @ShauryaMathur

0
4
Open comments for this post

5h 21m 2s logged

My CSA final project is due in an hour. Instead of working on a game in (Trigger warning) java s*ing I’m building an app that turns your gestures into mouse commands. I started with a group of 3 but I have been the only one who has done any work. Its due in 6 hours wish me luck

My CSA final project is due in an hour. Instead of working on a game in (Trigger warning) java s*ing I’m building an app that turns your gestures into mouse commands. I started with a group of 3 but I have been the only one who has done any work. Its due in 6 hours wish me luck

Replying to @ShauryaMathur

0
4

Followers

Loading…