0

i have this html page with image captcha

i want to crop only the captcha image, because i can't get the image source

so i want to crop only the captcha image then pass it on my code to extract number from image

here's the code of extract number from image

import cv2
import numpy as np
import pytesseract

im_path="E:/"
im_name = "test.png"

# Read Image and Crop Borders
img = cv2.imread(im_path+im_name)[3:-2, 5:]

# Threshold on Red Channel
th=185
img[img[...,2]>th]=0

# Gray Color
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Thresholding
binary = cv2.threshold(gray, 0, 255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]

# Resize as original image is small 
scale_ = 5 # of original size
width = int(img.shape[1] * scale_ )
height = int(img.shape[0] * scale_ )
dim = (width, height)
# resize image
resized = cv2.resize(binary, dim, interpolation = cv2.INTER_CUBIC)

# Morhpological Erosion
resized = cv2.erode(resized, None)

# OCR
txt = pytesseract.image_to_string(resized, config='--psm 13 outputbase digits')

# Visualization
cv2.namedWindow("output", cv2.WINDOW_NORMAL)
cv2.imshow("output", resized)
cv2.waitKey(0)

print(txt)

(i got these code from member here named Bilal)

so what i expect is i crop the image from the html page, then passed it on the code above to extract the number from the cropping image

i dont really know how to crop image

Daniel
  • 49
  • 6

0 Answers0