개정판 c64be242
issue #1366: fix path
Change-Id: I2ec81696a73fbc8ffb1b96e2c3289f33f507aebd
.gitignore | ||
---|---|---|
266 | 266 |
/DTI_PID/DTI_PID/res/Result/*.txt |
267 | 267 |
/DTI_PID/PID.db |
268 | 268 |
Projects |
269 |
/DTI_PID/DTI_PID/AppWebService.py |
|
270 |
/DTI_PID/WebServer |
|
271 |
/DTI_PID/DTI_PID/WebServer |
DTI_PID/DTI_PID/TextDetector.py | ||
---|---|---|
128 | 128 |
ocr_image = imgGray.copy() # np.ones(imgGray.shape, np.uint8) * 255 |
129 | 129 |
|
130 | 130 |
# get text box original way |
131 |
not_containing_bbox, binary_image = self.getTextBox(ocr_image, imgGray, maxTextSize, minSize) |
|
131 |
#not_containing_bbox, binary_image = self.getTextBox(ocr_image, imgGray, maxTextSize, minSize)
|
|
132 | 132 |
|
133 | 133 |
# using craft |
134 |
#return self.getTextBox_craft(ocr_image, maxTextSize, minSize, offset_x, offset_y, web=True)
|
|
134 |
return self.getTextBox_craft(ocr_image, maxTextSize, minSize, offset_x, offset_y, web=True) |
|
135 | 135 |
|
136 | 136 |
rects = [] |
137 | 137 |
|
... | ... | |
222 | 222 |
img_path = os.path.join(project.getTempPath(), 'OCR_CRAFT_{}.png'.format(app_doc_data.imgName)) |
223 | 223 |
|
224 | 224 |
if not web: |
225 |
sys.path.insert(0, os.path.join('.\DTIPID_GERRIT\DTI_PID\WebServer\CRAFT_pytorch_master'))
|
|
226 |
from CRAFT_pytorch_master import text_craft
|
|
225 |
sys.path.insert(0, os.path.dirname(os.path.realpath('./'))+ '\\WebServer\\CRAFT_pytorch_master')
|
|
226 |
import text_craft |
|
227 | 227 |
|
228 |
boxes = text_craft.get_text_box(ocr_image, img_path, score_path) |
|
228 |
boxes = text_craft.get_text_box(ocr_image, img_path, score_path, os.path.dirname(os.path.realpath('./')) + '\\WebServer\\CRAFT_pytorch_master\\weights\\craft_mlt_25k.pth')
|
|
229 | 229 |
else: |
230 | 230 |
app_web_service = AppWebService() |
231 | 231 |
boxes = app_web_service.request_text_box(ocr_image, img_path, score_path) |
DTI_PID/WebServer/CRAFT_pytorch_master/craft.py | ||
---|---|---|
8 | 8 |
import torch.nn as nn |
9 | 9 |
import torch.nn.functional as F |
10 | 10 |
|
11 |
from CRAFT_pytorch_master.basenet.vgg16_bn import vgg16_bn, init_weights
|
|
11 |
from basenet.vgg16_bn import vgg16_bn, init_weights |
|
12 | 12 |
#from .basenet.vgg16_bn import vgg16_bn, init_weights |
13 | 13 |
|
14 | 14 |
class double_conv(nn.Module): |
DTI_PID/WebServer/CRAFT_pytorch_master/file_utils.py | ||
---|---|---|
2 | 2 |
import os |
3 | 3 |
import numpy as np |
4 | 4 |
import cv2 |
5 |
from CRAFT_pytorch_master import imgproc
|
|
5 |
import imgproc |
|
6 | 6 |
#import imgproc |
7 | 7 |
|
8 | 8 |
# borrowed from https://github.com/lengstrom/fast-style-transfer/blob/master/src/utils.py |
DTI_PID/WebServer/CRAFT_pytorch_master/text_craft.py | ||
---|---|---|
19 | 19 |
import cv2 |
20 | 20 |
from skimage import io |
21 | 21 |
import numpy as np |
22 |
from CRAFT_pytorch_master import craft_utils |
|
23 |
from CRAFT_pytorch_master import imgproc |
|
24 |
from CRAFT_pytorch_master import file_utils |
|
25 |
#import craft_utils
|
|
26 |
#import imgproc
|
|
27 |
#import file_utils
|
|
22 |
#from CRAFT_pytorch_master import craft_utils
|
|
23 |
#from CRAFT_pytorch_master import imgproc
|
|
24 |
#from CRAFT_pytorch_master import file_utils
|
|
25 |
import craft_utils |
|
26 |
import imgproc |
|
27 |
import file_utils |
|
28 | 28 |
import json |
29 | 29 |
import zipfile |
30 | 30 |
|
31 | 31 |
#from CRAFT_pytorch_master.craft import CRAFT |
32 |
from .craft import CRAFT
|
|
32 |
from craft import CRAFT |
|
33 | 33 |
|
34 | 34 |
from collections import OrderedDict |
35 | 35 |
def copyStateDict(state_dict): |
... | ... | |
97 | 97 |
|
98 | 98 |
return boxes, polys, ret_score_text |
99 | 99 |
|
100 |
def get_text_box(img, img_path, score_path): |
|
100 |
def get_text_box(img, img_path, score_path, trained_model=None):
|
|
101 | 101 |
if img.shape[0] == 2: img = img[0] |
102 | 102 |
if len(img.shape) == 2 : img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB) |
103 | 103 |
if img.shape[2] == 4: img = img[:,:,:3] |
... | ... | |
105 | 105 |
#image = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB) |
106 | 106 |
|
107 | 107 |
parser = argparse.ArgumentParser(description='CRAFT Text Detection') |
108 |
parser.add_argument('--trained_model', default='E:\Projects\DTIPID_GERRIT\DTI_PID\DTI_PID\CRAFT_pytorch_master/weights/craft_mlt_25k.pth', type=str, help='pretrained model')
|
|
108 |
parser.add_argument('--trained_model', default=trained_model, type=str, help='pretrained model')
|
|
109 | 109 |
parser.add_argument('--text_threshold', default=0.7, type=float, help='text confidence threshold') |
110 | 110 |
parser.add_argument('--low_text', default=0.4, type=float, help='text low-bound score') |
111 | 111 |
parser.add_argument('--link_threshold', default=0.4, type=float, help='link confidence threshold') |
DTI_PID/WebServer/app.py | ||
---|---|---|
3 | 3 |
import numpy as np |
4 | 4 |
import sys, os |
5 | 5 |
|
6 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\CRAFT_pytorch_master') |
|
7 |
|
|
6 | 8 |
app = Flask(__name__) |
7 | 9 |
|
8 | 10 |
@app.route('/') |
... | ... | |
11 | 13 |
|
12 | 14 |
@app.route('/text_box', methods=['POST']) |
13 | 15 |
def text_box(): |
14 |
from CRAFT_pytorch_master import text_craft
|
|
16 |
import text_craft |
|
15 | 17 |
|
16 | 18 |
r = request |
17 | 19 |
nparr = np.fromstring(r.data, np.uint8) |
18 | 20 |
|
19 |
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR) |
|
21 |
buff = cv2.imdecode(nparr, cv2.IMREAD_COLOR) |
|
22 |
img = buff.reshape(1, -1) |
|
20 | 23 |
|
21 |
boxes = text_craft.get_text_box(img, img_path=None, score_path=None) |
|
24 |
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')
|
|
22 | 25 |
|
23 | 26 |
return jsonify({'text_box': boxes}) |
24 | 27 |
|
내보내기 Unified diff