deeptextdetection.py 1.3 KB

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