我正在尝试从这张图片中读取字符。但是两者之间的曲线阻碍了这一过程。有人可以帮我吗?如何从此类图像中提取字母?
img = cv2.imread('screenshot.png', 0)
ret, thresh_img = cv2.threshold(img, 125, 255, cv2.THRESH_BINARY_INV)
cv2.imshow('grey image',thresh_img)
cv2.imwrite("result11.jpg", thresh_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
我试图将其转换为灰度并消除波动噪声。我做不到。请帮我。新手使用OpenCV。
答案 0 :(得分:0)
您可以应用以下顺序:
1-自适应阈值
2-形态转化
3-按位操作
步骤1: Adaptive Threshold
第2步:Morphological Transformation
步骤3: Bitwise operation
现在,如果我们从图像中读取,结果将是:
dbdhm
代码:
import cv2
import numpy as np
import pytesseract
img = cv2.imread("UzhPS.png")
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
flt = cv2.adaptiveThreshold(gry,
100, cv2.ADAPTIVE_THRESH_MEAN_C,
cv2.THRESH_BINARY, 13, 16)
krn = np.ones((3, 3), np.uint8)
opn = cv2.morphologyEx(flt, cv2.MORPH_OPEN, krn)
cls = cv2.morphologyEx(opn, cv2.MORPH_CLOSE, krn)
gry = cv2.bitwise_or(gry, cls)
txt = pytesseract.image_to_string(gry)
print(txt[2:])