【发布时间】:2018-05-28 10:25:50
【问题描述】:
在从包含 2D 矩阵形式的图像中提取整数期间,Tesseract 无法给出正确的结果,并且每次执行代码时结果都会有所不同,任何人都可以知道下面的代码中缺少什么
img = cv2.imread(img_path)
rows = img.shape[0]
cols = img.shape[1]
#print rows , cols
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Apply dilation and erosion to remove some noise
#kernel = np.ones((5,5), np.uint64)
#img = cv2.dilate(img, kernel, iterations=1)
#img = cv2.erode(img, kernel, iterations=1)
# Write image after removed noise
cv2.imwrite(src_path + "removed_noise1.png", img)
# Apply threshold to get image with only black and white
#img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,225,95)
img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C , cv2.THRESH_BINARY ,251,95)
#print cv2.getGaussianKernel(ksize=221,sigma=41)
# Write the image after apply opencv to do some ...
cv2.imwrite(src_path + "thres1.png", img)
# Recognize text with tesseract for python
result = pytesseract.image_to_string(Image.open(src_path + "thres1.png"))
输入
阈值:adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY ,251,95
阈值输出:
输出的形式为 1 5 5 7 5 7 3 8 6 4 9 0 2 4 8 6 1 3 0 2 3 9 0 8 9 可以是行主要形式和列主要形式无关紧要但我们确实需要将给定的输出保存到变量中
【问题讨论】:
-
你能上传一些示例输入图像及其自适应阈值输出吗?
-
我已附上输入文件
-
是不是不小心又发了同一张图?
-
预期的输出是什么?您在此图像中有一个网格,您希望输出哪种格式?
-
输出格式为 1 5 5 7 5 7 3 8 6 4 9 0 2 4 8 6 1 3 0 2 3 9 0 8 9 可以是行主格式和列主格式形式无关紧要,但我们确实需要将给定的输出保存到变量中
标签: python opencv tensorflow tesseract