import cv2
import os
import glob
import pandas as pd
from pylibdmtx import pylibdmtx
import xlsxwriter
# co de for scanning
img_dir = "C:\\images" # Enter Directory of all images
data_path = os.path.join(img_dir,'*g')
files = glob.glob(data_path)
data = []
result=[]
for f1 in files:
img = cv2.imread(f1,cv2.IMREAD_UNCHANGED)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
msg = pylibdmtx.decode(thresh)
print(msg)
data.append(img)
result.append(msg)
print(type(result[0]))
我在列表名称 result 中有一个包含 4 个列表的 lsit 。上面代码的输出是 result 。该代码旨在读取条形码,但它也提供了我不需要的位置。
所以在上面的代码之后,我有一个名为 result 的输出,这给了我::
[[Decoded(data=b'AZ:HP7CXNGSUFEPZCO4GS5RQPY6XY', rect=Rect(left=37, top=152, width=94, height=97))], [Decoded(data=b'AZ:RCHKBW5WGZE98J7E9853OW4ZHE', rect=Rect(left=40, top=125, width=91, height=95))], [Decoded(data=b'AZ:5Z7HME1FRNAZFINDPTDAOTB9GQ', rect=Rect(left=27, top=112, width=88, height=88))]
所以现在我想从所有单个列表中提取或找到 az aprt 并将其导出到 Excel。
AZ:HP7CXNGSUFEPZCO4GS5RQPY6XY
AZ:RCHKBW5WGZE98J7E9853OW4ZHE
AZ:5Z7HME1FRNAZFINDPTDAOTB9GQ
我只想要上面的输出并省略所有位置详细信息。
我尝试过索引,但它说列表超出范围。
请帮助我。
您需要迭代列表并检索每个列表的良好属性。
values = [[Decoded(data=b'AZ:HP7CXNGSUFEPZCO4GS5RQPY6XY', rect=Rect(left=37, top=152, width=94, height=97))],
[Decoded(data=b'AZ:9475EFWZCNARPEJEZEMXDFHIBI', rect=Rect(left=32, top=191, width=90, height=88))],
[Decoded(data=b'AZ:6ECWZUQGEJCR5EZXDH9URCN53M', rect=Rect(left=48, top=183, width=88, height=89))],
[Decoded(data=b'AZ:XZ9P6KTDGREM5KIXUO9IHCTKAQ', rect=Rect(left=73, top=121, width=91, height=94))]]
datas = [value[0].data for value in values] # list of encoded string (b'')
datas = [value[0].data.decode() for value in values] # list of strings