coin-counter


Namecoin-counter JSON
Version 2.0.1 PyPI version JSON
download
home_pageNone
SummaryA computer vision-based coin detection and counting system with CLI and GUI interfaces
upload_time2025-10-08 14:34:05
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT
keywords coin counter computer-vision opencv detection image-processing
VCS
bugtrack_url
requirements numpy opencv-python json argparse
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash
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

1. Clone or download the repository
2. Install required packages:
```bash
pip install opencv-python numpy matplotlib pillow
```

## Usage

### GUI Version

Run the graphical interface:

```bash
python coin_counter_gui.py
```

#### GUI Workflow:

1. **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"

2. **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

```bash
python coin_counter_cli.py register --label Quarter --value 0.25 \
  --front quarter_front.jpg --back quarter_back.jpg
```

#### Detect Coins Using Hough Method

```bash
python coin_counter_cli.py detect --scene coins.jpg --method hough \
  --min_radius 10 --max_radius 150 --param2 30
```

#### Detect Coins Using Contour Method

```bash
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

1. Use good lighting (natural daylight works best)
2. Plain, contrasting background
3. Coin should fill most of the frame
4. Image should be in focus
5. Take separate images of front and back

### Scene Images
1. Place coins on a contrasting background
2. Avoid overlapping coins when possible
3. Ensure consistent lighting
4. Keep camera parallel to the surface
5. Use adequate resolution (coins should be at least 50-100 pixels in diameter)

### Parameter Tuning

**If coins are not detected:**
- Hough: Lower `param2`, increase `max_radius`
- Contour: Lower `circularity`, increase `max_area`

**If too many false detections:**
- Hough: Increase `param2`, decrease `max_radius`
- Contour: Increase `circularity`, decrease `max_area`
- Increase `match_threshold` for 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) or `circularity` (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_threshold` for stricter matching
- Retake reference images
- Ensure coins in scene are similar to reference images

## How It Works

