0

最初,我对所有 OCR 算法进行了调查,我发现 tesseract 是最快和准确的,但在结构化文本中。所以我正在尝试做一些图像操作,以便杂乱图像中的文本也可以被识别。

我试过这段代码

 import cv2 as cv
import numpy as np
from PIL import Image
import pytesseract

def find_area(contours):
    area = []
    for c in contours:
        con_area = cv.contourArea(c)
        area.append(con_area)
    return area
            


img = cv.imread('/home/bharat/Pictures/Bad/c5.jpg')
img1 = cv.imread('/home/bharat/Pictures/Bad/c5.jpg')
img = cv.cvtColor(img,cv.COLOR_BGR2GRAY)

# canny_img = cv.Canny(img,25,255)
# canny_img = hysteresis(canny_img,25,255)
# canny_img1 = cv.Canny(img,10,250)
# canny_img2= cv.Canny(img,50,100)
# ret,img12 = cv.threshold(img,127,255,cv.THRESH_BINARY+cv.THRESH_OTSU)

contours, hierarchy = cv.findContours(img, cv.RETR_TREE  , cv.CHAIN_APPROX_NONE)
print(str(len(contours)))
cv.drawContours(img1,contours,-1,(255,0,0),3)

# sorted_con = sorted(contours,key=cv.contourArea,reverse=True)
# # cv.drawContours(img1,sorted_con,-1,(255,0,0),3)
# for sc in sorted_con[:20]:
#     cv.drawContours(img1,[sc],-1,(255,0,0),3)
#     cv.imshow('wg',img1)
#     cv.waitKey(0)

print(pytesseract.image_to_data(img1,lang='jpn',
config='--oem 2--tessdata-/usr/share/tesseract-ocr/5/tessdata'))
# # img = Image.open("/home/bharat/Pictures/Bad/c13.jpg")
# # img.show()

cv.imshow('as',img1)
cv.imshow('q',img)
# cv.imshow('wg',canny_img1)
# cv.imshow('Org_img',canny_img2)
if cv.waitKey(0)==27:
    cv.destroyAllWindows()

它工作正常,但仍然未检测到图像日文文本 日文文本 2,我也尝试了精明的边缘检测和轮廓检测,但仍然无法识别文本。即使图像质量很好,这也无法识别

4

0 回答 0