Skip to content

doopii/Single-Object-Detection

Repository files navigation

Single Object Detection

A Python GUI tool for detecting objects in images using computer vision techniques. Users can select a Region of Interest (ROI) and run detection methods (template matching, color segmentation, or edge detection) with instant visual feedback. This project was developed as a student assignment, but anyone interested in image processing or OpenCV is welcome to use or modify it.


Features

  • Graphical Interface: Easy-to-use Python/Tkinter GUI.
  • ROI Selection: Draw a rectangle or polygon to select the target object.
  • Multiple Detection Methods:
    • Template Matching: Finds objects by comparing patterns (grayscale/color).
    • Color Segmentation: Detects objects by color similarity (HSV/BGR).
    • Edge Detection: Finds objects by contours and shapes.
  • Image Preprocessing: Adjust brightness, contrast, blur, and more.
  • Parameter Controls: Fine-tune detection thresholds, color tolerances, and more.
  • Visual Results: Shows detected objects and generates a detection report.

How to Use

  1. Load Image
    Click "Load Image" and choose a file (jpg, png, bmp, etc).
  2. Select ROI
    Use the mouse to draw a rectangle or polygon around the target object.
  3. Choose Detection Method
    Select template matching, color segmentation, or edge detection from the sidebar.
  4. Adjust Parameters
    Set detection thresholds, color tolerance, or edge settings (Canny filter).
  5. Detect Objects
    Click "Apply Detection" to run the algorithm.
  6. View Results
    The detected objects will be highlighted in the image, and a report of detected objects will be shown.

Installation

This project requires Python 3 and the following packages:

  • opencv-python
  • pillow
  • numpy

Install dependencies with pip:

pip install opencv-python pillow numpy

Run the program:

python main.py

Detection Methods

Template Matching

  • Detects objects by comparing the ROI with the rest of the image.
  • Supports grayscale or color pattern matching.
  • Options for rotation and scale invariance.

Color Segmentation

  • Detects objects matching a color range (HSV/BGR).
  • Adjustable color tolerance and area filtering.

Edge Detection

  • Uses Canny edge detection to find contours.
  • Adjustable low/high threshold and area filtering.

Example Output

After running detection, the GUI displays:

  • The original image with detected objects highlighted.
  • Detection Report:
    • Shows the total number of objects detected.
    • Lists object labels, areas, and methods used.
    • Example:
      TEMPLATE: 2 found
      
      Detected Objects (by label):
      Label 1: 2432 px
      Label 2: 2671 px
      
      Threshold: 0.65
      Method: grayscale
      
  • Debug info for further analysis.

You can also include a screenshot of the output window, showing the image and report side-by-side.


Credits

  • Uses OpenCV for image processing and detection algorithms.
  • Assignment for students, but open for anyone interested in computer vision or Python GUI development.

License

This project is for educational purposes. See LICENSE for details (if available).


Contributing

Feel free to fork and submit pull requests or issues. Suggestions and improvements are welcome!