프로젝트

일반

사용자정보

개정판 3b88ca51

ID3b88ca517ab6788fdaaea28cff6dc467b5b591e8
상위 7d8182a0
하위 ce3c9764

백흠경이(가) 6년 이상 전에 추가함

jenkins integration test

차이점 보기:

DTI_PID/DTI_PID/AreaOcrTestmodule.py
1
import http.client
2
import urllib
3
import base64
4
import json
5
import cv2
6
import numpy as np
7
import matplotlib.pyplot as plt
8
import matplotlib.image as mpimg
9
from PIL import Image
10
from io import BytesIO
11
import pytesseract
12

  
13

  
14
CONST_IMG_PID_UY1_K_300DPI = "res/UY1-K-2000_P1_300dpi.png"
15
src = []
16
resized = []
17
croppedSrc = []
18
eventSp = (-1, -1)
19
eventEp = (-1, -1)
20
cropping = False
21

  
22
resizeFactor = 0.15
23

  
24

  
25
def cropSrc(event, x, y, flags, param):
26
    global src
27
    global resized, croppedSrc
28
    global eventSp, cropping
29
    global resizeFactor
30

  
31
    if event == cv2.EVENT_LBUTTONDOWN:
32
        eventSp = (-1, -1)
33
        eventEp = (-1, -1)
34

  
35
        eventSp = (x, y)
36
        cropping = True
37
    elif event == cv2.EVENT_LBUTTONUP:
38
        eventEp = (x, y)
39
        cropping = False
40
        
41
        realSrcEventSp = (int(eventSp[0]/resizeFactor), int(eventSp[1]/resizeFactor))
42
        realSrcEventEp = (int(eventEp[0]/resizeFactor), int(eventEp[1]/resizeFactor))
43
        croppedSrc = src[realSrcEventSp[1]:realSrcEventEp[1], realSrcEventSp[0]:realSrcEventEp[0]]
44
        kernel = np.ones((2, 2), np.uint8)
45
        croppedSrc = cv2.dilate(croppedSrc, kernel)
46
        im = Image.fromarray(croppedSrc)
47
        #ocrData = pytesseract.image_to_data(im, config='-psm 10')
48
        #ocrData = pytesseract.image_to_string(im, config='-psm 10')
49
        ocrData = pytesseract.image_to_boxes(im, config='-c tessedit_char_whitelist="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" -psm 6')
50
        #ocrData = pytesseract.image_to_data(im, config='-c tessedit_char_whitelist=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -psm 6')
51
        #ocrData = pytesseract.image_to_string(im, config = "hocr")
52
        print("tesseract result : \n" + ocrData)
53

  
54
        #### For image_to_data()
55
        #if ocrData:
56
        #    splitOcrData = ocrData.split('\n')
57
        #    size = len(splitOcrData)
58
        #    i = 1
59
        #    while i < size:
60
        #        data = splitOcrData[i]
61
        #        sData = data.split('\t')
62
        #        if len(sData) == 12:
63
        #            text = sData[11]
64
        #            tx = int(sData[6]) // 2
65
        #            ty = int(sData[7]) // 2
66
        #            tw = int(sData[8]) // 2
67
        #            th = int(sData[9]) // 2
68
        #            #realSp = (symbolSp[0]+tx, symbolSp[1]+ty)
69
        #            #cv2.putText(canvas, text, (realSp[0], realSp[1]+th), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 3)
70
        #        i = i+1
71
        
72

  
73
        ## For image_to_boxes()
74
        if ocrData:
75
            splitOcrData = ocrData.split('\n')
76
            for data in splitOcrData:
77
                sData = data.split(' ')
78
                text = sData[0]
79
                tx = int(sData[1])
80
                ty = int(sData[2])
81
                tex = int(sData[3])
82
                tey = int(sData[4])
83
                tw = tex - tx
84
                th = tey - ty
85
                #realSp = (symbolSp[0]+tx, symbolSp[1]+ty)
86
                #cv2.putText(canvas, text, (realSp[0], realSp[1]+th), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 3)
87

  
88
        cv2.imshow('cropped', croppedSrc)
89
        cv2.waitKey(0)
90

  
91

  
92
def main():
93
    global src
94
    global resized, resizeFactor
95
    print('main')
96
    src = cv2.imread(CONST_IMG_PID_UY1_K_300DPI)
97

  
98
    resized = cv2.resize(src, None, fx=resizeFactor, fy=resizeFactor)
99
    cv2.namedWindow('main')
100
    cv2.setMouseCallback('main', cropSrc)
101
    cv2.imshow('main', resized)
102
    cv2.waitKey(0)
103

  
104

  
105
main()

내보내기 Unified diff