21 到 31 行.
def captcha_solver(path,threshold):
image = cv2.imread(path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
colmean = image.sum(axis=0)/70
colmean_index = np.where(colmean < threshold)
min_val = np.min(colmean_index)
max_val = np.max(colmean_index)
colmean_index = list(colmean_index)
separators = []
for i in np.arange(0,len(colmean_index[0]) - 1):
if colmean_index[0][i] != colmean_index[0][i+1] - 1:
separators.append(colmean_index[0][i])
1
qza1212 2019-07-31 10:24:11 +08:00 1
def captcha_solver(path,threshold):
image = cv2.imread(path) // 读取图片 image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) // 转灰度图 colmean = image.sum(axis=0)/70 // 对每列取和然后除以 70 colmean_index = np.where(colmean < threshold) // 找到所有小于阈值的列索引,这里索引已经从小到大排好序 min_val = np.min(colmean_index) // 拿到最小索引 max_val = np.max(colmean_index) // 拿到最大索引 colmean_index = list(colmean_index) // mat 转 list separators = [] for i in np.arange(0,len(colmean_index[0]) - 1): // 遍历 list if colmean_index[0][i] != colmean_index[0][i+1] - 1: // 其实就是找不相邻的列 separators.append(colmean_index[0][i]) 整个算法比较简单,大概只能处理非自然场景下指定方向的连通域分割 |