import cv2
import pytesseract
from PIL import Image
image = cv2.imread(‘D:Automationcaptchascaptcha.png’)
if image is None:
print(“Error: Unable to load image. Please check if the file path is correct and the file exists.”)
else:
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, thresholded = cv2.threshold(gray, 8, 255, cv2.THRESH_BINARY)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
morphed = cv2.morphologyEx(thresholded, cv2.MORPH_CLOSE, kernel)
median = cv2.medianBlur(morphed, 3)
cv2.imshow('Processed Image', median)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('D:Automationcaptchasmorphed_image.png', median)
pytesseract.pytesseract.tesseract_cmd = r'C:/Program Files/Tesseract-OCR/tesseract.exe'
image_path = "D:Automationcaptchasmorphed_image.png"
with Image.open(image_path) as img:
text = pytesseract.image_to_string(image_path, config=' -c tessedit_char_whitelist=0123456789')
print("Text : ", text)
enter image description here
Please me to solve this……………….
New contributor
Ronit Patel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.