Skip to content

Commit f8f511d

Browse files
committed
Add an example for parsing GS1 Application Identifiers
1 parent d932eab commit f8f511d

File tree

4 files changed

+233
-0
lines changed

4 files changed

+233
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
"BarcodeReaderTaskSettingOptions": [
3+
{
4+
"Name": "task_gs1_ai_barcode",
5+
"ExpectedBarcodesCount": 1,
6+
"BarcodeFormatIds": [
7+
"BF_DEFAULT"
8+
],
9+
"SectionArray": [
10+
{
11+
"Section": "ST_REGION_PREDETECTION",
12+
"ImageParameterName": "ip_localize_barcode",
13+
"StageArray": [
14+
{
15+
"Stage": "SST_PREDETECT_REGIONS"
16+
}
17+
]
18+
},
19+
{
20+
"Section": "ST_BARCODE_LOCALIZATION",
21+
"ImageParameterName": "ip_localize_barcode",
22+
"StageArray": [
23+
{
24+
"Stage": "SST_LOCALIZE_CANDIDATE_BARCODES"
25+
},
26+
{
27+
"Stage": "SST_LOCALIZE_BARCODES"
28+
}
29+
]
30+
},
31+
{
32+
"Section": "ST_BARCODE_DECODING",
33+
"ImageParameterName": "ip_decode_barcode",
34+
"StageArray": [
35+
{
36+
"Stage": "SST_RESIST_DEFORMATION"
37+
},
38+
{
39+
"Stage": "SST_COMPLEMENT_BARCODE"
40+
},
41+
{
42+
"Stage": "SST_SCALE_BARCODE_IMAGE"
43+
},
44+
{
45+
"Stage": "SST_DECODE_BARCODES"
46+
}
47+
]
48+
}
49+
]
50+
}
51+
],
52+
"CaptureVisionTemplates": [
53+
{
54+
"Name": "ReadGS1AIBarcode",
55+
"ImageROIProcessingNameArray": [
56+
"roi_gs1_ai_barcode"
57+
],
58+
"SemanticProcessingNameArray": [
59+
"sp_gs1_ai"
60+
]
61+
}
62+
],
63+
"ImageParameterOptions": [
64+
{
65+
"Name": "ip_localize_barcode",
66+
"ApplicableStages": [
67+
{
68+
"Stage": "SST_BINARIZE_IMAGE",
69+
"BinarizationModes": [
70+
{
71+
"Mode": "BM_LOCAL_BLOCK"
72+
73+
}
74+
]
75+
},
76+
{
77+
"Stage": "SST_BINARIZE_TEXTURE_REMOVED_GRAYSCALE"
78+
},
79+
{
80+
"Stage": "SST_TRANSFORM_GRAYSCALE",
81+
"GrayscaleTransformationModes": [
82+
{
83+
"Mode": "GTM_ORIGINAL"
84+
},
85+
{
86+
"Mode": "GTM_INVERTED"
87+
}
88+
]
89+
}
90+
]
91+
},
92+
{
93+
"Name": "ip_decode_barcode",
94+
"ApplicableStages": [
95+
{
96+
"Stage": "SST_TRANSFORM_GRAYSCALE",
97+
"GrayscaleTransformationModes": [
98+
{
99+
"Mode": "GTM_ORIGINAL"
100+
}
101+
]
102+
},
103+
{
104+
"Stage": "SST_SCALE_IMAGE",
105+
"ImageScaleSetting": {
106+
"ScaleType": "ST_SCALE_DOWN",
107+
"ReferenceEdge": "RE_SHORTER_EDGE",
108+
"EdgeLengthThreshold": 99999
109+
}
110+
}
111+
]
112+
}
113+
],
114+
"TargetROIDefOptions": [
115+
{
116+
"Name": "roi_gs1_ai_barcode",
117+
"TaskSettingNameArray": [
118+
"task_gs1_ai_barcode"
119+
]
120+
}
121+
],
122+
"SemanticProcessingOptions": [
123+
{
124+
"Name": "sp_gs1_ai",
125+
"ReferenceObjectFilter": {
126+
"ReferenceTargetROIDefNameArray": [
127+
"roi_gs1_ai_barcode"
128+
]
129+
},
130+
"TaskSettingNameArray": [
131+
"dcp_gs1_ai"
132+
]
133+
}
134+
],
135+
"CodeParserTaskSettingOptions": [
136+
{
137+
"Name": "dcp_gs1_ai",
138+
"CodeSpecifications": [
139+
"GS1_AI"
140+
]
141+
}
142+
]
143+
}

