NaturalHistoryMuseum / pylibdmtx

Read Data Matrix barcodes from Python 2 and 3.
MIT License
145 stars 56 forks source link

Size cannot be set. #60

Open Craftint opened 3 years ago

Craftint commented 3 years ago
encoded_data = encode('A', size='10x10')
print(encoded_data.width)
print(encoded_data.height)

Returns

70
70

While I have set it to be 10x10.

MathijsNL commented 2 years ago

The width and height of the resulting image is 70x70 pixels.

The datamatrix itself is 10x10 cells.

The border around the encoded datamatrix is 10 pixels, so 20 in total. That leaves us with 50 pixels, 5 pixels per cell.

If you want to somehow modify this you can cut off the border and resize as needed.

from PIL import Image
import numpy as np
import cv2

img = Image.frombytes('RGB', (encoded_data.width, encoded_data.height), encoded_data.pixels)
img_cv2 = np.array(img)
resized = cv2.resize(img_cv2 , (14,14), interpolation = cv2.INTER_CUBIC)

resized = cv2.resize(img_cv2 , (14,14), interpolation = cv2.INTER_CUBIC)

Result: