【发布时间】:2020-05-14 15:09:55
【问题描述】:
我想对专利牌进行预处理,然后输入 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()
我的输出,我认为这很糟糕:
这是图片:
这是我使用 HoughTransform 旋转图像时的输出:
最终结果应该是这样的(但请记住,我将对其他图像使用相同的预处理):
【问题讨论】:
标签: python python-3.x opencv image-processing