我想从我的形象删除线,这将是很容易的,我可以只是侵 eclipse 他们死亡,然后扩大,但有些字母是空的,所以我不能这样做。
"""Importing the modules"""
import cv2
import numpy as np
"""Importing the image and resizing it"""
BASE_IMG = cv2.imread(r"C:\Users\usr\Documents\Python\Projects\CaptchaSolver\captcha.png")
BASE_IMG = cv2.resize(BASE_IMG, (480, 360))
img = cv2.imread(r"C:\Users\usr\Documents\Python\Projects\CaptchaSolver\captcha.png",
cv2.IMREAD_GRAYSCALE)
img = cv2.resize(img, (480, 360))
"""Converting it to binary image and trying my best to get rid of the lines"""
_, img = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY)
img = ~img
img = cv2.erode(img, np.ones((2, 2), np.uint8), iterations=2)
img = cv2.dilate(img, (5, 5), iterations = 3)
img = cv2.Canny(img, 100, 100, edges=1)
cv2.imshow("Base", BASE_IMG)
cv2.imshow("Output", img)
cv2.waitKey(0)
如果你想知道更多细节可以问
1条答案
按热度按时间ohfgkhjo1#
其中一种方法可以是进行边缘检测,应用Hough变换,然后为
cv2.inpaint
方法创建掩码。下面是这种方法的代码:并且输出: