DPM(Direct Part Marking), translated into direct part marking in Chinese, refers to the permanent marking of text or readable symbols on the surface of industrial parts (such as automobile hub, circuit board, etc.), such as DataMatrix and QR two-dimensional code. This kind of bar code is difficult to identify. Dynamsoft Barcode Reader SDK v7.2 began to support DPM barcode decoding.

Reading Data Matrix Codes Marked on Parts

Obtain Dynamsoft Barcode Reader SDK Python module The source code, compile and install according to the instructions.

The code for bar code recognition is simple:

from dbr import DynamsoftBarcodeReader
dbr = DynamsoftBarcodeReader()
dbr.initLicense('LICENSE-KEY')
results = dbr.decodeFile(fileName, dbr.BF_ALL)
for result in results:
    print('barcode format: ' + result[0])
    print('barcode value: ' + result[1])

Now let's put a bitmap of the DataMatrix code.

The above code can't decode the graph directly, so it needs to modify the parameters. Online document The method of setting up C language is provided.

runtimeSettings.furtherModes.dpmCodeReadingModes[0] = DPMCRM_GENERAL;
runtimeSettings.localizationModes[0] = LM_STATISTICS_MARKS;

Using Python can be set up through JSON format templates.

  1. Get all the parameters

    	params = dbr.getParameters()
    	import json
    json_obj = json.loads(params)
    
  2. modify parameters

    	templateName = json_obj['ImageParameter']['Name']
    	json_obj['ImageParameter']['DPMCodeReadingModes'][0]['Mode'] = 'DPMCRM_GENERAL'
    	json_obj['ImageParameter']['LocalizationModes'][0]['Mode'] = 'LM_STATISTICS_MARKS'
    
  3. Save settings

    	params = json.dumps(json_obj)
    	ret = dbr.setParameters(params)
    

The decoding result is obtained by running the program:

Complete code

from dbr import DynamsoftBarcodeReader
dbr = DynamsoftBarcodeReader()
dbr.initLicense('LICENSE-KEY')
 
params = dbr.getParameters()
print(params)
 
import json
json_obj = json.loads(params)
# Update JSON object
templateName = json_obj['ImageParameter']['Name']
# DPM
json_obj['ImageParameter']['DPMCodeReadingModes'][0]['Mode'] = 'DPMCRM_GENERAL'
json_obj['ImageParameter']['LocalizationModes'][0]['Mode'] = 'LM_STATISTICS_MARKS'
# Convert JSON object to string
params = json.dumps(json_obj)
# Set parameters
ret = dbr.setParameters(params)
 
results = dbr.decodeFile('dpm.jpg', dbr.BF_ALL)
for result in results:
    print('barcode format: ' + result[0])
    print('barcode value: ' + result[1])

Source code

https://github.com/dynamsoft-dbr/python