# Python OCR Tutorial: Recognize SEMI Semiconductor Fonts with Dynamsoft Capture Vision SDK

Canonical: https://www.dynamsoft.com/codepool/semi-font-ocr-recognition-python.html
Markdown: https://www.dynamsoft.com/codepool/semi-font-ocr-recognition-python.md
Description: A step-by-step Python OCR tutorial for SEMI font recognition on semiconductor wafers. Learn how to load a custom dot-matrix font model and extract characters from wafer images using Dynamsoft Capture Vision SDK on Windows, Linux, and macOS.
Author: Xiao Ling
Published: 2025-07-03
Updated: 2026-07-14
Topics: Python, OCR, SEMI, Semiconductor, DCV, Windows, Linux, macOS

**SEMI (Semiconductor Equipment and Materials International) font** is a special dot matrix font used for marking silicon wafers. In this tutorial, we'll walk through building a Python application to recognize these specialized markings using Dynamsoft Capture Vision SDK.

**What you'll build:** A cross-platform Python script that loads a custom SEMI OCR model, processes semiconductor wafer images, and overlays recognized dot-matrix font characters as bounding-box annotations using Dynamsoft Capture Vision SDK.

## Key Takeaways

- Dynamsoft Capture Vision SDK supports custom OCR models, enabling recognition of non-standard fonts such as the SEMI dot-matrix font used on silicon wafers.
- The `CaptureVisionRouter` class accepts user-supplied model buffers via `append_model_buffer()`, making the pipeline extensible to any industry-specific character set.
- Recognition results include per-character bounding-box location data, making it straightforward to overlay text annotations on wafer images using OpenCV.
- The complete solution runs on Windows, Linux, and macOS with a single `pip install` command.

## Common Developer Questions
#### How do I recognize SEMI font characters on semiconductor wafers using Python OCR?

Load the custom SEMI OCR model into `CaptureVisionRouter`, initialize the matching JSON recognition settings, and run capture on the wafer image. The returned text-line results include both recognized characters and bounding boxes for overlay visualization.

### Can Dynamsoft Capture Vision SDK read custom or non-standard dot-matrix fonts?

Yes. This article shows that the SDK can load a domain-specific OCR model and recognize a non-standard dot-matrix font used in semiconductor workflows rather than only common printed text.

### How do I load a custom OCR model into Dynamsoft Capture Vision SDK in Python?

Read the model file as bytes and pass it to `append_model_buffer()`, then load the companion JSON settings file before capture. Both the binary model and the settings are required for the SEMI recognition template to work correctly.

## Watch SEMI OCR Font Recognition in Action
<video src="https://github.com/user-attachments/assets/703b35dd-9bee-4652-a687-3b5e1d7d64c9" controls="controls" muted="muted" style="max-height:640px; min-height: 200px; max-width: 100%;"></video>


## Prerequisites
- Python 3.8 or later
- **Dynamsoft Capture Vision Trial License**: Get a [30-Day trial license key](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform) for the Dynamsoft Capture Vision SDK.
- **Python Packages**: Install the required Python packages using the following commands:

    ```bash
    pip install dynamsoft-capture-vision-bundle opencv-python
    ```
    
    - `dynamsoft-capture-vision-bundle`: Python binding for Dynamsoft Capture Vision SDK.
    - `opencv-python`: For displaying source images and overlaying recognition results.

## What This Implementation Provides

- **Specialized SEMI Font Recognition**: Uses a custom model trained for **single-density dot matrix fonts (uppercase letters A-Z and digits 0-9)**.
- **Visual Feedback**: Draws bounding boxes around recognized text.
- **Batch Processing**: Processes single images or entire directories.
- **Cross-Platform**: Works on **Windows**, **Linux**, and **macOS**.

![Semi-Font OCR Recognition](./img/2025/07/semi-font-ocr-recognition.png)

## Step 1: Initialize the Dynamsoft Capture Vision SDK

Create a new Python file and initialize the SDK with your license key:

```python
from dynamsoft_capture_vision_bundle import *

err_code, err_str = LicenseManager.init_license("LICENSE-KEY")
if err_code != EnumErrorCode.EC_OK and err_code != EnumErrorCode.EC_LICENSE_CACHE_USED:
    print("License initialization failed: " + err_str)
```

