After remove captcha’s background.
The image remain digits and noise.
Noise line is all in one color : RGB(127,127,127)
And then using morphology method.
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2)) self.im = cv2.morphologyEx(self.im, cv2.MORPH_CLOSE, kernel)
Some part of digit will be remove.
How to use morphologyEx() remove only color in RGB(127,127,127) ?
Advertisement
Answer
In order to eliminate color within a particular range you have to use cv2.inRange()
function.
Here is the code:
lower = np.array([126,126,126]) #-- Lower range -- upper = np.array([127,127,127]) #-- Upper range -- mask = cv2.inRange(img, lower, upper) res = cv2.bitwise_and(img, img, mask= mask) #-- Contains pixels having the gray color-- cv2.imshow('Result',res)
This is what I got for the two images you have:
Image 1:
Image 2:
You carry on from here.