问题描述
我想从这张图片中提取数字。
我已经使用 opencv 使用此代码片段对图像进行了预处理
def inverte(imagem):
imagem = (255-imagem)
return imagem
import cv2
image = cv2.imread('5.jpg',0)
print(image)
thresh = cv2.threshold(image,255,cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
thresh=inverte(thresh)
这段代码的输出是这样的
现在,我使用 tesseract 使用此代码从该图像中获取文本
import pytesseract
image=cv2.imread("output.png")
rgb = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
custom_config = r'--psm 13 --oem 1 -c tessedit_char_whitelist=0123456789'
results = pytesseract.image_to_string(rgb,lang='eng',config=custom_config)
print(results)
我已经尝试了所有有效的 psm 值和 oem 值,但没有给出正确的结果
解决方法
您需要了解以下内容:
你已经知道分页模式,所以我不需要推荐它。
识别文本的一种方法是对图像应用阈值。你有三个选择
您已经应用了简单阈值,但无法获得所需的结果。接下来,您可以应用 #' Merge two tables
#'
#' This is the main and,basically,the only function in joyn.
#'
#' @param x data frame: referred to *left* in R terminology,or *master* in
#' Stata terminology.
#' @param y data frame: referred to *right* in R terminology,or *using* in
#' Stata terminology.
#' @return a data.table joining x and y.
#' @export
#' @import data.table
#'
#' @examples
#' x <- c(1,2)
,即:
现在,如果您使用当前配置阅读它:
adaptive-threshold
很遗憾,无法识别数字 9。
如果我们尝试 607
阈值:
现在,如果您使用当前配置阅读它:
inRange
代码:
607
您可以在 0.3.7
中获得相同的结果这个答案更像是一个文本识别中图像处理的小教程,而不是一个完整的答案。原因是无法识别数字九。不过,我认为解释包含简短的信息和有用的链接,可能会鼓励您识别数字 9。