A Java-based real-time motion detection application that integrates OpenCV for video processing and Swing for the graphical user interface (GUI).
This project captures video from a webcam, detects motion in real-time, and identifies the direction of motion (Left, Center, or Right). It uses OpenCV for image processing and Java Swing for the user interface.
- 📷 Real-time video capture using OpenCV.
- ⚡ Efficient motion detection using frame difference.
- 🧭 Motion direction detection: Left, Center, or Right.
- 🖥️ GUI integration for video display and feedback.
- 🎯 Visual feedback with bounding rectangles on moving objects.
- GUI Setup: A user-friendly interface with video display, direction feedback, and control buttons.
- Camera Initialization: Captures video frames using OpenCV's
VideoCapture
. - Motion Detection Algorithm:
- Grayscale conversion and Gaussian blur to reduce noise.
- Frame difference to highlight motion areas.
- Thresholding and dilation to clean up the motion regions.
- Contour detection to identify motion regions.
- Calculation of motion direction based on region centroid.
- Visual Feedback: Bounding rectangles on motion areas and direction indication (Left, Center, Right).
- Camera Control: Start and stop camera functionality.
A snapshot of the application in action:
- Java (Swing for GUI)
- OpenCV (for video processing)
- Install OpenCV and configure it with your Java project.
- Ensure you have a working webcam connected to your system.
- Run the
Main.java
file.
Main.java - createGUI(): Sets up the GUI components. - startCamera(): Initializes the camera and starts the motion detection thread. - stopCamera(): Releases the camera resources. - matToBufferedImage(): Converts OpenCV Mat objects to BufferedImage for display. - Motion Detection Logic: - Frame difference, thresholding, contour detection, and centroid-based direction determination.
Contributions are welcome! Please fork this repository, make your changes, and submit a pull request.