examples/official/gs1ai/main.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import sys
2+
from dynamsoft_capture_vision_bundle import *
3+
import os
4+
import json
5+
6+
if __name__ == '__main__':
7+
8+
print("**********************************************************")
9+
print("Welcome to Dynamsoft Capture Vision - Barcode Sample")
10+
print("**********************************************************")
11+
12+
error_code, error_message = LicenseManager.init_license(
13+
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
14+
if error_code != EnumErrorCode.EC_OK and error_code != EnumErrorCode.EC_LICENSE_CACHE_USED:
15+
print("License initialization failed: ErrorCode:",
16+
error_code, ", ErrorString:", error_message)
17+
else:
18+
cvr_instance = CaptureVisionRouter()
19+
cvr_instance.init_settings_from_file('GS1AI_Scanner.json')
20+
while (True):
21+
image_path = input(
22+
">> Input your image full path:\n"
23+
">> 'Enter' for sample image or 'Q'/'q' to quit\n"
24+
).strip('\'"')
25+
26+
if image_path.lower() == "q":
27+
sys.exit(0)
28+
29+
if not os.path.exists(image_path):
30+
print("The image path does not exist.")
31+
continue
32+
33+
result = cvr_instance.capture(
34+
image_path, "ReadGS1AIBarcode")
35+
if result.get_error_code() != EnumErrorCode.EC_OK:
36+
print("Error:", result.get_error_code(),
37+
result.get_error_string())
38+
else:
39+
items = result.get_items()
40+
for item in items:
41+
if item.get_type() == EnumCapturedResultItemType.CRIT_BARCODE:
42+
format_type = item.get_format()
43+
text_bytes = item.get_bytes()
44+
text = text_bytes.decode('utf-8')
45+
print('Barcode text: {} '.format(text))
46+
47+
location = item.get_location()
48+
x1 = location.points[0].x
49+
y1 = location.points[0].y
50+
x2 = location.points[1].x
51+
y2 = location.points[1].y
52+
x3 = location.points[2].x
53+
y3 = location.points[2].y
54+
x4 = location.points[3].x
55+
y4 = location.points[3].y
56+
57+
elif item.get_type() == EnumCapturedResultItemType.CRIT_PARSED_RESULT:
58+
try:
59+
json_string = item.get_json_string()
60+
data = json.loads(item.get_json_string())
61+
output_lines = []
62+
for item in data.get("ResultInfo", []):
63+
ai = item.get("FieldName", "")
64+
description = ""
65+
value = ""
66+
67+
# Get ChildFields
68+
child_fields = item.get("ChildFields", [[]])[0]
69+
for field in child_fields:
70+
if field["FieldName"].endswith("AI"):
71+
# For dynamic AIs like 310n or 392n, use RawValue instead of FieldName
72+
ai = field.get("RawValue", ai)
73+
description = field.get("Value", "")
74+
elif field["FieldName"].endswith("Data"):
75+
value = field.get("Value", "")
76+
77+
output_lines.append(f"AI: {ai}")
78+
output_lines.append(f"Description: {description.upper()}")
79+
output_lines.append(f"Value: {value}")
80+
output_lines.append("-" * 40)
81+
82+
"\n".join(output_lines)
83+
84+
print("\n".join(output_lines))
85+
except json.JSONDecodeError as e:
86+
print("JSON Decode Error:", e)
87+
continue
88+
89+
input("Press Enter to quit...")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dynamsoft-capture-vision-bundle

examples/official/gs1ai/test.png

351 KB
Loading

0 commit comments

Comments
 (0)