Spaces:
Runtime error
Runtime error
# import cv2 | |
# import pytesseract | |
# import numpy as np | |
# image = cv2.imread('rzse0mcqxbgs8z2pf6lr.png') | |
# def get_grayscale(image): | |
# return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
# def remove_noise(image): | |
# return cv2.medianBlur(image,5) | |
# def thresholding(image): | |
# return cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1] | |
# def dilate(image): | |
# kernel = np.ones((5,5),np.uint8) | |
# return cv2.dilate(image, kernel, iterations = 1) | |
# def erode(image): | |
# kernel = np.ones((5,5),np.uint8) | |
# return cv2.erode(image, kernel, iterations = 1) | |
# def opening(image): | |
# kernel = np.ones((5,5),np.uint8) | |
# return cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel) | |
# def canny(image): | |
# return cv2.Canny(image, 100, 200) | |
# def deskew(image): | |
# coords = np.column_stack(np.where(image > 0)) | |
# angle = cv2.minAreaRect(coords)[-1] | |
# if angle < -45: | |
# angle = -(90 + angle) | |
# else: | |
# angle = -angle | |
# (h, w) = image.shape[:2] | |
# center = (w // 2, h // 2) | |
# M = cv2.getRotationMatrix2D(center, angle, 1.0) | |
# rotated = cv2.warpAffine(image, M, (w, h), flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE) | |
# return rotated | |
# def match_template(image, template): | |
# return cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED) | |
# custom_config = r'--oem 3 --psm 6' | |
# pytesseract.image_to_string(image, config=custom_config) | |
# gray = get_grayscale(image) | |
# thresh = thresholding(gray) | |
# opening = opening(gray) | |
# canny = canny(gray) | |
# ocr = PaddleOCR(use_angle_cls=True, lang='en', use_pdserving=False, cls_batch_num=8, det_batch_num=8, rec_batch_num=8) | |
# ocr = PaddleOCR(use_angle_cls=True, lang='en') | |
# def index(url): | |
# response = requests.get(url) | |
# img = Image.open(BytesIO(response.content)) | |
# resize_factor = 1 | |
# new_size = tuple(int(dim * resize_factor) for dim in img.size) | |
# img = img.resize(new_size, Image.Resampling.LANCZOS) | |
# img_array = np.array(img.convert('RGB')) | |
# result = ocr.ocr(img_array) | |
# boxes = [line[0] for line in result] | |
# txts = [line[1][0] for line in result] | |
# scores = [line[1][1] for line in result] | |
# print(boxes) | |
# print(txts) | |
# output_dict = {"texts": txts, "boxes": boxes, "scores": scores} | |
# output_json = json.dumps(output_dict) # Convert to JSON string | |
# return output_json | |
import easyocr | |
image_url = 'https://res.cloudinary.com/ddvajyjou/image/upload/v1706960876/rzse0mcqxbgs8z2pf6lr.png' | |
reader = easyocr.Reader(['en']) | |
result = reader.readtext(image_url) | |
for (bbox, text, prob) in result: | |
print(f'Text: {text}, Probability: {prob}') |