1# -*- coding: utf-8 -*- 2#!/usr/bin/python 3import sys 4import os 5import cv2 as cv 6import numpy as np 7 8def main(): 9 print('\nDeeptextdetection.py') 10 print(' A demo script of text box alogorithm of the paper:') 11 print(' * Minghui Liao et al.: TextBoxes: A Fast Text Detector with a Single Deep Neural Network https://arxiv.org/abs/1611.06779\n') 12 13 if (len(sys.argv) < 2): 14 print(' (ERROR) You must call this script with an argument (path_to_image_to_be_processed)\n') 15 quit() 16 17 if not os.path.isfile('TextBoxes_icdar13.caffemodel') or not os.path.isfile('textbox.prototxt'): 18 print " Model files not found in current directory. Aborting" 19 print " See the documentation of text::TextDetectorCNN class to get download links." 20 quit() 21 22 img = cv.imread(str(sys.argv[1])) 23 textSpotter = cv.text.TextDetectorCNN_create("textbox.prototxt", "TextBoxes_icdar13.caffemodel") 24 rects, outProbs = textSpotter.detect(img); 25 vis = img.copy() 26 thres = 0.6 27 28 for r in range(np.shape(rects)[0]): 29 if outProbs[r] > thres: 30 rect = rects[r] 31 cv.rectangle(vis, (rect[0],rect[1]), (rect[0] + rect[2], rect[1] + rect[3]), (255, 0, 0), 2) 32 33 cv.imshow("Text detection result", vis) 34 cv.waitKey() 35 36if __name__ == "__main__": 37 main() 38