dotcode-decoder 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,248 @@
1
+ Metadata-Version: 2.4
2
+ Name: dotcode-decoder
3
+ Version: 1.0.0
4
+ Summary: Fast DotCode 2D barcode decoder
5
+ Author: Anish karki
6
+ Keywords: barcode dotcode decoder 2d
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.7
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Topic :: Multimedia :: Graphics
15
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
16
+ Requires-Python: >=3.7
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: opencv-python>=4.5.0
19
+ Requires-Dist: numpy>=1.19.0
20
+ Requires-Dist: scipy>=1.7.0
21
+ Dynamic: author
22
+ Dynamic: classifier
23
+ Dynamic: description
24
+ Dynamic: description-content-type
25
+ Dynamic: keywords
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
29
+
30
+ # DotCode Decoder
31
+
32
+ [![Python Version](https://img.shields.io/badge/python-3.7+-blue.svg)](https://python.org)
33
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
34
+ [![PyPI](https://img.shields.io/badge/pypi-v1.0.0-orange.svg)](https://pypi.org/project/dotcode)
35
+
36
+ **Fast, accurate DotCode 2D barcode decoder for industrial and commercial applications.**
37
+
38
+ ---
39
+
40
+ ## 📦 Installation
41
+
42
+ ```bash
43
+ pip install dotcode
44
+ ```
45
+
46
+ Or install from source:
47
+
48
+ ```bash
49
+ git clone https://github.com/yourusername/dotcode.git
50
+ cd dotcode
51
+ pip install -e .
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 🚀 Quick Start
57
+
58
+ ```python
59
+ from dotcode import decode, DecodeResult
60
+
61
+ # Single image
62
+ result = decode("image.jpg")
63
+ print(result.message) # "25E13KXUKSXG1313"
64
+
65
+ # With details
66
+ result: DecodeResult = decode("image.jpg")
67
+ print(f"Message: {result.message}")
68
+ print(f"Time: {result.elapsed_ms:.0f}ms")
69
+ print(f"Confidence: {result.confidence:.2f}")
70
+ print(f"Method: {result.method}")
71
+
72
+ # Batch decode
73
+ results = decode_batch(["img1.jpg", "img2.jpg", "img3.jpg"])
74
+ for r in results:
75
+ print(f"{r.file}: {r.message} ({r.elapsed_ms:.0f}ms)")
76
+ ```
77
+
78
+ ---
79
+
80
+ ## ⚙️ Advanced Usage
81
+
82
+ ```python
83
+ from dotcode import DotCodeDecoder
84
+
85
+ # Custom configuration
86
+ decoder = DotCodeDecoder(
87
+ timeout_ms=500, # Max time per image
88
+ confidence=0.35, # Confidence threshold (0.20-0.40)
89
+ fast_mode=True, # Fast decode (6 angles) or accurate (12 angles)
90
+ use_sauvola=False # Sauvola thresholding for poor lighting
91
+ )
92
+
93
+ # Decode with custom settings
94
+ result = decoder.decode("image.jpg")
95
+ print(result.message)
96
+
97
+ # Disable fast mode for better accuracy on difficult images
98
+ decoder = DotCodeDecoder(fast_mode=False)
99
+ ```
100
+
101
+ ---
102
+
103
+ ## 📊 Performance
104
+
105
+ | Metric | Value |
106
+ |--------|-------|
107
+ | **Accuracy** | **96.2%** (381/396 images) |
108
+ | **Average Speed** | **41ms** per image |
109
+ | **Success Rate** | 96%+ |
110
+ | **Timeout** | 300ms (configurable) |
111
+ | **Stage Distribution** | Regression: 27% \| Angle Sweep: 73% |
112
+
113
+ ### Performance by Stage
114
+
115
+ | Stage | Images | Avg Time | Description |
116
+ |-------|--------|----------|-------------|
117
+ | **Regression** | 103 (27%) | ~20ms | Fast path - direct grid fit |
118
+ | **Angle Sweep** | 278 (73%) | ~45ms | Slower path - angle correction |
119
+ | **Invert Fallback** | 0 | N/A | Last resort for inverted images |
120
+
121
+ ---
122
+
123
+ ## 🔧 How It Works
124
+
125
+ 1. **Dot Detection**
126
+ Extracts dot centroids using adaptive thresholding (Otsu/fixed) with morphological erosion to separate touching dots.
127
+
128
+ 2. **Iterative Regression**
129
+ Straightens tilted/skewed grids using per-row polynomial fitting with early exit when angle stabilizes.
130
+
131
+ 3. **Grid Snapping**
132
+ Fits detected dots to a 10×47 checkerboard grid using k-means clustering (or optional Procrustes + RANSAC for difficult images).
133
+
134
+ 4. **Reed-Solomon Error Correction**
135
+ Corrects errors in the extracted bitstream using Reed-Solomon decoding over GF(113) - handles up to 7 errors per code.
136
+
137
+ 5. **Text Decoding**
138
+ Converts corrected values to readable text using DotCode code sets (A, B, C) with state machine for character encoding.
139
+
140
+ ---
141
+
142
+ ## 📁 Project Structure
143
+
144
+ ```
145
+ dotcode/
146
+ ├── __init__.py # Main exports
147
+ ├── decoder.py # Core decoding logic
148
+ ├── image.py # Image processing (thresholding, blob detection)
149
+ ├── codes.py # DotCode code sets (A, B, C)
150
+ ├── rs.py # Reed-Solomon error correction
151
+ └── utils.py # Utility classes and constants
152
+
153
+ examples/
154
+ ├── basic_usage.py # Simple decode example
155
+ └── batch_usage.py # Batch processing example
156
+
157
+ tests/
158
+ └── test_decoder.py # Unit tests
159
+ ```
160
+
161
+ ---
162
+
163
+ ## 🔬 Algorithm Details
164
+
165
+ ### Reed-Solomon Error Correction
166
+ - Field: **GF(113)**
167
+ - Primitive element: **3**
168
+ - Corrects up to **~5-7 errors** per code
169
+ - Uses Berlekamp-Massey algorithm for error location
170
+
171
+ ### Iterative Regression
172
+ - **2 iterations** (configurable)
173
+ - **Early exit** when angle change < 0.1°
174
+ - **Per-row quadratic fit** for curvature correction
175
+
176
+ ### Threshold Selection
177
+ - **Otsu's method** (automatic)
178
+ - **Fixed thresholds**: 105, 115, 125, 135, 145, 155, 165, 175
179
+ - **Sauvola threshold** (local adaptive) - optional
180
+
181
+ ---
182
+
183
+ ## 🛠️ Requirements
184
+
185
+ - Python 3.7+
186
+ - OpenCV >= 4.5.0
187
+ - NumPy >= 1.19.0
188
+ - SciPy >= 1.7.0 (for KDTree)
189
+
190
+ ---
191
+
192
+ ## 📝 License
193
+
194
+ MIT License - see [LICENSE](LICENSE) file for details.
195
+
196
+ ---
197
+
198
+ ## 🤝 Contributing
199
+
200
+ Contributions are welcome! Please:
201
+
202
+ 1. Fork the repository
203
+ 2. Create a feature branch
204
+ 3. Submit a pull request
205
+
206
+ ### Development Setup
207
+
208
+ ```bash
209
+ # Clone the repository
210
+ git clone https://github.com/yourusername/dotcode.git
211
+ cd dotcode
212
+
213
+ # Install in development mode
214
+ pip install -e .
215
+
216
+ # Run tests
217
+ python test.py
218
+ ```
219
+
220
+ ---
221
+
222
+ ## 📚 References
223
+
224
+ - [DotCode Specification (AIM)](https://www.aimglobal.org/dotcode)
225
+ - [Wikipedia: DotCode](https://en.wikipedia.org/wiki/DotCode)
226
+ - [Reed-Solomon Error Correction](https://en.wikipedia.org/wiki/Reed%E2%80%93Solomon_error_correction)
227
+
228
+ ---
229
+
230
+ ## 📧 Contact
231
+
232
+ For questions or support:
233
+ - GitHub Issues: [https://github.com/yourusername/dotcode/issues](https://github.com/yourusername/dotcode/issues)
234
+ - Email: your.email@example.com
235
+
236
+ ---
237
+
238
+ ## ⭐ Acknowledgments
239
+
240
+ This project builds on research in 2D barcode decoding and industrial computer vision. Special thanks to:
241
+
242
+ - The open-source community for OpenCV, NumPy, and SciPy
243
+ - AIM Global for the DotCode specification
244
+ - Contributors who helped test and improve the decoder
245
+
246
+ ---
247
+
248
+ **Made with ❤️ for industrial automation and barcode enthusiasts.**
@@ -0,0 +1,219 @@
1
+ # DotCode Decoder
2
+
3
+ [![Python Version](https://img.shields.io/badge/python-3.7+-blue.svg)](https://python.org)
4
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
5
+ [![PyPI](https://img.shields.io/badge/pypi-v1.0.0-orange.svg)](https://pypi.org/project/dotcode)
6
+
7
+ **Fast, accurate DotCode 2D barcode decoder for industrial and commercial applications.**
8
+
9
+ ---
10
+
11
+ ## 📦 Installation
12
+
13
+ ```bash
14
+ pip install dotcode
15
+ ```
16
+
17
+ Or install from source:
18
+
19
+ ```bash
20
+ git clone https://github.com/yourusername/dotcode.git
21
+ cd dotcode
22
+ pip install -e .
23
+ ```
24
+
25
+ ---
26
+
27
+ ## 🚀 Quick Start
28
+
29
+ ```python
30
+ from dotcode import decode, DecodeResult
31
+
32
+ # Single image
33
+ result = decode("image.jpg")
34
+ print(result.message) # "25E13KXUKSXG1313"
35
+
36
+ # With details
37
+ result: DecodeResult = decode("image.jpg")
38
+ print(f"Message: {result.message}")
39
+ print(f"Time: {result.elapsed_ms:.0f}ms")
40
+ print(f"Confidence: {result.confidence:.2f}")
41
+ print(f"Method: {result.method}")
42
+
43
+ # Batch decode
44
+ results = decode_batch(["img1.jpg", "img2.jpg", "img3.jpg"])
45
+ for r in results:
46
+ print(f"{r.file}: {r.message} ({r.elapsed_ms:.0f}ms)")
47
+ ```
48
+
49
+ ---
50
+
51
+ ## ⚙️ Advanced Usage
52
+
53
+ ```python
54
+ from dotcode import DotCodeDecoder
55
+
56
+ # Custom configuration
57
+ decoder = DotCodeDecoder(
58
+ timeout_ms=500, # Max time per image
59
+ confidence=0.35, # Confidence threshold (0.20-0.40)
60
+ fast_mode=True, # Fast decode (6 angles) or accurate (12 angles)
61
+ use_sauvola=False # Sauvola thresholding for poor lighting
62
+ )
63
+
64
+ # Decode with custom settings
65
+ result = decoder.decode("image.jpg")
66
+ print(result.message)
67
+
68
+ # Disable fast mode for better accuracy on difficult images
69
+ decoder = DotCodeDecoder(fast_mode=False)
70
+ ```
71
+
72
+ ---
73
+
74
+ ## 📊 Performance
75
+
76
+ | Metric | Value |
77
+ |--------|-------|
78
+ | **Accuracy** | **96.2%** (381/396 images) |
79
+ | **Average Speed** | **41ms** per image |
80
+ | **Success Rate** | 96%+ |
81
+ | **Timeout** | 300ms (configurable) |
82
+ | **Stage Distribution** | Regression: 27% \| Angle Sweep: 73% |
83
+
84
+ ### Performance by Stage
85
+
86
+ | Stage | Images | Avg Time | Description |
87
+ |-------|--------|----------|-------------|
88
+ | **Regression** | 103 (27%) | ~20ms | Fast path - direct grid fit |
89
+ | **Angle Sweep** | 278 (73%) | ~45ms | Slower path - angle correction |
90
+ | **Invert Fallback** | 0 | N/A | Last resort for inverted images |
91
+
92
+ ---
93
+
94
+ ## 🔧 How It Works
95
+
96
+ 1. **Dot Detection**
97
+ Extracts dot centroids using adaptive thresholding (Otsu/fixed) with morphological erosion to separate touching dots.
98
+
99
+ 2. **Iterative Regression**
100
+ Straightens tilted/skewed grids using per-row polynomial fitting with early exit when angle stabilizes.
101
+
102
+ 3. **Grid Snapping**
103
+ Fits detected dots to a 10×47 checkerboard grid using k-means clustering (or optional Procrustes + RANSAC for difficult images).
104
+
105
+ 4. **Reed-Solomon Error Correction**
106
+ Corrects errors in the extracted bitstream using Reed-Solomon decoding over GF(113) - handles up to 7 errors per code.
107
+
108
+ 5. **Text Decoding**
109
+ Converts corrected values to readable text using DotCode code sets (A, B, C) with state machine for character encoding.
110
+
111
+ ---
112
+
113
+ ## 📁 Project Structure
114
+
115
+ ```
116
+ dotcode/
117
+ ├── __init__.py # Main exports
118
+ ├── decoder.py # Core decoding logic
119
+ ├── image.py # Image processing (thresholding, blob detection)
120
+ ├── codes.py # DotCode code sets (A, B, C)
121
+ ├── rs.py # Reed-Solomon error correction
122
+ └── utils.py # Utility classes and constants
123
+
124
+ examples/
125
+ ├── basic_usage.py # Simple decode example
126
+ └── batch_usage.py # Batch processing example
127
+
128
+ tests/
129
+ └── test_decoder.py # Unit tests
130
+ ```
131
+
132
+ ---
133
+
134
+ ## 🔬 Algorithm Details
135
+
136
+ ### Reed-Solomon Error Correction
137
+ - Field: **GF(113)**
138
+ - Primitive element: **3**
139
+ - Corrects up to **~5-7 errors** per code
140
+ - Uses Berlekamp-Massey algorithm for error location
141
+
142
+ ### Iterative Regression
143
+ - **2 iterations** (configurable)
144
+ - **Early exit** when angle change < 0.1°
145
+ - **Per-row quadratic fit** for curvature correction
146
+
147
+ ### Threshold Selection
148
+ - **Otsu's method** (automatic)
149
+ - **Fixed thresholds**: 105, 115, 125, 135, 145, 155, 165, 175
150
+ - **Sauvola threshold** (local adaptive) - optional
151
+
152
+ ---
153
+
154
+ ## 🛠️ Requirements
155
+
156
+ - Python 3.7+
157
+ - OpenCV >= 4.5.0
158
+ - NumPy >= 1.19.0
159
+ - SciPy >= 1.7.0 (for KDTree)
160
+
161
+ ---
162
+
163
+ ## 📝 License
164
+
165
+ MIT License - see [LICENSE](LICENSE) file for details.
166
+
167
+ ---
168
+
169
+ ## 🤝 Contributing
170
+
171
+ Contributions are welcome! Please:
172
+
173
+ 1. Fork the repository
174
+ 2. Create a feature branch
175
+ 3. Submit a pull request
176
+
177
+ ### Development Setup
178
+
179
+ ```bash
180
+ # Clone the repository
181
+ git clone https://github.com/yourusername/dotcode.git
182
+ cd dotcode
183
+
184
+ # Install in development mode
185
+ pip install -e .
186
+
187
+ # Run tests
188
+ python test.py
189
+ ```
190
+
191
+ ---
192
+
193
+ ## 📚 References
194
+
195
+ - [DotCode Specification (AIM)](https://www.aimglobal.org/dotcode)
196
+ - [Wikipedia: DotCode](https://en.wikipedia.org/wiki/DotCode)
197
+ - [Reed-Solomon Error Correction](https://en.wikipedia.org/wiki/Reed%E2%80%93Solomon_error_correction)
198
+
199
+ ---
200
+
201
+ ## 📧 Contact
202
+
203
+ For questions or support:
204
+ - GitHub Issues: [https://github.com/yourusername/dotcode/issues](https://github.com/yourusername/dotcode/issues)
205
+ - Email: your.email@example.com
206
+
207
+ ---
208
+
209
+ ## ⭐ Acknowledgments
210
+
211
+ This project builds on research in 2D barcode decoding and industrial computer vision. Special thanks to:
212
+
213
+ - The open-source community for OpenCV, NumPy, and SciPy
214
+ - AIM Global for the DotCode specification
215
+ - Contributors who helped test and improve the decoder
216
+
217
+ ---
218
+
219
+ **Made with ❤️ for industrial automation and barcode enthusiasts.**
@@ -0,0 +1,9 @@
1
+ """
2
+ DotCode Decoder - Fast 2D barcode reader (Conveyor ready)
3
+ """
4
+
5
+ from .decoder import DotCodeDecoder, decode
6
+ from .utils import DecodeResult, DecodeStage
7
+
8
+ __version__ = "1.0.0"
9
+ __all__ = ['DotCodeDecoder', 'decode', 'DecodeResult', 'DecodeStage']