Skip to content

Commit

Permalink
edit README, print less, save result pic in res dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Cabchinoe committed May 24, 2019
1 parent 2e99d80 commit 428695d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.pyc
*.caffemodel
.idea
*.so
results
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ The codes are used for implementing CTPN for scene text detection, described in:
Z. Tian, W. Huang, T. He, P. He and Y. Qiao: Detecting Text in Natural Image with
Connectionist Text Proposal Network, ECCV, 2016.

Online demo is available at: [textdet.com](http://textdet.com)

These demo codes (with our trained model) are for text-line detection (without
side-refinement part).
Expand All @@ -18,15 +17,15 @@ Python2.7, cython and all what Caffe depends on.

# How to run this code

1. Clone this repository with `git clone https://github.com/tianzhi0549/CTPN.git`. It will checkout the codes of CTPN and Caffe we ship.
1. Clone this repository with `git clone https://github.com/Cabchinoe/CTPN.git`. It will checkout the codes of CTPN and Caffe we ship. This repo provides a caffe version works on cuda10 and cudnn 7.

2. Install the caffe we ship with codes bellow.
* Install caffe's dependencies. You can follow [this tutorial](http://caffe.berkeleyvision.org/installation.html). *Note: we need Python support. The CUDA version we need is 7.0.*
* Install caffe's dependencies. You can follow [this tutorial](http://caffe.berkeleyvision.org/installation.html). *Note: we need Python support. The CUDA version we need over 10*
* Enter the directory `caffe`.
* Run `cp Makefile.config.example Makefile.config`.
* Open Makefile.config and set `WITH_PYTHON_LAYER := 1`. If you want to use CUDNN, please also set `CUDNN := 1`. Uncomment the `CPU_ONLY :=1` if you want to compile it without GPU.

*Note: To use CUDNN, you need to download CUDNN from NVIDIA's official website, and install it in advance. The CUDNN version we use is 3.0.*
*Note: To use CUDNN, you need to download CUDNN from NVIDIA's official website, and install it in advance. The CUDNN version we use is 7*
* Run `make -j && make pycaffe`.

3. After Caffe is set up, you need to download a trained model (about 78M) from [Google Drive](https://drive.google.com/open?id=0B7c5Ix-XO7hqQWtKQ0lxTko4ZGs) or [our website](http://textdet.com/downloads/ctpn_trained_model.caffemodel), and then populate it into directory `models`. The model's name should be ` ctpn_trained_model.caffemodel`.
Expand All @@ -42,4 +41,4 @@ If you may want to use other Caffe instead of the one we ship for some reasons,
* Lstm

# License
The codes are released under the MIT License.
The codes are released under the MIT License. (And anti996)
7 changes: 0 additions & 7 deletions src/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ def __init__(self, caffe_model):

def detect(self, im, mean):
im_data=prepare_img(im, mean)
print "dd1"
_=self.caffe_model.forward2({
"data": im_data[np.newaxis, :],
"im_info": np.array([[im_data.shape[1], im_data.shape[2]]], np.float32)
})
print "dd2"
rois=self.caffe_model.blob("rois")
scores=self.caffe_model.blob("scores")
return rois, scores
Expand All @@ -38,19 +36,14 @@ def detect(self, im):
Detecting texts from an image
:return: the bounding boxes of the detected texts
"""
print "start"
text_proposals, scores=self.text_proposal_detector.detect(im, cfg.MEAN)
print "000"
keep_inds=np.where(scores>cfg.TEXT_PROPOSALS_MIN_SCORE)[0]
text_proposals, scores=text_proposals[keep_inds], scores[keep_inds]
print 111
sorted_indices=np.argsort(scores.ravel())[::-1]
text_proposals, scores=text_proposals[sorted_indices], scores[sorted_indices]
print 222
# nms for text proposals
keep_inds=nms(np.hstack((text_proposals, scores)), cfg.TEXT_PROPOSALS_NMS_THRESH)
text_proposals, scores=text_proposals[keep_inds], scores[keep_inds]
print 333
scores=normalize(scores)

text_lines=self.text_proposal_connector.get_text_lines(text_proposals, scores, im.shape[:2])
Expand Down
1 change: 0 additions & 1 deletion src/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def forward2(self, input_data):
for k, v in input_data.items():
self.net.blobs[k].reshape(*v.shape)
self.net.blobs[k].data[...]=v
print 'net forward'
return self.net.forward()

def net_def_file(self):
Expand Down
5 changes: 4 additions & 1 deletion tools/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from detectors import TextProposalDetector, TextDetector
import os.path as osp
from utils.timer import Timer

from PIL import Image
DEMO_IMAGE_DIR="demo_images/"
NET_DEF_FILE="models/deploy.prototxt"
MODEL_FILE="models/ctpn_trained_model.caffemodel"
Expand Down Expand Up @@ -59,6 +59,9 @@
print "Time: %f"%timer.toc()

im_with_text_lines=draw_boxes(im, text_lines, caption=im_name, wait=False)
im_with_text_lines = cv2.cvtColor(im_with_text_lines,cv2.COLOR_BGR2RGB)
Image.fromarray(im_with_text_lines).save('./res/'+im_name)


print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "Thank you for trying our demo. Press any key to exit..."
Expand Down

0 comments on commit 428695d

Please sign in to comment.