我想用python中的机器学习为图像构建OCR。
我对图像进行了预处理,将其转换为灰度,应用了otsu阈值法。
然后我用轮廓线找到文本区域并在其上绘制矩形框。但是之后我该如何提取检测到的文本。我不想用pytesseract。我想用knn或支持向量机或CNN进行预测,但我面临的主要问题是如何利用轮廓线从图像中提取检测到的文本。Image=cv2.imread('DL.png')
I=Image.copy()
i=Image.copy()
G_Image=cv2.cvtColor(Image,cv2.COLOR_BGR2GRAY)
#Otsu Thresholding
blur = cv2.GaussianBlur(G_Image,(1,1),0)
ret,th = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
image, contours, hierarchy = cv2.findContours(th,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
#img = cv2.drawContours(Image, contours, -1, (0,255,0), 3)
for contour in contours:
# get rectangle bounding contour
[x, y, w, h] = cv2.boundingRect(contour)
if h>20:
continue
# draw rectangle around contour on original image
cv2.rectangle(I, (x, y), (x + w, y + h), (255, 0, 255), 0)
现在我如何使用这些检测到的区域并将它们发送到我的机器学习算法(KNN、SVM或CNN)以从图像中获取文本。