A fun and interactive desktop application that lets you try on virtual glasses in real-time using your webcam! Built using Java, OpenCV, and Swing GUI.
- Real-time face detection using Haar cascades
- Change between 4 different virtual glasses by pressing keys
1to4 - Live webcam feed using OpenCV’s
VideoCapture - Transparent PNG glasses overlay support
- No more blue tint issue — accurate colors maintained
- Java (JDK 8 or above)
- OpenCV 4.1.1
- Swing (Java GUI)
- Haar Cascade Classifier for face detection
- Maven (optional, for dependency management)
VirtualTryOnJava/
│
├── lib/
│ ├── opencv_java4110.dll # OpenCV DLL file
│ └── opencv-4110.jar # OpenCV Java JAR
│
├── src/
│ └── main/
│ ├── java/
│ │ └── tryon/
│ │ └── VirtualTryOn.java # Main Java class
│ │
│ └── resources/
│ ├── models/
│ │ ├── haarcascade_frontalface_alt.xml # Face detection model
│ │ └── haarcascade_eye.xml # Optional eye model
│ │
│ └── glasses/
│ ├── glasses_01.png
│ ├── glasses_02.png
│ ├── glasses_03.png
│ └── glasses_04.png
│
├── pom.xml # Maven configuration file
└── README.md # Project documentation
---
## How to Run the Project
Follow these steps to successfully run the Virtual Glasses Try-On project on your local machine:
---
### 1. **Clone the Repository**
```bash
git clone https://github.com/your-username/VirtualTryOnJava.git
cd VirtualTryOnJava
- Make sure Java (JDK 17 or above) is installed.
- Download OpenCV for Windows from the official site: https://opencv.org/releases/
- Extract the downloaded ZIP.
- Inside the extracted folder, navigate to:
opencv/build/java/x64/opencv_java4110.dll - Copy the file
opencv_java4110.dlland place it in your project’s and also copy the file 'opencv-4110.jar'VirtualTryOnJava/lib/
In src/main/java/tryon/VirtualTryOn.java, update this line:
System.load("C:\\Users\\YourName\\path\\to\\opencv_java4110.dll");✅ Replace the path above with the absolute path to your actual .dll file.
Example:
System.load("C:\\Users\\Vaishnavi\\Downloads\\VirtualTryOnJava\\lib\\opencv_java4110.dll");- Open the project.
- Right-click
VirtualTryOn.javaand run it.
Run the following commands:
mvn clean install
mvn compile exec:java "-Dexec.mainClass=tryon.VirtualTryOn" "-Dexec.jvmArgs=-Djava.library.path=lib"Now your webcam will open and detect your face with virtual glasses overlaid!
Press keys 1–4 to switch between glasses styles in real-time.