Python (Windows)

You are currently viewing the documentation for the latest version (3.0.0). To access a different version, click the "Switch version" button located in the upper-right corner of the page.

■ If you are not sure which version of the product you are currently using, please feel free to contact Mech-Mind Technical Support.

This topic introduces how to use the Python samples of Mech-DLK SDK on Windows. For sample descriptions, refer to Sample Usage Guide.

Installation Package Contents

The Mech-DLK SDK installation package contains Python samples in the following directories:

Contents Description

python/dist

Wheel installation package (.whl file) for Python 3.9 to 3.12

python/examples

Python examples

  • Before running the Python samples, copy the relevant files from the cpp/bin directory to a specified location. --resource-path should point to the resource directory that contains the model package and images needed for the sample to run. In this example, cpp/resources is used. You can also specify a custom resource directory if needed. Refer to the Steps for running each sample for detailed instructions.

  • If the file or directory name used to run or compile the sample contains Chinese, find the Language and Region option in Windows Settings, open Beta: Use Unicode UTF-8 for worldwide language support, and then restart your computer.

Prerequisites

To use the Python samples in Mech-DLK SDK, the following software must be installed:

Install Mech-DLK SDK

Obtain the latest version of Mech-DLK SDK from Installation Guide and complete installation.

Install Python

Install any version of Python 3.9–3.12.

Install Python Wheel Package

  1. In the python/dist directory, right-click and select Open in Terminal. In the PowerShell window, run the following command to install the Python wheel package. Ensure the wheel file matches your local Python version; the command below uses Python 3.10 as an example:

    pip install mmind_dl_sdk-3.0.0-cp310-cp310-win_amd64.whl --force-reinstall
  2. Copy the hasp_rt.exe file and all .dll files from cpp/bin to Lib\site-packages\mmind_dl_sdk in your Python installation directory.

    python copy dll

Install OpenCV (Optional)

To run the OpenCV samples, run the following command in a PowerShell terminal:

pip install opencv-python

Install HALCON (Optional)

To run the HALCON samples, first install the HALCON software. Then run the following command in a PowerShell terminal to install the matching Python package.

pip install "mvtec-halcon==20110.*"
The mvtec-halcon version must match your local HALCON software version. This example uses HALCON 20.11, which corresponds to version 20110.x.

Example Adjustment Instructions

Before running the Python samples, customize the input images, model packages, and related resource files to suit your needs. The following content provides examples of common adjustment items.

  • Input image: Replace the detection image or modify the image file path as needed.

  • Model package: The installation package includes a default defect segmentation model package. Replace it with your own model as needed.

  • Output: Adjust the output method of the detection result according to the project requirements, such as modifying the directory, file name, or output location of the result image.

  • Resource files: Add or replace images, model packages, and other resources in cpp/resources directory, or specify a custom directory as needed.

Run Samples

Before running the sample, point --resource-path to a valid resource directory (in this example, cpp/resources is used). If a custom resource directory is used, please make sure it contains the files needed for the sample to run.

Basic Sample

  1. In the python/examples directory, right-click and select Open in Terminal.

  2. Run the following command in an opened PowerShell terminal:

    python basic_infer.py --resource-path "xxx\cpp\resources"
    python run basic sample

Advanced Sample (Multi-Thread Inference)

  1. In the python/examples directory, right-click and select Open in Terminal.

  2. Run the following command in an opened PowerShell terminal:

    python infer_with_multi_thread.py --resource-path "xxx\cpp\resources"
    python run multi thread sample
By default, the multi-thread inference sample uses an inference engine that is independent of each thread. If multiple threads share the same inference engine, ensure the safety of concurrent use of multiple threads.

Advanced Sample (OpenCV)

  1. Before running OpenCV samples, complete dependency installation according to Install OpenCV.

  2. In the python/examples directory, right-click and select Open in Terminal.

  3. Run the following command in an opened PowerShell terminal:

    python infer_with_opencv.py --resource-path "xxx\cpp\resources"
    python run opencv sample

Advanced Sample (HALCON)

  1. Before running the HALCON samples, complete dependency installation according to Install HALCON.

  2. Copy the kernel .dll file (as shown below) of HALCON from bin/x64-win64 in the installation directory of HALCON and paste it to python/examples in the script directory of Python.

    python copy halcon dll
  3. In the python/examples directory, right-click and select Open in Terminal.

  4. Run the following command in an opened PowerShell terminal:

    python infer_with_halcon.py --resource-path "xxx\cpp\resources"
    python run halcon sample

FAQs

Installation Issues

Failed to Install the Wheel Package

  • Problem: An error occurred when the .whl file was installed, indicating that wheel did not match the current Python version.

  • Solution: Check the local Python version and select the wheel file in the python/dist directory.

Operation Issues

Missing .dll Errors

  • Problem: An error occurred when running the Python samples, indicating that SDK-related .dll files were missing or loading failed.

  • Solution: Refer to Install Python Wheel Package and copy the relevant files to the corresponding directory.

Missing Resources or Model Errors

  • Problem: The resource or model is missing.

  • Solution: Confirm that --resource-path points to a valid resource directory and that it contains the model and resource files needed to run the sample.

OpenCV or HALCON Dependency Errors

  • Problem: An error occurred when running the OpenCV or HALCON sample, indicating that a dependency was missing.

  • Solution: Confirm that the corresponding Python package has been installed as needed. For HALCON samples, please copy the core .dll file in the HALCON installation directory to the python/examples directory and then run it.

Is this page helpful?

You can give a feedback in any of the following ways:

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.