I need to extract captcha, I’m researching opencv. My goal is to solve this form of captcha reliably.
Original Captcha
My temporary solution is:
- convert binary image with threshold
- convert convex
- remove grid
But right now I don’t know how to write the code next.
Can anyone give me keywords or solution for this problem?
My code:
import cv2
import numpy as np
image_path = 'captcha_wb.png'
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
scale_percent = 200
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dim = (width, height)
resized_image = cv2.resize(image, dim, interpolation = cv2.INTER_LINEAR)
# kernel = np.ones((2, 2), np.uint8)
# Using cv2.erode() method
# erode_image = cv2.erode(resized_image, kernel, cv2.BORDER_REFLECT)
_, thresholded_image = cv2.threshold(resized_image, 128, 255, cv2.THRESH_BINARY)
# contours, _= cv2.findContours(thresholded_image, cv2.RETR_TREE,
# cv2.CHAIN_APPROX_SIMPLE)
cv2.imshow('Adaptive Gaussian', thresholded_image)
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()