A computer vision-based coin detection and counting system with CLI and GUI interfaces
Project description
Coin Counter Application
A computer vision-based coin detection and counting system with both CLI and GUI interfaces. The application uses ORB (Oriented FAST and Rotated BRIEF) feature matching to identify coins and calculate their total value.
Features
- Dual Interface: Command-line and graphical user interface
- Multiple Detection Methods:
- Hough Circle Transform
- Contour-based detection with multiple thresholding techniques
- Coin Registration: Register reference coins with front and back images
- Automatic Identification: Match detected circles to registered coin types
- Value Calculation: Automatically sum the total value of detected coins
- Visual Output:
- Annotated images with detected coins
- Pie chart showing coin distribution
- Adjustable Parameters: Fine-tune detection for different lighting and backgrounds
Requirements
pip install opencv-python numpy matplotlib pillow
Dependencies
- Python 3.7+
- OpenCV (cv2)
- NumPy
- Matplotlib
- Pillow (PIL) - GUI only
- tkinter - GUI only (usually comes with Python)
Installation
- Clone or download the repository
- Install required packages:
pip install opencv-python numpy matplotlib pillow
Usage
GUI Version
Run the graphical interface:
python coin_counter_gui.py
GUI Workflow:
-
Register Coins (Register Coin tab):
- Enter coin label (e.g., "Quarter", "Dime")
- Enter coin value in dollars (e.g., 0.25)
- Browse and select front image
- Browse and select back image
- Click "Register Coin"
-
Detect Coins (Detect Coins tab):
- Click "Load Scene Image" to load an image with multiple coins
- Choose detection method (Hough or Contour)
- Adjust parameters as needed
- Click "Detect Coins"
- View results and pie chart
- Save annotated image or pie chart
CLI Version
Register a Reference Coin
python coin_counter_cli.py register --label Quarter --value 0.25 \
--front quarter_front.jpg --back quarter_back.jpg
Detect Coins Using Hough Method
python coin_counter_cli.py detect --scene coins.jpg --method hough \
--min_radius 10 --max_radius 150 --param2 30
Detect Coins Using Contour Method
python coin_counter.py detect --scene coins.jpg --method contour \
--min_area 1000 --max_area 30000 --circularity 0.6
Detection Methods
Hough Circle Transform
Best for: Clean backgrounds, well-separated coins, consistent lighting
Parameters:
--dp: Inverse ratio of accumulator resolution (default: 1.2)--min_dist: Minimum distance between circle centers (default: 30)--param1: Higher threshold for Canny edge detector (default: 100)--param2: Accumulator threshold for circle detection (default: 30)--min_radius: Minimum circle radius in pixels (default: 8)--max_radius: Maximum circle radius in pixels (default: 200)
Contour Detection
Best for: Challenging backgrounds, overlapping coins, varied lighting
Parameters:
--min_area: Minimum contour area in pixels² (default: 500)--max_area: Maximum contour area in pixels² (default: 50000)--circularity: Circularity threshold 0-1 (default: 0.7)
Uses multiple thresholding methods:
- Otsu's method
- Inverted Otsu (for dark coins on light background)
- Adaptive thresholding
- Canny edge detection
Common Parameters
--match_threshold: Minimum ORB feature matches required for identification (default: 8)- Increase for stricter matching (fewer false positives)
- Decrease for more lenient matching (better for poor quality images)
File Structure
coin_counter/
├── coin_counter.py # CLI version
├── coin_counter_gui.py # GUI version
├── README.md # This file
└── refs/ # Reference coin images (auto-created)
├── metadata.json # Coin information database
├── Quarter_front.jpg
├── Quarter_back.jpg
└── ...
Tips for Best Results
Taking Reference Images
- Use good lighting (natural daylight works best)
- Plain, contrasting background
- Coin should fill most of the frame
- Image should be in focus
- Take separate images of front and back
Scene Images
- Place coins on a contrasting background
- Avoid overlapping coins when possible
- Ensure consistent lighting
- Keep camera parallel to the surface
- Use adequate resolution (coins should be at least 50-100 pixels in diameter)
Parameter Tuning
If coins are not detected:
- Hough: Lower
param2, increasemax_radius - Contour: Lower
circularity, increasemax_area
If too many false detections:
- Hough: Increase
param2, decreasemax_radius - Contour: Increase
circularity, decreasemax_area - Increase
match_thresholdfor stricter identification
If coins are identified incorrectly:
- Lower
match_threshold(may cause more "Unknown" results) - Retake reference images with better quality
- Ensure scene image quality is good
Output Files
- Annotated Image: Shows detected coins with labels and values
- Pie Chart: Visual distribution of coin types and total value
- Console Output: Detailed detection results and summary
Limitations
- Works best with circular coins
- Requires good image quality
- May struggle with:
- Heavily worn or dirty coins
- Extreme lighting conditions
- Very small coins in large images
- Overlapping coins
- Non-uniform backgrounds
Troubleshooting
Problem: No coins detected
- Try both detection methods
- Adjust radius/area parameters to match actual coin sizes
- Check image quality and lighting
Problem: Many false detections
- Increase
param2(Hough) orcircularity(Contour) - Restrict size parameters more narrowly
- Use a cleaner background
Problem: Coins detected but labeled "Unknown"
- Lower
match_threshold - Improve reference image quality
- Ensure scene image is clear and well-lit
- Register more reference coins if needed
Problem: Wrong coin identification
- Increase
match_thresholdfor stricter matching - Retake reference images
- Ensure coins in scene are similar to reference images
How It Works
- Circle Detection: Finds circular shapes using Hough or Contour methods
- Feature Extraction: Computes ORB features for each detected circle
- Feature Matching: Compares features against registered reference coins
- Identification: Matches detected coins to registered types based on feature similarity
- Aggregation: Counts coins and calculates total value
Contributing
Feel free to submit issues or pull requests to improve the application.
Acknowledgments
Built using OpenCV's computer vision algorithms and ORB feature detection.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coin_counter-2.0.2.tar.gz.
File metadata
- Download URL: coin_counter-2.0.2.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbe2c9841d9d76080e198de2f0f2cf14fe000c6023e39713724e03483c0843c6
|
|
| MD5 |
ad293c1d450683a987427d3979024213
|
|
| BLAKE2b-256 |
3bc415999f3486dc787ab7e5a3e70cc8d21630cf6e6db9c6325c08fe04f9f13a
|
File details
Details for the file coin_counter-2.0.2-py3-none-any.whl.
File metadata
- Download URL: coin_counter-2.0.2-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7050ff116fd018da8ebfcc8da8e421ebb2949e7418147c8f46d0274313779f9
|
|
| MD5 |
b5e94da21e79d99e243d56bd3647b95d
|
|
| BLAKE2b-256 |
b3ada5bdc818681a07e2fbaf2162d1945b1585be8432cd1227eddf8b16519c49
|