0

Let's assume i have a numpy array like

[[1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0]
 [1 0 1 1 0 1 0 1 0 1 0 0 0 0 1 1]
 [1 0 1 1 0 1 1 0 1 0 1 0 1 0 1 0]
 [1 1 0 1 0 1 1 1 0 1 0 1 0 1 1 1]
 [1 0 0 1 0 0 0 1 1 1 0 1 0 0 0 0]
 [1 0 1 1 0 1 0 1 0 1 1 0 0 0 1 1]
 [1 0 0 1 1 0 0 1 1 0 1 0 1 0 0 0]
 [1 1 1 1 0 1 1 1 1 0 1 1 0 0 1 1]
 [1 1 1 1 0 0 0 1 1 0 0 1 0 1 1 0]
 [1 1 0 1 0 1 1 1 1 1 1 0 1 0 0 1]
 [1 0 1 1 0 0 1 1 1 0 1 1 0 1 0 0]
 [1 0 0 1 1 0 0 0 1 0 0 0 1 1 0 1]
 [1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0]
 [1 0 1 1 0 0 0 0 1 1 0 1 1 1 0 1]
 [1 0 1 1 0 1 0 0 0 1 1 1 1 0 1 0]
 [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]]

Which is basically an already deciphered data matrix code from custom code...how can I easily convert this to text?

I tried using the pylibdmtx library but this failed:

from pylibdmtx.pylibdmtx import decode, encode

decode((myarray.tobytes(), 16, 16))

I can obviously use matplotlib save it using imshow to file. Read it in as an image and use the decode function on the image, but since i already have the 16x16 decoded part i want to be efficient. Is there an easy python implementation available for this?

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
Stephan
  • 36
  • 2

1 Answers1

0

I solved it. The problem was this: A: pylibdmtx decode function needs a boundary around the code of atleast 2 empty rows. B: it needs atleast two pixels per value so you need to upscale your numpy array like: 1 1 1 1 instead of just 1

C: you need a value of 255 instead of 1 and you need to make sure the data type is set uint8

Stephan
  • 36
  • 2