Skip to content

A real-time motion detection application built using Java and OpenCV. It captures video from a webcam, detects motion, and determines its direction (Left, Center, or Right). The project features a user-friendly Swing GUI for video display and motion feedback, with efficient motion processing algorithms.

Notifications You must be signed in to change notification settings

NdaedzoPhoshoko/Robot-With-One-Eye

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Motion Detection Using OpenCV and Java Swing

A Java-based real-time motion detection application that integrates OpenCV for video processing and Swing for the graphical user interface (GUI).

📋 Project Overview

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.

🛠️ Features

  • 📷 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.

🔧 How It Works

  1. GUI Setup: A user-friendly interface with video display, direction feedback, and control buttons.
  2. Camera Initialization: Captures video frames using OpenCV's VideoCapture.
  3. 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.
  4. Visual Feedback: Bounding rectangles on motion areas and direction indication (Left, Center, Right).
  5. Camera Control: Start and stop camera functionality.

🖼️ Screenshot

A snapshot of the application in action:

Motion Detection Application Screenshot

💻 Technologies Used

  • Java (Swing for GUI)
  • OpenCV (for video processing)

🚀 How to Run

  1. Install OpenCV and configure it with your Java project.
  2. Ensure you have a working webcam connected to your system.
  3. Run the Main.java file.

📄 Code Overview

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.
    

🤝 Contributing

Contributions are welcome! Please fork this repository, make your changes, and submit a pull request.

About

A real-time motion detection application built using Java and OpenCV. It captures video from a webcam, detects motion, and determines its direction (Left, Center, or Right). The project features a user-friendly Swing GUI for video display and motion feedback, with efficient motion processing algorithms.

Resources

Stars

Watchers

Forks

Languages