Spaces:
Running
Running
Download ocr_detection.py from jovialsoh/InpaintingAndOCRAPI: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/jovialsoh/InpaintingAndOCRAPI/resolve/main/ocr_detection.py
- Command line
-
hf download hf://spaces/jovialsoh/InpaintingAndOCRAPI/ocr_detection.py
-
curl -L -o ocr_detection.py https://huggingface.co/spaces/jovialsoh/InpaintingAndOCRAPI/resolve/main/ocr_detection.py
1.04 kB
| import easyocr, cv2 | |
| class OCRDetection: | |
| def __init__(self): | |
| #initializing of my ocr detection | |
| self.reader = easyocr.Reader(["fr", "en"], gpu=False) | |
| def detection(self, image): | |
| output_data = [] | |
| ocr_result = self.reader.readtext(image) | |
| #getting of text position | |
| for box, text, conf in ocr_result: | |
| x_coords = [point[0] for point in box] | |
| y_coords = [point[1] for point in box] | |
| x = int(min(x_coords)) | |
| y = int(min(y_coords)) | |
| w = int(max(x_coords) - x) | |
| h = int(max(y_coords) - y) | |
| output_data.append({ | |
| "pos_x": x, | |
| "pos_y": y, | |
| "width": w, | |
| "height": h, | |
| "text": text, | |
| "precision": conf | |
| }) | |
| return output_data | |
| if __name__ == "__main__": | |
| print("test") | |
| ocr = OCRDetection() | |
| image = cv2.imread("image1.jpg") | |
| result = ocr.detection(image) | |
| print(result) |