简体   繁体   English

将 numpy 数组数据矩阵代码转换为文本

[英]convert numpy array data matrix code to text

Let's assume i have a numpy array like假设我有一个 numpy 数组

[[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:我尝试使用 pylibdmtx 库,但失败了:

from pylibdmtx.pylibdmtx import decode, encode

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

I can obviously use matplotlib save it using imshow to file.我显然可以使用 matplotlib 使用 imshow 将其保存到文件中。 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.将其作为图像读入并在图像上使用解码 function,但由于我已经拥有 16x16 解码部分,因此我想提高效率。 Is there an easy python implementation available for this?是否有一个简单的 python 实现可用于此?

I solved it.我解决了。 The problem was this: A: pylibdmtx decode function needs a boundary around the code of atleast 2 empty rows.问题是这样的: A: pylibdmtx decode function 需要在至少 2 个空行的代码周围设置一个边界。 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 B:每个值至少需要两个像素,因此您需要升级 numpy 数组,例如:1 1 1 1 而不是 1

C: you need a value of 255 instead of 1 and you need to make sure the data type is set uint8 C:你需要一个值 255 而不是 1 并且你需要确保数据类型设置为 uint8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM