我用 PyQt5 GUI 创建了一个用于车牌识别的 python 程序。它使用easyocr从图像中提取文本。它作为 .py 可以正常工作,但是当我将其转换为 .exe 时,easyocr 不起作用。GUI 继续正常工作。该程序的每个部分都有错误消息。所以我可以说一切都很好,除了easyocr。
Pyinstaller 命令;(我也尝试过 --onefile ,结果相同)
pyinstaller --noconfirm --onedir --windowed --add-data
"D:/plaka_tanıma/source;source/"
"D:/plaka_tanıma/main.py"
我创建的脚本;
class PlakaTaniyici():
def __init__(self):
self.__image = None
self.__location = None
self.__text = None
self.__confidence = None
self.__err_message = False
def __resize(self):
height, width, channel = self.__image.shape
oran = 1
if width > height:
oran = 837 / width
else:
oran = 521 / height
self.__image = cv2.resize(self.__image, None, fx=oran, fy=oran)
def __plakaYeriTespit(self):
if self.__image is not None:
gray = cv2.cvtColor(self.__image, cv2.COLOR_BGR2GRAY)
bfilter = cv2.bilateralFilter(gray, 11, 17, 17)
edged = cv2.Canny(bfilter, 30, 200)
key_points = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
countours = sorted(imutils.grab_contours(key_points), key=cv2.contourArea, reverse=True)[:10]
for countour in countours:
approx = cv2.approxPolyDP(countour, 10, True)
if len(approx) == 4:
self.__location = approx
break
else:
self.__err_message = "Gorsel islenemiyor!"
def __plakaOku(self):
if self.__location is not None:
try:
reader = easyocr.Reader(['en'])
tl = self.__location[0][0]
br = self.__location[2][0]
result = reader.readtext(self.__image[tl[1]:br[1], tl[0]:br[0]])
self.__confidence = int(result[0][-1] * 100)
self.__text = result[0][-2]
except:
self.__err_message = "Plaka okunurken hata gerçekleşti."
else:
self.__err_message = "Plaka tespit edilemedi!"
def __sonGorsel(self):
if self.__location is not None:
self.__image = cv2.rectangle(
self.__image,
tuple(self.__location[0][0]),
tuple(self.__location[2][0]),
color=(0, 255, 0),
thickness=4,
)
def plakaTespit(self, image):
self.__reset()
self.__image = image
self.__plakaYeriTespit()
self.__plakaOku()
self.__sonGorsel()
self.__resize()
self.__image = cv2.cvtColor(self.__image, cv2.COLOR_BGR2RGB)
return self.__confidence, self.__text, self.__image, self.__err_message
确切地说,我收到错误消息“Plaka okunurken hata gerçekleşti。”;
def __plakaOku(self):
if self.__location is not None:
try:
reader = easyocr.Reader(['en'])
tl = self.__location[0][0]
br = self.__location[2][0]
result = reader.readtext(self.__image[tl[1]:br[1], tl[0]:br[0]])
self.__confidence = int(result[0][-1] * 100)
self.__text = result[0][-2]
except:
self.__err_message = "Plaka okunurken hata gerçekleşti."
else:
self.__err_message = "Plaka tespit edilemedi!"
self.__location 是图像上车牌的位置。所以程序找到车牌但无法读取。所以我认为这是因为easyocr。同样,它作为 .py 可以 100% 正常工作。我必须将其转换为 .exe。