## Step 2: Load the SEMI OCR Model

A custom model trained by Dynamsoft enables the Capture Vision SDK to recognize SEMI fonts:

```python
cvr = CaptureVisionRouter()

# Load the SEMI OCR model
with open('models/semi-ocr.data', 'rb') as f:
    model_data = f.read()
    
err_code, err_str = cvr.append_model_buffer('semi-ocr', model_data, 1)
if err_code != EnumErrorCode.EC_OK:
    print("Model loading failed: " + err_str)
```


For model-related questions, please contact [Dynamsoft Support](https://www.dynamsoft.com/company/customer-service/).

## Step 3: Configure SEMI OCR Recognition from a JSON Settings File

Besides the model file, recognition settings must be loaded from a `semi-ocr.json` file.

```python
err_code, err_str = cvr.init_settings_from_file("semi-ocr.json")
if err_code != EnumErrorCode.EC_OK:
    print("Configuration loading failed: " + err_str)
```

## Step 4: Process Wafer Images and Visualize Recognition Results

Here's the core recognition logic that processes images and overlays results:

```python
import cv2
import numpy as np

def process_image(image_path, cvr):
    cv_image = cv2.imread(image_path)
                    
    result = cvr.capture(image_path, "recognize_semi_ocr")
    
    if result.get_error_code() != EnumErrorCode.EC_OK:
        print("Error: " + str(result.get_error_code())+ result.get_error_string())
    else:
        items = result.get_items()
        for item in items:
            if isinstance(item, TextLineResultItem):
                print(f"{RED}{item.get_text()}{RESET}")

                location = item.get_location()
                points = [(p.x, p.y) for p in location.points]
                cv2.drawContours(cv_image, [np.intp(points)], 0, (0, 255, 0), 2)

                cv2.putText(cv_image, item.get_text(), (points[0][0] + 10, points[0][1] + 20),
        
        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)
    
        cv2.imshow(
            os.path.basename(image_path), cv_image)
```

## Step 5: Build an Interactive File and Directory Scanner

Add a loop to handle single files or directories:

```python
import os

def main():
    cvr = CaptureVisionRouter()
    # ... initialization code from previous steps ...
    
    while True:
        path = input("Enter image path or directory (Q to quit): ").strip()
        
        if path.lower() == "q":
            break
            
        if not os.path.exists(path):
            print("File not found: " + path)
            continue
        else:
            if os.path.isfile(path):
                process_image(path, cvr)
            elif os.path.isdir(path):
                files = os.listdir(path)
                for file in files:
                    if file.endswith(".jpg") or file.endswith(".jpeg") or file.endswith(".png"):
                        process_image(os.path.join(path, file), cvr)
                    
            cv2.waitKey(0)
            cv2.destroyAllWindows()

if __name__ == '__main__':
    main()
```

## Step 6: Run the SEMI Font OCR Application

```bash
python read_semi_ocr.py
```

![SEMI OCR Font from multiple images](./img/2025/07/semi-font-ocr-recognition-multiple.png)

## Common Issues & Edge Cases

- **Model file not found**: Ensure `models/semi-ocr.data` is present in the working directory. `append_model_buffer()` returns a non-zero error code if the file cannot be read — inspect `err_str` for details.
- **`EC_LICENSE_CACHE_USED` on startup**: This is not a failure; the SDK is using a locally cached license and recognition proceeds normally. Only treat the result as an error when the code is neither `EC_OK` nor `EC_LICENSE_CACHE_USED`.
- **Empty results from `get_items()`**: Verify that `semi-ocr.json` was loaded successfully and that the task name passed to `cvr.capture()` — `"recognize_semi_ocr"` — exactly matches the template name defined in that JSON file.
- **Low accuracy on degraded wafers**: The custom model targets clean single-density dot-matrix fonts. For heavily worn or etched surfaces, apply contrast enhancement or grayscale normalization with OpenCV before calling `cvr.capture()`.

## Source Code

[Get the complete sample project source code on GitHub](https://github.com/yushulx/python-barcode-qrcode-sdk/edit/main/examples/official/semi_font_ocr)
