Roboflow Fork Prong Detector
This project provides a Python script for automated detection and measurement of fork prongs in images using computer vision and machine learning techniques. The script is designed to process images of forks, identify prong tips, determine fork orientation, and calculate distances between prongs in millimeters.
Features
- Image Preprocessing: Converts images to grayscale and applies median filtering for noise reduction.
- Edge Detection & Prong Identification: Uses PCA (Principal Component Analysis) and clustering (KMeans) to identify prong regions and tips.
- Fork Orientation Detection: Determines whether the fork is oriented vertically or horizontally.
- Prong Counting: Dynamically detects the number of prongs (3 or 4) and labels them in order.
- Distance Calculation: Computes the distances between adjacent prongs and converts pixel distances to millimeters using a reference span.
- Visualization: Generates annotated plots showing detected prongs, fork orientation, and measurement tables.
- Batch Processing: Processes all images in a specified folder, skipping non-image files and previously processed outputs.
- Progress Reporting: Uses the
rich library to display progress bars and status updates during batch processing.
How It Works
- Setup:
- Requires a Roboflow API key set as the environment variable
ROBOFLOW_API_KEY.
- Images should be placed in the
data/forks directory.
- Processing:
- For each image, the script preprocesses the image and sends it to the Roboflow inference API to detect fork objects and their edge points.
- The detected points are analyzed using PCA to align and rotate the fork for consistent analysis.
- Prong regions are identified, and clustering algorithms are used to find prong tips.
- The script determines the fork’s orientation and orders the prongs accordingly.
- Distances between prongs are calculated and converted to millimeters.
- Annotated visualizations and measurement tables are saved to the
data/analysis directory.
- Output:
- Annotated images with detected prongs and measurement tables.
- Progress and summary information printed to the console.
Requirements
- Python 3.7+
- Packages:
- numpy
- matplotlib
- scikit-learn
- Pillow
- rich
- inference-sdk
Install dependencies with:
pip install numpy matplotlib scikit-learn Pillow rich inference-sdk
Usage
- Set your Roboflow API key:
export ROBOFLOW_API_KEY=your_api_key_here
- Place fork images in the
data/forks directory.
- Run the script:
File Structure
Roboflow.py: Main script for fork prong detection and measurement.
data/forks/: Input images of forks.
data/analysis/: Output annotated images and measurement tables.
Notes
-
The script is designed for batch processing and will skip files that are not images or are previously generated outputs.
-
The pixel-to-millimeter conversion uses a reference span (default: 15mm) between the outermost prongs.