Skip to content

Commit 5aad2f9

Browse files
committed
Add a SEMI OCR example
1 parent 841858b commit 5aad2f9

File tree

9 files changed

+233
-0
lines changed

9 files changed

+233
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Semi-OCR Example with Dynamsoft Capture Vision SDK
2+
3+
This example demonstrates how to use Dynamsoft Capture Vision SDK to recognize **SEMI (Semiconductor Equipment and Materials International)** font markings on silicon wafers. The custom model provided by Dynamsoft is trained for **single-density dot matrix fonts** and supports only **26 uppercase letters and 10 digits**.
4+
5+
## Prerequisites
6+
7+
- Python 3.8 or later
8+
- Install required packages:
9+
10+
```bash
11+
pip install -r requirements.txt
12+
```
13+
14+
- Obtain a [30-day trial license](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform)
15+
16+
## Usage
17+
18+
1. Set your license key in `read_semi_ocr.py`:
19+
20+
```python
21+
err_code, err_str = LicenseManager.init_license("LICENSE-KEY")
22+
```
23+
24+
2. Run the script:
25+
26+
```bash
27+
python read_semi_ocr.py
28+
```
29+
30+
## Support
31+
32+
For model-related issues, please contact [Dynamsoft Support](https://www.dynamsoft.com/company/customer-service/).
15.6 KB
Loading
25.4 KB
Loading
17.4 KB
Loading
81.4 KB
Loading
Binary file not shown.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
from dynamsoft_capture_vision_bundle import *
3+
4+
if __name__ == '__main__':
5+
# 1.Initializes license.
6+
# You can request or extend a trial license at: https://www.dynamsoft.com/customer/license/trialLicense?product=dcv&utm_source=samples&package=python
7+
# The string below is a free public trial license. Note: an active internet connection is required for this license to work.
8+
err_code, err_str = LicenseManager.init_license("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
9+
if err_code != EnumErrorCode.EC_OK and err_code != EnumErrorCode.EC_LICENSE_CACHE_USED:
10+
print("License initialization failed: ErrorCode: " + str(err_code) + ", ErrorString: " + err_str)
11+
else:
12+
# 2.Creates an instance of CaptureVisionRouter.
13+
cvr = CaptureVisionRouter()
14+
with open('models/semi-ocr.data', 'rb') as f:
15+
model_data = f.read()
16+
17+
err_code, err_str = cvr.append_model_buffer('semi-ocr', model_data, 1)
18+
print("Model initialization: ErrorCode: " + str(err_code) + ", ErrorString: " + err_str)
19+
20+
# 3.Performs capture jobs(recognizing text lines) on an image
21+
err_code, err_str = cvr.init_settings_from_file("semi-ocr.json")
22+
print("Template initialization: ErrorCode: " + str(err_code) + ", ErrorString: " + err_str)
23+
24+
files_list = []
25+
while True:
26+
path = input("Please enter the image file/directory path: ").strip('\'"')
27+
if not os.path.exists(path):
28+
print("File not found: " + path)
29+
else:
30+
if os.path.isfile(path):
31+
files_list.append(path)
32+
elif os.path.isdir(path):
33+
files =os.listdir(path)
34+
for file in files:
35+
if file.endswith(".jpg") or file.endswith(".jpeg") or file.endswith(".png"):
36+
files_list.append(os.path.join(path, file))
37+
break
38+
39+
for file_path in files_list:
40+
result=cvr.capture(file_path, "recognize_semi_ocr")
41+
42+
print("File: " + file_path)
43+
44+
# 4.Outputs the result.
45+
if result.get_error_code() != EnumErrorCode.EC_OK:
46+
print("Error: " + str(result.get_error_code())+ result.get_error_string())
47+
else:
48+
items = result.get_items()
49+
# print(f'read {len(items)} items')
50+
for item in items:
51+
if isinstance(item, TextLineResultItem):
52+
print(item.get_text())
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dynamsoft-capture-vision-bundle
2+
opencv-python
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"CaptureVisionTemplates": [
3+
{
4+
"Name": "recognize_semi_ocr",
5+
"ImageROIProcessingNameArray": [
6+
"roi_test"
7+
],
8+
"Timeout": 2000
9+
}
10+
],
11+
"TargetROIDefOptions": [
12+
{
13+
"Name": "roi_test",
14+
"TaskSettingNameArray": [
15+
"task_test"
16+
]
17+
}
18+
],
19+
"TextLineSpecificationOptions": [
20+
{
21+
"Name": "tls_test",
22+
"CharacterModelName": "",
23+
"TextLineRecModelName": "semi-ocr",
24+
"CharHeightRange": [
25+
1,
26+
1000,
27+
1
28+
],
29+
"StringLengthRange": [
30+
7,
31+
13
32+
],
33+
"BinarizationModes": [
34+
{
35+
"BlockSizeX": 30,
36+
"BlockSizeY": 30,
37+
"Mode": "BM_LOCAL_BLOCK",
38+
"EnableFillBinaryVacancy": 0,
39+
"ThresholdCompensation": 15
40+
}
41+
]
42+
}
43+
],
44+
"LabelRecognizerTaskSettingOptions": [
45+
{
46+
"Name": "task_test",
47+
"TextLineSpecificationNameArray": [
48+
"tls_test"
49+
],
50+
"SectionArray": [
51+
{
52+
"Section": "ST_REGION_PREDETECTION",
53+
"ImageParameterName": "ip_test",
54+
"StageArray": [
55+
{
56+
"Stage": "SST_PREDETECT_REGIONS"
57+
}
58+
]
59+
},
60+
{
61+
"Section": "ST_TEXT_LINE_LOCALIZATION",
62+
"ImageParameterName": "ip_test",
63+
"StageArray": [
64+
{
65+
"Stage": "SST_LOCALIZE_TEXT_LINES"
66+
}
67+
]
68+
},
69+
{
70+
"Section": "ST_TEXT_LINE_RECOGNITION",
71+
"ImageParameterName": "ip_test",
72+
"StageArray": [
73+
{
74+
"Stage": "SST_RECOGNIZE_RAW_TEXT_LINES"
75+
},
76+
{
77+
"Stage": "SST_ASSEMBLE_TEXT_LINES"
78+
}
79+
]
80+
}
81+
]
82+
}
83+
],
84+
"CaptureVisionModelOptions": [
85+
{
86+
"Name": "semi-ocr",
87+
"MaxModelInstances": 1
88+
}
89+
],
90+
"ImageParameterOptions": [
91+
{
92+
"Name": "ip_test",
93+
"ApplicableStages": [
94+
{
95+
"Stage": "SST_TRANSFORM_GRAYSCALE",
96+
"GrayscaleTransformationModes": [
97+
{
98+
"Mode": "GTM_ORIGINAL"
99+
},
100+
{
101+
"Mode": "GTM_INVERTED"
102+
}
103+
]
104+
},
105+
{
106+
"Stage": "SST_DETECT_TEXTURE",
107+
"TextureDetectionModes": [
108+
{
109+
"Mode": "TDM_GENERAL_WIDTH_CONCENTRATION",
110+
"Sensitivity": 8
111+
}
112+
]
113+
},
114+
{
115+
"Stage": "SST_BINARIZE_IMAGE",
116+
"BinarizationModes": [
117+
{
118+
"EnableFillBinaryVacancy": 0,
119+
"ThresholdCompensation": 21,
120+
"Mode": "BM_LOCAL_BLOCK",
121+
"MorphOperation": "Dilate",
122+
"MorphOperationKernelSizeX": 7,
123+
"MorphOperationKernelSizeY": 7
124+
}
125+
]
126+
},
127+
{
128+
"Stage": "SST_DETECT_TEXT_ZONES",
129+
"TextDetectionMode": {
130+
"Mode": "TTDM_LINE",
131+
"CharHeightRange": [
132+
5,
133+
1000,
134+
1
135+
],
136+
"StringLengthRange": [
137+
7,
138+
13
139+
],
140+
"Direction": "HORIZONTAL",
141+
"Sensitivity": 7
142+
}
143+
}
144+
]
145+
}
146+
]
147+
}

0 commit comments

Comments
 (0)