Python 使用glob()将图像目录加载到标签检测工具时出错
标签检测工具,根据设备编号自动识别图像标签并将其输出到excel电子表格中。我一直在尝试检测使用glob()加载的整个图像文件夹的标签。不幸的是,似乎有一个属性错误(图像附加)没有加载所有需要处理的图像。这是我第一次使用glob()函数,我对编码还很陌生。如果您有任何关于在输入目录中递归查找和加载图像的更简单方法的帮助,我们将不胜感激 样本输入图像]: 属性错误:Python 使用glob()将图像目录加载到标签检测工具时出错,python,pandas,opencv,image-processing,python-tesseract,Python,Pandas,Opencv,Image Processing,Python Tesseract,标签检测工具,根据设备编号自动识别图像标签并将其输出到excel电子表格中。我一直在尝试检测使用glob()加载的整个图像文件夹的标签。不幸的是,似乎有一个属性错误(图像附加)没有加载所有需要处理的图像。这是我第一次使用glob()函数,我对编码还很陌生。如果您有任何关于在输入目录中递归查找和加载图像的更简单方法的帮助,我们将不胜感激 样本输入图像]: 属性错误: import re import cv2 import glob import imutils # resizeimage im
import re
import cv2
import glob
import imutils # resizeimage
import pytesseract
import matplotlib.pyplot as plt
import os
import pandas as pd
#Load input image directory
image = [cv2.imread(file) for file in glob.glob('Image Samples/CE Test Pics/*.JPG')]
for im in image: plt.figure()
plt.imshow(im)
plt.show()
# Resize the image - change width to 500
image = imutils.resize(image, width=500)
# Display the original image
cv2.imshow("Original Image", image)
cv2.waitKey(0)
# Convert image to string using PyTesseract
text = pytesseract.image_to_string(image, lang='eng', config='--psm 11')
# Recognizes contract number (modify according to business needs)
for line in text.split('\n'):
# Detects two digits, a hyphen, five digits or characters, a space, and then two digits or characters
if re.match(r'^\d{2}-\w{5} \w{2}$', line):
print(line)
elif re.match(r'^\d{2}-\w{4}', line):
print(line)
elif re.match(r'^\d{2}-\w{5}', line):
print(line)
elif re.match(r'^\d{2}-\w{6}', line):
print(line)
elif re.match(r'^\d{2}-\d{4}\w{1}$', line):
print(line)
elif re.match(r'^\w{2}-\d{4}\w{2}$', line):
print(line)
df = pd.DataFrame({'Original Image': image,
'Contract Number': line})
df = pd.DataFrame({'Original Image': image,
'Contract Number': line})
# print(text)
df.to_excel('./ContractNumberTest.xlsx', sheet_name= 'Air Testing', index = False)
您正在尝试调整图像列表的大小,但您希望自己调整图像的大小Hey Luiggi-感谢您的帮助!什么是递归调整所有图像大小的最佳方法,以便更容易为OCR工具(pytesseract)预处理图像?