프로젝트

일반

사용자정보

개정판 a91e2268

IDa91e2268a30773903ac58219b94c2e96b99064c5
상위 727341a8
하위 3b798877

함의성이(가) 약 5년 전에 추가함

issue #700: license on, add key generator in webserver /requset_license_key, Authorization : admin

Change-Id: Iec123b8e754bd9e5f690ed6bc93ec9182c3ed1e3

차이점 보기:

DTI_PID/DTI_PID/App.py
127 127
    app._excepthook = sys.excepthook
128 128
    sys.excepthook = app.exception_handler.handler
129 129

  
130
    if True:#QLicenseDialog.check_license_key():
130
    if QLicenseDialog.check_license_key():
131 131
        dlg = Ui_Dialog()
132 132

  
133 133
        selectedProject = dlg.showDialog()
DTI_PID/DTI_PID/TextDetector.py
39 39

  
40 40
    def detectTextAreas(self, img, offset):
41 41
        try:
42
            return self.getTextAreaInfo(img, offset[0], offset[1])
42
            app_doc_data = AppDocData.instance()
43
            
44
            configs = app_doc_data.getConfigs('Engine', 'Text Area')
45
            if (configs and int(configs[0].value) is 1) or not configs:
46
                # get text box original way
47
                return self.getTextAreaInfo(img, offset[0], offset[1])
48
            else:
49
                # using craft
50
                return self.get_text_box_using_craft(img, offset[0], offset[1], web=True)
51

  
43 52
        except Exception as ex:
44 53
            from App import App
45 54
            from AppDocData import MessageType
......
130 139

  
131 140
            ocr_image = imgGray.copy()  # np.ones(imgGray.shape, np.uint8) * 255
132 141

  
133
            configs = app_doc_data.getConfigs('Engine', 'Text Area')
134
            if (configs and int(configs[0].value) is 1) or not configs:
135
                # get text box original way
136
                not_containing_bbox, binary_image = self.getTextBox(ocr_image, imgGray, maxTextSize, minSize)
137
            else:
138
                # using craft
139
                return self.get_text_box_using_craft(ocr_image, maxTextSize, minSize, offset_x, offset_y, web=True)
140

  
142
            not_containing_bbox, binary_image = self.getTextBox(ocr_image, imgGray, maxTextSize, minSize)
143
            
141 144
            rects = []
142 145

  
143 146
            for bbox in not_containing_bbox:
......
238 241

  
239 242
        return tile_info_list
240 243

  
241
    def get_text_box_using_craft(self, ocr_image, maxTextSize, minSize, offset_x, offset_y, web=False):
244
    def get_text_box_using_craft(self, imgGray, offset_x, offset_y, web=False):
242 245
        """ get text box by using craft """
243 246

  
244 247
        from AppWebService import AppWebService
......
247 250
        app_doc_data = AppDocData.instance()
248 251
        project = app_doc_data.getCurrentProject()
249 252

  
253
        ocr_image = imgGray.copy()
254

  
255
        configs = app_doc_data.getConfigs('Text Size', 'Max Text Size')
256
        maxTextSize = int(configs[0].value) if 1 == len(configs) else 100
257
        configs = app_doc_data.getConfigs('Text Size', 'Min Text Size')
258
        minSize = int(configs[0].value) if 1 == len(configs) else 15
259

  
250 260
        binary_image = cv2.threshold(ocr_image, 200, 255, cv2.THRESH_BINARY)[1]
251 261
        
252 262
        score_path = os.path.join(project.getTempPath(), 'OCR_CRAFT_SCORE_{}.png'.format(app_doc_data.imgName))
DTI_PID/WebServer/app.py
1
from flask import Flask, jsonify, request
1
from flask import Flask, jsonify, request, render_template
2 2
import cv2
3 3
import numpy as np
4 4
import sys, os
......
30 30
@app.route('/')
31 31
def index():
32 32
    return 'Hello ID2'
33

  
34
@app.route('/requset_license_key/')
35
def requset_license_key():
36
    return render_template('license.html')
37

  
38
@app.route('/gen_key', methods=['POST'])
39
def gen_key():
40
    import base64
41

  
42
    if request.method == 'POST':
43
        r = request
44

  
45
        key = 'Image Drawing to Intelligent Drawing'
46

  
47
        pw = r.form['Authorization']
48
        clear = r.form['Computer_Name']
49

  
50
        if pw != 'admin':
51
            return 'Invalid Authorization'
52

  
53
        enc = []
54
        for i in range(len(clear)):
55
            key_c = key[i % len(key)]
56
            enc_c = (ord(clear[i]) + ord(key_c)) % 256
57
            enc.append(enc_c)
58

  
59
        new_key = base64.urlsafe_b64encode(bytes(enc))
60

  
61
        return 'License Key for ' + clear + ' : ' + new_key.decode('utf-8')
62

  
63
@app.route('/symbol_box', methods=['POST'])
64
def symbol_box():
65
    if request.method == 'POST':
66
        r = request
67
        nparr = np.fromstring(r.data, np.uint8)
68

  
69
        img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
70

  
71
        boxes = text_craft.get_text_box(img, img_path=None, score_path=None, trained_model=os.path.dirname(os.path.realpath(__file__)) + '\\CRAFT_pytorch_master\\weights\\craft_mlt_25k.pth')
72

  
73
        return jsonify({'symbol_box': boxes})
74

  
33 75
    
34 76
@app.route('/text_box', methods=['POST'])
35 77
def text_box():
DTI_PID/WebServer/templates/license.html
1
<html>
2
   <body>
3
   
4
      <form action = "/gen_key" method = "POST">
5
         <p>Authorization : <input type = "password" name ="Authorization" /></p>
6
         <p>Computer Name : <input type = "text" name = "Computer_Name" /></p>
7
         <p><input type = "submit" value = "submit" /></p>
8
      </form>
9
      
10
   </body>
11
</html>

내보내기 Unified diff