textDetector.hpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #ifndef __OPENCV_TEXT_TEXTDETECTOR_HPP__
  5. #define __OPENCV_TEXT_TEXTDETECTOR_HPP__
  6. #include "ocr.hpp"
  7. namespace cv
  8. {
  9. namespace text
  10. {
  11. //! @addtogroup text_detect
  12. //! @{
  13. /** @brief An abstract class providing interface for text detection algorithms
  14. */
  15. class CV_EXPORTS_W TextDetector
  16. {
  17. public:
  18. /**
  19. @brief Method that provides a quick and simple interface to detect text inside an image
  20. @param inputImage an image to process
  21. @param Bbox a vector of Rect that will store the detected word bounding box
  22. @param confidence a vector of float that will be updated with the confidence the classifier has for the selected bounding box
  23. */
  24. CV_WRAP virtual void detect(InputArray inputImage, CV_OUT std::vector<Rect>& Bbox, CV_OUT std::vector<float>& confidence) = 0;
  25. virtual ~TextDetector() {}
  26. };
  27. /** @brief TextDetectorCNN class provides the functionallity of text bounding box detection.
  28. This class is representing to find bounding boxes of text words given an input image.
  29. This class uses OpenCV dnn module to load pre-trained model described in @cite LiaoSBWL17.
  30. The original repository with the modified SSD Caffe version: https://github.com/MhLiao/TextBoxes.
  31. Model can be downloaded from [DropBox](https://www.dropbox.com/s/g8pjzv2de9gty8g/TextBoxes_icdar13.caffemodel?dl=0).
  32. Modified .prototxt file with the model description can be found in `opencv_contrib/modules/text/samples/textbox.prototxt`.
  33. */
  34. class CV_EXPORTS_W TextDetectorCNN : public TextDetector
  35. {
  36. public:
  37. /**
  38. @overload
  39. @param inputImage an image expected to be a CV_U8C3 of any size
  40. @param Bbox a vector of Rect that will store the detected word bounding box
  41. @param confidence a vector of float that will be updated with the confidence the classifier has for the selected bounding box
  42. */
  43. CV_WRAP virtual void detect(InputArray inputImage, CV_OUT std::vector<Rect>& Bbox, CV_OUT std::vector<float>& confidence) CV_OVERRIDE = 0;
  44. /** @brief Creates an instance of the TextDetectorCNN class using the provided parameters.
  45. @param modelArchFilename the relative or absolute path to the prototxt file describing the classifiers architecture.
  46. @param modelWeightsFilename the relative or absolute path to the file containing the pretrained weights of the model in caffe-binary form.
  47. @param detectionSizes a list of sizes for multiscale detection. The values`[(300,300),(700,500),(700,300),(700,700),(1600,1600)]` are
  48. recommended in @cite LiaoSBWL17 to achieve the best quality.
  49. */
  50. static Ptr<TextDetectorCNN> create(const String& modelArchFilename, const String& modelWeightsFilename,
  51. std::vector<Size> detectionSizes);
  52. /**
  53. @overload
  54. */
  55. CV_WRAP static Ptr<TextDetectorCNN> create(const String& modelArchFilename, const String& modelWeightsFilename);
  56. };
  57. //! @}
  58. }//namespace text
  59. }//namespace cv
  60. #endif // _OPENCV_TEXT_OCR_HPP_