我想对专利牌进行预处理,然后输入 OCR。
在我这个部分,我必须做一般性的事情,因为我只处理一张图像,但后来它们会更多并且从不同的角度进行。
我在插入过滤器的部分,我想知道下一部分是否是找到轮廓或拉直它(为此我使用霍夫变换)。
在合作实验室工作:
!pip install pytesseract
import cv2
import numpy as np
import matplotlib.pyplot as plt
import pytesseract
plt.style.use('dark_background')
crop_img = cv2.imread('/content/0.png')
#IMG2GRAY
gray = cv2.cvtColor(crop_img, cv2.COLOR_BGR2GRAY)
plt.imshow(gray)
#tresh
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
plt.imshow(thresh)
# Otsu's thresholding after Gaussian filtering
blur = cv2.GaussianBlur(thresh,(5,5),0)
th3 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]
plt.imshow(th3)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我的输出,我认为这很糟糕:
这是图像:
这是我使用 HoughTransform 旋转图像时的输出:
最终结果应该是这样的(但请记住,我将对其他图像使用相同的预处理):