Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
eragonruan committed Jun 26, 2018
1 parent 9037b66 commit 794fd8d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
3 changes: 1 addition & 2 deletions ctpn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import text_proposal_connector
from . import text_connect

38 changes: 21 additions & 17 deletions ctpn/demo.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
from __future__ import print_function
import tensorflow as tf
import numpy as np
import os, sys, cv2

import cv2
import glob
import os
import shutil
import sys

import numpy as np
import tensorflow as tf

sys.path.append(os.getcwd())
from lib.networks.factory import get_network
from lib.fast_rcnn.config import cfg,cfg_from_file
from lib.fast_rcnn.config import cfg, cfg_from_file
from lib.fast_rcnn.test import test_ctpn
from lib.utils.timer import Timer
from lib.text_connector.detectors import TextDetector
from lib.text_connector.text_connect_cfg import Config as TextLineCfg


def resize_im(im, scale, max_scale=None):
f=float(scale)/min(im.shape[0], im.shape[1])
if max_scale!=None and f*max(im.shape[0], im.shape[1])>max_scale:
f=float(max_scale)/max(im.shape[0], im.shape[1])
return cv2.resize(im, None,None, fx=f, fy=f,interpolation=cv2.INTER_LINEAR), f
f = float(scale) / min(im.shape[0], im.shape[1])
if max_scale != None and f * max(im.shape[0], im.shape[1]) > max_scale:
f = float(max_scale) / max(im.shape[0], im.shape[1])
return cv2.resize(im, None, None, fx=f, fy=f, interpolation=cv2.INTER_LINEAR), f


def draw_boxes(img,image_name,boxes,scale):
def draw_boxes(img, image_name, boxes, scale):
base_name = image_name.split('/')[-1]
with open('data/results/' + 'res_{}.txt'.format(base_name.split('.')[0]), 'w') as f:
for box in boxes:
Expand All @@ -35,17 +40,18 @@ def draw_boxes(img,image_name,boxes,scale):
cv2.line(img, (int(box[6]), int(box[7])), (int(box[2]), int(box[3])), color, 2)
cv2.line(img, (int(box[4]), int(box[5])), (int(box[6]), int(box[7])), color, 2)

min_x = min(int(box[0]/scale),int(box[2]/scale),int(box[4]/scale),int(box[6]/scale))
min_y = min(int(box[1]/scale),int(box[3]/scale),int(box[5]/scale),int(box[7]/scale))
max_x = max(int(box[0]/scale),int(box[2]/scale),int(box[4]/scale),int(box[6]/scale))
max_y = max(int(box[1]/scale),int(box[3]/scale),int(box[5]/scale),int(box[7]/scale))
min_x = min(int(box[0] / scale), int(box[2] / scale), int(box[4] / scale), int(box[6] / scale))
min_y = min(int(box[1] / scale), int(box[3] / scale), int(box[5] / scale), int(box[7] / scale))
max_x = max(int(box[0] / scale), int(box[2] / scale), int(box[4] / scale), int(box[6] / scale))
max_y = max(int(box[1] / scale), int(box[3] / scale), int(box[5] / scale), int(box[7] / scale))

line = ','.join([str(min_x),str(min_y),str(max_x),str(max_y)])+'\r\n'
line = ','.join([str(min_x), str(min_y), str(max_x), str(max_y)]) + '\r\n'
f.write(line)

img=cv2.resize(img, None, None, fx=1.0/scale, fy=1.0/scale, interpolation=cv2.INTER_LINEAR)
img = cv2.resize(img, None, None, fx=1.0 / scale, fy=1.0 / scale, interpolation=cv2.INTER_LINEAR)
cv2.imwrite(os.path.join("data/results", base_name), img)


def ctpn(sess, net, image_name):
timer = Timer()
timer.tic()
Expand All @@ -62,7 +68,6 @@ def ctpn(sess, net, image_name):
'{:d} object proposals').format(timer.total_time, boxes.shape[0]))



if __name__ == '__main__':
if os.path.exists("data/results/"):
shutil.rmtree("data/results/")
Expand Down Expand Up @@ -98,4 +103,3 @@ def ctpn(sess, net, image_name):
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print(('Demo for {:s}'.format(im_name)))
ctpn(sess, net, im_name)

2 changes: 1 addition & 1 deletion ctpn/demo_pb.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import print_function

import cv2
import glob
import os
import shutil
import sys

import cv2
import numpy as np
import tensorflow as tf
from tensorflow.python.platform import gfile
Expand Down
11 changes: 7 additions & 4 deletions ctpn/generate_pb.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import print_function
from tensorflow.python.framework.graph_util import convert_variables_to_constants

import os
import sys

import tensorflow as tf
import os, sys
from tensorflow.python.framework.graph_util import convert_variables_to_constants

sys.path.append(os.getcwd())
from lib.networks.factory import get_network
from lib.fast_rcnn.config import cfg,cfg_from_file

from lib.fast_rcnn.config import cfg, cfg_from_file

if __name__ == "__main__":
cfg_from_file('ctpn/text.yml')
Expand Down
3 changes: 2 additions & 1 deletion ctpn/train_net.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path
import pprint
import sys
import os.path

sys.path.append(os.getcwd())
from lib.fast_rcnn.train import get_training_roidb, train_net
from lib.fast_rcnn.config import cfg_from_file, get_output_dir, get_log_dir
Expand Down

0 comments on commit 794fd8d

Please sign in to comment.