Skip to content

Commit db0c73b

Browse files
committed
Add README.md
1 parent f8f511d commit db0c73b

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

examples/official/gs1ai/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# GS1 Application Identifier (AI) Parser
2+
This sample code demonstrates how to decode barcodes and parse **GS1 Application Identifiers (AIs)** using **Python** and **Dynamsoft Capture Vision**.
3+
4+
5+
## Prerequisites
6+
- Install required packages using pip:
7+
8+
```bash
9+
pip install -r requirements.txt
10+
```
11+
12+
- Request a [trial license key](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform) for **Dynamsoft Capture Vision**.
13+
14+
## Usage
15+
1. Set the license key in the `main.py` file:
16+
```python
17+
LicenseManager.init_license("LICENSE-KEY")
18+
```
19+
20+
2. Run the script:
21+
22+
```bash
23+
python main.py
24+
```
25+
26+
![GS1 AI Parser](https://www.dynamsoft.com/codepool/img/2025/04/python-detect-barcode-gs1-ai.png)

examples/official/gs1ai/main.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from dynamsoft_capture_vision_bundle import *
33
import os
44
import json
5+
import cv2
6+
import numpy as np
57

68
if __name__ == '__main__':
79

@@ -29,20 +31,22 @@
2931
if not os.path.exists(image_path):
3032
print("The image path does not exist.")
3133
continue
32-
34+
35+
cv_image = cv2.imread(image_path)
3336
result = cvr_instance.capture(
34-
image_path, "ReadGS1AIBarcode")
37+
cv_image, "ReadGS1AIBarcode")
3538
if result.get_error_code() != EnumErrorCode.EC_OK:
3639
print("Error:", result.get_error_code(),
3740
result.get_error_string())
3841
else:
3942
items = result.get_items()
4043
for item in items:
4144
if item.get_type() == EnumCapturedResultItemType.CRIT_BARCODE:
42-
format_type = item.get_format()
45+
format_type = item.get_format_string()
4346
text_bytes = item.get_bytes()
4447
text = text_bytes.decode('utf-8')
4548
print('Barcode text: {} '.format(text))
49+
print('Barcode format: {} '.format(format_type))
4650

4751
location = item.get_location()
4852
x1 = location.points[0].x
@@ -54,6 +58,12 @@
5458
x4 = location.points[3].x
5559
y4 = location.points[3].y
5660

61+
cv2.drawContours(
62+
cv_image, [np.intp([(x1, y1), (x2, y2), (x3, y3), (x4, y4)])], 0, (0, 255, 0), 2)
63+
64+
cv2.putText(cv_image, text, (x1, y1 - 10),
65+
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
66+
5767
elif item.get_type() == EnumCapturedResultItemType.CRIT_PARSED_RESULT:
5868
try:
5969
json_string = item.get_json_string()
@@ -64,11 +74,9 @@
6474
description = ""
6575
value = ""
6676

67-
# Get ChildFields
6877
child_fields = item.get("ChildFields", [[]])[0]
6978
for field in child_fields:
7079
if field["FieldName"].endswith("AI"):
71-
# For dynamic AIs like 310n or 392n, use RawValue instead of FieldName
7280
ai = field.get("RawValue", ai)
7381
description = field.get("Value", "")
7482
elif field["FieldName"].endswith("Data"):
@@ -85,5 +93,9 @@
8593
except json.JSONDecodeError as e:
8694
print("JSON Decode Error:", e)
8795
continue
96+
cv2.imshow(
97+
"Original Image with Detected Barcodes", cv_image)
98+
cv2.waitKey(0)
99+
cv2.destroyAllWindows()
88100

89101
input("Press Enter to quit...")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dynamsoft-capture-vision-bundle
2+
opencv-python

0 commit comments

Comments
 (0)