这是代码本身
import cv2
import numpy as np
import imutils
import easyocr
from matplotlib import pyplot as pl
img = cv2.imread('images/lixiang.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_filter = cv2.bilateralFilter(gray, 11, 90, 15)
edges = cv2.Canny(img_filter, 50, 200)
cont = cv2.findContours(edges.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cont = imutils.grab_contours(cont)
cont = sorted(cont, key=cv2.contourArea, reverse=True)[:8]
pos = None
for c in cont:
approx = cv2.approxPolyDP(c, 10, True)
if len(approx) == 4:
pos = approx
break
mask = np.zeros(gray.shape, dtype='uint8')
new_img = cv2.drawContours(mask, [pos], 0, 255, -1)
bitwise_img = cv2.bitwise_and(img, img, mask = mask)
(y, x) = np.where(mask==255 )
(x1, y1) = (np.min(x), np.min(y))
(x2, y2) = (np.max(x), np.max(y))
crop = gray[x1:x2, y1:y2]
text = easyocr.Reader(['en'])
text = text.readtext(crop)
pl.imshow(cv2.cvtColor(crop, cv2.COLOR_BGR2RGB))
pl.show()
错误:
CompleteTraceback (most recent call last):
File "c:\Users\������������\OneDrive\������� ����\a\OpenCV\numbers_plates.py", line 34, in <module>
text = easyocr.Reader(['en'])
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\������������\AppData\Local\Programs\Python\Python311\Lib\site-packages\easyocr\easyocr.py", line 92, in __init__
detector_path = self.getDetectorPath(detect_network)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\������������\AppData\Local\Programs\Python\Python311\Lib\site-packages\easyocr\easyocr.py", line 253, in getDetectorPath
download_and_unzip(self.detection_models[self.detect_network]['url'], self.detection_models[self.detect_network]['filename'], self.model_storage_directory, self.verbose)
File "C:\Users\������������\AppData\Local\Programs\Python\Python311\Lib\site-packages\easyocr\utils.py", line 628, in download_and_unzip
urlretrieve(url, zip_path, reporthook=reporthook)
File "C:\Users\������������\AppData\Local\Programs\Python\Python311\Lib\urllib\request.py", line 277, in urlretrieve
reporthook(blocknum, bs, size)
File "C:\Users\������������\AppData\Local\Programs\Python\Python311\Lib\site-packages\easyocr\utils.py", line 728, in progress_hook
print(f'\r{prefix} |{bar}| {percent}% {suffix}', end='')
File "C:\Users\������������\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1251.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u2588' in position 12: character maps to <undefined>