1. **Circle Detection**: Finds circular shapes using Hough or Contour methods
2. **Feature Extraction**: Computes ORB features for each detected circle
3. **Feature Matching**: Compares features against registered reference coins
4. **Identification**: Matches detected coins to registered types based on feature similarity
5. **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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "coin-counter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "coin, counter, computer-vision, opencv, detection, image-processing",
    "author": null,
    "author_email": "Ibteeker Mahir Ishum <mhrisham@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1d/7e/f58101caacbe3702df932dcb38e974d244f360025df5ba0fecd102c8afcc/coin_counter-2.0.1.tar.gz",
    "platform": null,
    "description": "# Coin Counter Application\r\n\r\nA 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.\r\n\r\n## Features\r\n\r\n- **Dual Interface**: Command-line and graphical user interface\r\n- **Multiple Detection Methods**: \r\n  - Hough Circle Transform\r\n  - Contour-based detection with multiple thresholding techniques\r\n- **Coin Registration**: Register reference coins with front and back images\r\n- **Automatic Identification**: Match detected circles to registered coin types\r\n- **Value Calculation**: Automatically sum the total value of detected coins\r\n- **Visual Output**: \r\n  - Annotated images with detected coins\r\n  - Pie chart showing coin distribution\r\n- **Adjustable Parameters**: Fine-tune detection for different lighting and backgrounds\r\n\r\n## Requirements\r\n\r\n```bash\r\npip install opencv-python numpy matplotlib pillow\r\n```\r\n\r\n### Dependencies\r\n\r\n- Python 3.7+\r\n- OpenCV (cv2)\r\n- NumPy\r\n- Matplotlib\r\n- Pillow (PIL) - GUI only\r\n- tkinter - GUI only (usually comes with Python)\r\n\r\n## Installation\r\n\r\n1. Clone or download the repository\r\n2. Install required packages:\r\n```bash\r\npip install opencv-python numpy matplotlib pillow\r\n```\r\n\r\n## Usage\r\n\r\n### GUI Version\r\n\r\nRun the graphical interface:\r\n\r\n```bash\r\npython coin_counter_gui.py\r\n```\r\n\r\n#### GUI Workflow:\r\n\r\n1. **Register Coins** (Register Coin tab):\r\n   - Enter coin label (e.g., \"Quarter\", \"Dime\")\r\n   - Enter coin value in dollars (e.g., 0.25)\r\n   - Browse and select front image\r\n   - Browse and select back image\r\n   - Click \"Register Coin\"\r\n\r\n2. **Detect Coins** (Detect Coins tab):\r\n   - Click \"Load Scene Image\" to load an image with multiple coins\r\n   - Choose detection method (Hough or Contour)\r\n   - Adjust parameters as needed\r\n   - Click \"Detect Coins\"\r\n   - View results and pie chart\r\n   - Save annotated image or pie chart\r\n\r\n### CLI Version\r\n\r\n#### Register a Reference Coin\r\n\r\n```bash\r\npython coin_counter_cli.py register --label Quarter --value 0.25 \\\r\n  --front quarter_front.jpg --back quarter_back.jpg\r\n```\r\n\r\n#### Detect Coins Using Hough Method\r\n\r\n```bash\r\npython coin_counter_cli.py detect --scene coins.jpg --method hough \\\r\n  --min_radius 10 --max_radius 150 --param2 30\r\n```\r\n\r\n#### Detect Coins Using Contour Method\r\n\r\n```bash\r\npython coin_counter.py detect --scene coins.jpg --method contour \\\r\n  --min_area 1000 --max_area 30000 --circularity 0.6\r\n```\r\n\r\n## Detection Methods\r\n\r\n### Hough Circle Transform\r\n\r\nBest for: Clean backgrounds, well-separated coins, consistent lighting\r\n\r\n**Parameters:**\r\n- `--dp`: Inverse ratio of accumulator resolution (default: 1.2)\r\n- `--min_dist`: Minimum distance between circle centers (default: 30)\r\n- `--param1`: Higher threshold for Canny edge detector (default: 100)\r\n- `--param2`: Accumulator threshold for circle detection (default: 30)\r\n- `--min_radius`: Minimum circle radius in pixels (default: 8)\r\n- `--max_radius`: Maximum circle radius in pixels (default: 200)\r\n\r\n### Contour Detection\r\n\r\nBest for: Challenging backgrounds, overlapping coins, varied lighting\r\n\r\n**Parameters:**\r\n- `--min_area`: Minimum contour area in pixels\u00b2 (default: 500)\r\n- `--max_area`: Maximum contour area in pixels\u00b2 (default: 50000)\r\n- `--circularity`: Circularity threshold 0-1 (default: 0.7)\r\n\r\nUses multiple thresholding methods:\r\n- Otsu's method\r\n- Inverted Otsu (for dark coins on light background)\r\n- Adaptive thresholding\r\n- Canny edge detection\r\n\r\n## Common Parameters\r\n\r\n- `--match_threshold`: Minimum ORB feature matches required for identification (default: 8)\r\n  - Increase for stricter matching (fewer false positives)\r\n  - Decrease for more lenient matching (better for poor quality images)\r\n\r\n## File Structure\r\n\r\n```\r\ncoin_counter/\r\n\u251c\u2500\u2500 coin_counter.py          # CLI version\r\n\u251c\u2500\u2500 coin_counter_gui.py      # GUI version\r\n\u251c\u2500\u2500 README.md                # This file\r\n\u2514\u2500\u2500 refs/                    # Reference coin images (auto-created)\r\n    \u251c\u2500\u2500 metadata.json        # Coin information database\r\n    \u251c\u2500\u2500 Quarter_front.jpg\r\n    \u251c\u2500\u2500 Quarter_back.jpg\r\n    \u2514\u2500\u2500 ...\r\n```\r\n\r\n## Tips for Best Results\r\n\r\n### Taking Reference Images\r\n\r\n1. Use good lighting (natural daylight works best)\r\n2. Plain, contrasting background\r\n3. Coin should fill most of the frame\r\n4. Image should be in focus\r\n5. Take separate images of front and back\r\n\r\n### Scene Images\r\n1. Place coins on a contrasting background\r\n2. Avoid overlapping coins when possible\r\n3. Ensure consistent lighting\r\n4. Keep camera parallel to the surface\r\n5. Use adequate resolution (coins should be at least 50-100 pixels in diameter)\r\n\r\n### Parameter Tuning\r\n\r\n**If coins are not detected:**\r\n- Hough: Lower `param2`, increase `max_radius`\r\n- Contour: Lower `circularity`, increase `max_area`\r\n\r\n**If too many false detections:**\r\n- Hough: Increase `param2`, decrease `max_radius`\r\n- Contour: Increase `circularity`, decrease `max_area`\r\n- Increase `match_threshold` for stricter identification\r\n\r\n**If coins are identified incorrectly:**\r\n- Lower `match_threshold` (may cause more \"Unknown\" results)\r\n- Retake reference images with better quality\r\n- Ensure scene image quality is good\r\n\r\n## Output Files\r\n\r\n- **Annotated Image**: Shows detected coins with labels and values\r\n- **Pie Chart**: Visual distribution of coin types and total value\r\n- **Console Output**: Detailed detection results and summary\r\n\r\n## Limitations\r\n\r\n- Works best with circular coins\r\n- Requires good image quality\r\n- May struggle with:\r\n  - Heavily worn or dirty coins\r\n  - Extreme lighting conditions\r\n  - Very small coins in large images\r\n  - Overlapping coins\r\n  - Non-uniform backgrounds\r\n\r\n## Troubleshooting\r\n\r\n**Problem**: No coins detected\r\n- Try both detection methods\r\n- Adjust radius/area parameters to match actual coin sizes\r\n- Check image quality and lighting\r\n\r\n**Problem**: Many false detections\r\n- Increase `param2` (Hough) or `circularity` (Contour)\r\n- Restrict size parameters more narrowly\r\n- Use a cleaner background\r\n\r\n**Problem**: Coins detected but labeled \"Unknown\"\r\n- Lower `match_threshold`\r\n- Improve reference image quality\r\n- Ensure scene image is clear and well-lit\r\n- Register more reference coins if needed\r\n\r\n**Problem**: Wrong coin identification\r\n- Increase `match_threshold` for stricter matching\r\n- Retake reference images\r\n- Ensure coins in scene are similar to reference images\r\n\r\n## How It Works\r\n\r\n1. **Circle Detection**: Finds circular shapes using Hough or Contour methods\r\n2. **Feature Extraction**: Computes ORB features for each detected circle\r\n3. **Feature Matching**: Compares features against registered reference coins\r\n4. **Identification**: Matches detected coins to registered types based on feature similarity\r\n5. **Aggregation**: Counts coins and calculates total value\r\n\r\n## Contributing\r\n\r\nFeel free to submit issues or pull requests to improve the application.\r\n\r\n## Acknowledgments\r\n\r\nBuilt using OpenCV's computer vision algorithms and ORB feature detection.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A computer vision-based coin detection and counting system with CLI and GUI interfaces",
    "version": "2.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/mhr-isham/Coin-Counter/issues",
        "Documentation": "https://github.com/mhr-isham/Coin-Counter#readme",
        "Homepage": "https://github.com/mhr-isham/Coin-Counter",
        "Repository": "https://github.com/mhr-isham/Coin-Counter"
    },
    "split_keywords": [
        "coin",
        " counter",
        " computer-vision",
        " opencv",
        " detection",
        " image-processing"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e1ace6ac1391030bfb79bd940f7f8af5d286bd95e73c4e2b33752c148db1f67b",
                "md5": "d2b9ada215fb42f289d50de54189a1ee",
                "sha256": "629efa48d65d2e0e8f0bf94e9debcb5fe411e1ee0d55f2faa84d09e65785d7de"
            },
            "downloads": -1,
            "filename": "coin_counter-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d2b9ada215fb42f289d50de54189a1ee",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 17867,
            "upload_time": "2025-10-08T14:34:04",
            "upload_time_iso_8601": "2025-10-08T14:34:04.102488Z",
            "url": "https://files.pythonhosted.org/packages/e1/ac/e6ac1391030bfb79bd940f7f8af5d286bd95e73c4e2b33752c148db1f67b/coin_counter-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1d7ef58101caacbe3702df932dcb38e974d244f360025df5ba0fecd102c8afcc",
                "md5": "cd98b406a51ebf0674d7a83fd54e5965",
                "sha256": "7925121f813055de695af80d4e3024588a3eedfae8adf0ecd0609ed24198e969"
            },
            "downloads": -1,
            "filename": "coin_counter-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "cd98b406a51ebf0674d7a83fd54e5965",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 17325,
            "upload_time": "2025-10-08T14:34:05",
            "upload_time_iso_8601": "2025-10-08T14:34:05.628148Z",
            "url": "https://files.pythonhosted.org/packages/1d/7e/f58101caacbe3702df932dcb38e974d244f360025df5ba0fecd102c8afcc/coin_counter-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-08 14:34:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mhr-isham",
    "github_project": "Coin-Counter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "opencv-python",
            "specs": []
        },
        {
            "name": "json",
            "specs": []
        },
        {
            "name": "argparse",
            "specs": []
        }
    ],
    "lcname": "coin-counter"
}
        
Elapsed time: 2.44617s