File size: 1,037 Bytes
8f098cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)