DM code recognition

DM code recognitionRoutine Effect IntroductionWhat is DM codeThe difference between DM code and QR code (two-dimensional code)Generate DM codeRun the routineCode ExplanationKey CodeCode structure

 

Routine Effect Introduction

What is DM code

DM code (Data Matrix code) is a two-dimensional barcode with the following characteristics:

  1. The shape is square or rectangular, composed of black and white dots.
  2. Supports smaller sizes, suitable for small area marking
  3. Strong anti-damage ability, can still be read even if it is damaged by 30%
  4. High coding density, can store more data

The difference between DM code and QR code (two-dimensional code)

  1. Appearance recognition:
  1. size:
  1. Application scenarios:
  1. Storage capacity:

Generate DM code

You can use the DM code generation tool provided in our materials, or you can search for an online DM generator online.

image-20250206171646414

Run the routine

After connecting to the IDE, click the Run button in the lower left corner, and use K230 to aim at the DM code we just generated. You can see that the content of the DM code is recognized on the screen.

The [3.00] in the right bracket refers to the rotation offset angle of the DM code.

image-20250206171343608

It should be noted that the recognition success rate of DM is lower than that of QR Code. If it cannot be recognized, you can try rotating the DM code or the camera.

Code Explanation

The complete example code file for this section is located in [Source Code/06.Codes/04.find_datamatrices]

Key Code

Code structure

Execution process:

  1. First import the necessary modules and define constants

  2. In the try block:

    • Initialize and configure the Sensor

    • Initialize the display and media managers

    • Start Sensor

    • Enter the main loop:

      • Check if you need to exit
      • Get image frame
      • Find Data Matrix Code
      • Plotting and displaying results
      • Performing garbage collection
  3. Exception handling:

    • Handling keyboard interrupts
    • Handling other exceptions
  4. Finally, in the finally block:

    • Stop Sensor
    • Destroy Display
    • Enable Hibernation Mode
    • Release the media buffer

The detailed flow chart is as follows:


Yes

No
其他异常
Other Exception
键盘中断
KeyboardInterrupt
开始
Start
导入必要的模块
Import necessary modules
定义检测图像宽高常量
Define image size constants
try 代码块
try block
初始化 sensor
Initialize sensor
重置 sensor
Reset sensor
设置帧大小和格式
Set frame size & format
初始化显示
Initialize display
初始化媒体管理器
Initialize media manager
启动 sensor
Start sensor
主循环
Main loop
检测是否退出
Check exit condition
清理工作
Cleanup
执行 finally 代码块
Run finally block
获取图像帧
Capture frame
查找 Data Matrix 码
Find Data Matrix codes
绘制结果
Draw result
显示图像
Show image
垃圾回收
Garbage collection
打印异常信息
Print error message
打印用户停止信息
Print user stop message
停止 sensor
Stop sensor
销毁显示
Destroy display
启用休眠
Enable sleep
释放媒体缓冲区
Release media buffers
结束
End