我试图通过去除噪声来细化图像。图像以红色为主,因此我尝试删除除红色以外的任何其他颜色。。下面是一个图像示例
我已找到此代码,但无法正确使用。如果你愿意回答我,把我当作一个新手,一步一步地学习,因为我需要学习的不仅仅是解决一个问题
import cv2
import numpy as np
# Load image
im = cv2.imread('Output.png')
# Make all perfectly green pixels white
im[np.all(im == (193, 47, 47), axis=-1)] = (0,0,0)
# Save result
cv2.imwrite('result1.png',im)
我只需要保留红色和白色作为背景色
我想细化图像,以便能够使用这样的代码从中提取数字
def getCaptcha(img):
pytesseract.pytesseract.tesseract_cmd=r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
img=Image.open(img)
text=pytesseract.image_to_string(img, lang='eng',config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
return text
print(getCaptcha('red_numerals_thresh.jpg'))
print(getCaptcha('red_numerals_result.jpg'))
下面是在Python OpenCV中使用cv2.inRange()实现这一点的一种方法
输入:
阈值图像:
结果:
相关问题 更多 >
编程相关推荐