mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #17570 from HannibalAPE:text_det_recog_demo
[GSoC] High Level API and Samples for Scene Text Detection and Recognition * APIs and samples for scene text detection and recognition * update APIs and tutorial for Text Detection and Recognition * API updates: (1) put decodeType into struct Voc (2) optimize the post-processing of DB * sample update: (1) add transformation into scene_text_spotting.cpp (2) modify text_detection.cpp with API update * update tutorial * simplify text recognition API update tutorial * update impl usage in recognize() and detect() * dnn: refactoring public API of TextRecognitionModel/TextDetectionModel * update provided models update opencv.bib * dnn: adjust text rectangle angle * remove points ordering operation in model.cpp * update gts of DB test in test_model.cpp * dnn: ensure to keep text rectangle angle - avoid 90/180 degree turns * dnn(text): use quadrangle result in TextDetectionModel API * dnn: update Text Detection API (1) keep points' order consistent with (bl, tl, tr, br) in unclip (2) update contourScore with boundingRect
This commit is contained in:
@@ -1326,6 +1326,255 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
float confThreshold = 0.5f, float nmsThreshold = 0.0f);
|
||||
};
|
||||
|
||||
|
||||
/** @brief This class represents high-level API for text recognition networks.
|
||||
*
|
||||
* TextRecognitionModel allows to set params for preprocessing input image.
|
||||
* TextRecognitionModel creates net from file with trained weights and config,
|
||||
* sets preprocessing input, runs forward pass and return recognition result.
|
||||
* For TextRecognitionModel, CRNN-CTC is supported.
|
||||
*/
|
||||
class CV_EXPORTS_W_SIMPLE TextRecognitionModel : public Model
|
||||
{
|
||||
public:
|
||||
CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
|
||||
TextRecognitionModel();
|
||||
|
||||
/**
|
||||
* @brief Create Text Recognition model from deep learning network
|
||||
* Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method
|
||||
* @param[in] network Net object
|
||||
*/
|
||||
CV_WRAP TextRecognitionModel(const Net& network);
|
||||
|
||||
/**
|
||||
* @brief Create text recognition model from network represented in one of the supported formats
|
||||
* Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method
|
||||
* @param[in] model Binary file contains trained weights
|
||||
* @param[in] config Text file contains network configuration
|
||||
*/
|
||||
CV_WRAP inline
|
||||
TextRecognitionModel(const std::string& model, const std::string& config = "")
|
||||
: TextRecognitionModel(readNet(model, config)) { /* nothing */ }
|
||||
|
||||
/**
|
||||
* @brief Set the decoding method of translating the network output into string
|
||||
* @param[in] decodeType The decoding method of translating the network output into string: {'CTC-greedy': greedy decoding for the output of CTC-based methods}
|
||||
*/
|
||||
CV_WRAP
|
||||
TextRecognitionModel& setDecodeType(const std::string& decodeType);
|
||||
|
||||
/**
|
||||
* @brief Get the decoding method
|
||||
* @return the decoding method
|
||||
*/
|
||||
CV_WRAP
|
||||
const std::string& getDecodeType() const;
|
||||
|
||||
/**
|
||||
* @brief Set the vocabulary for recognition.
|
||||
* @param[in] vocabulary the associated vocabulary of the network.
|
||||
*/
|
||||
CV_WRAP
|
||||
TextRecognitionModel& setVocabulary(const std::vector<std::string>& vocabulary);
|
||||
|
||||
/**
|
||||
* @brief Get the vocabulary for recognition.
|
||||
* @return vocabulary the associated vocabulary
|
||||
*/
|
||||
CV_WRAP
|
||||
const std::vector<std::string>& getVocabulary() const;
|
||||
|
||||
/**
|
||||
* @brief Given the @p input frame, create input blob, run net and return recognition result
|
||||
* @param[in] frame The input image
|
||||
* @return The text recognition result
|
||||
*/
|
||||
CV_WRAP
|
||||
std::string recognize(InputArray frame) const;
|
||||
|
||||
/**
|
||||
* @brief Given the @p input frame, create input blob, run net and return recognition result
|
||||
* @param[in] frame The input image
|
||||
* @param[in] roiRects List of text detection regions of interest (cv::Rect, CV_32SC4). ROIs is be cropped as the network inputs
|
||||
* @param[out] results A set of text recognition results.
|
||||
*/
|
||||
CV_WRAP
|
||||
void recognize(InputArray frame, InputArrayOfArrays roiRects, CV_OUT std::vector<std::string>& results) const;
|
||||
};
|
||||
|
||||
|
||||
/** @brief Base class for text detection networks
|
||||
*/
|
||||
class CV_EXPORTS_W TextDetectionModel : public Model
|
||||
{
|
||||
protected:
|
||||
CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
|
||||
TextDetectionModel();
|
||||
|
||||
public:
|
||||
|
||||
/** @brief Performs detection
|
||||
*
|
||||
* Given the input @p frame, prepare network input, run network inference, post-process network output and return result detections.
|
||||
*
|
||||
* Each result is quadrangle's 4 points in this order:
|
||||
* - bottom-left
|
||||
* - top-left
|
||||
* - top-right
|
||||
* - bottom-right
|
||||
*
|
||||
* Use cv::getPerspectiveTransform function to retrive image region without perspective transformations.
|
||||
*
|
||||
* @note If DL model doesn't support that kind of output then result may be derived from detectTextRectangles() output.
|
||||
*
|
||||
* @param[in] frame The input image
|
||||
* @param[out] detections array with detections' quadrangles (4 points per result)
|
||||
* @param[out] confidences array with detection confidences
|
||||
*/
|
||||
CV_WRAP
|
||||
void detect(
|
||||
InputArray frame,
|
||||
CV_OUT std::vector< std::vector<Point> >& detections,
|
||||
CV_OUT std::vector<float>& confidences
|
||||
) const;
|
||||
|
||||
/** @overload */
|
||||
CV_WRAP
|
||||
void detect(
|
||||
InputArray frame,
|
||||
CV_OUT std::vector< std::vector<Point> >& detections
|
||||
) const;
|
||||
|
||||
/** @brief Performs detection
|
||||
*
|
||||
* Given the input @p frame, prepare network input, run network inference, post-process network output and return result detections.
|
||||
*
|
||||
* Each result is rotated rectangle.
|
||||
*
|
||||
* @note Result may be inaccurate in case of strong perspective transformations.
|
||||
*
|
||||
* @param[in] frame the input image
|
||||
* @param[out] detections array with detections' RotationRect results
|
||||
* @param[out] confidences array with detection confidences
|
||||
*/
|
||||
CV_WRAP
|
||||
void detectTextRectangles(
|
||||
InputArray frame,
|
||||
CV_OUT std::vector<cv::RotatedRect>& detections,
|
||||
CV_OUT std::vector<float>& confidences
|
||||
) const;
|
||||
|
||||
/** @overload */
|
||||
CV_WRAP
|
||||
void detectTextRectangles(
|
||||
InputArray frame,
|
||||
CV_OUT std::vector<cv::RotatedRect>& detections
|
||||
) const;
|
||||
};
|
||||
|
||||
/** @brief This class represents high-level API for text detection DL networks compatible with EAST model.
|
||||
*
|
||||
* Configurable parameters:
|
||||
* - (float) confThreshold - used to filter boxes by confidences, default: 0.5f
|
||||
* - (float) nmsThreshold - used in non maximum suppression, default: 0.0f
|
||||
*/
|
||||
class CV_EXPORTS_W_SIMPLE TextDetectionModel_EAST : public TextDetectionModel
|
||||
{
|
||||
public:
|
||||
CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
|
||||
TextDetectionModel_EAST();
|
||||
|
||||
/**
|
||||
* @brief Create text detection algorithm from deep learning network
|
||||
* @param[in] network Net object
|
||||
*/
|
||||
CV_WRAP TextDetectionModel_EAST(const Net& network);
|
||||
|
||||
/**
|
||||
* @brief Create text detection model from network represented in one of the supported formats.
|
||||
* An order of @p model and @p config arguments does not matter.
|
||||
* @param[in] model Binary file contains trained weights.
|
||||
* @param[in] config Text file contains network configuration.
|
||||
*/
|
||||
CV_WRAP inline
|
||||
TextDetectionModel_EAST(const std::string& model, const std::string& config = "")
|
||||
: TextDetectionModel_EAST(readNet(model, config)) { /* nothing */ }
|
||||
|
||||
/**
|
||||
* @brief Set the detection confidence threshold
|
||||
* @param[in] confThreshold A threshold used to filter boxes by confidences
|
||||
*/
|
||||
CV_WRAP
|
||||
TextDetectionModel_EAST& setConfidenceThreshold(float confThreshold);
|
||||
|
||||
/**
|
||||
* @brief Get the detection confidence threshold
|
||||
*/
|
||||
CV_WRAP
|
||||
float getConfidenceThreshold() const;
|
||||
|
||||
/**
|
||||
* @brief Set the detection NMS filter threshold
|
||||
* @param[in] nmsThreshold A threshold used in non maximum suppression
|
||||
*/
|
||||
CV_WRAP
|
||||
TextDetectionModel_EAST& setNMSThreshold(float nmsThreshold);
|
||||
|
||||
/**
|
||||
* @brief Get the detection confidence threshold
|
||||
*/
|
||||
CV_WRAP
|
||||
float getNMSThreshold() const;
|
||||
};
|
||||
|
||||
/** @brief This class represents high-level API for text detection DL networks compatible with DB model.
|
||||
*
|
||||
* Related publications: @cite liao2020real
|
||||
* Paper: https://arxiv.org/abs/1911.08947
|
||||
* For more information about the hyper-parameters setting, please refer to https://github.com/MhLiao/DB
|
||||
*
|
||||
* Configurable parameters:
|
||||
* - (float) binaryThreshold - The threshold of the binary map. It is usually set to 0.3.
|
||||
* - (float) polygonThreshold - The threshold of text polygons. It is usually set to 0.5, 0.6, and 0.7. Default is 0.5f
|
||||
* - (double) unclipRatio - The unclip ratio of the detected text region, which determines the output size. It is usually set to 2.0.
|
||||
* - (int) maxCandidates - The max number of the output results.
|
||||
*/
|
||||
class CV_EXPORTS_W_SIMPLE TextDetectionModel_DB : public TextDetectionModel
|
||||
{
|
||||
public:
|
||||
CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
|
||||
TextDetectionModel_DB();
|
||||
|
||||
/**
|
||||
* @brief Create text detection algorithm from deep learning network.
|
||||
* @param[in] network Net object.
|
||||
*/
|
||||
CV_WRAP TextDetectionModel_DB(const Net& network);
|
||||
|
||||
/**
|
||||
* @brief Create text detection model from network represented in one of the supported formats.
|
||||
* An order of @p model and @p config arguments does not matter.
|
||||
* @param[in] model Binary file contains trained weights.
|
||||
* @param[in] config Text file contains network configuration.
|
||||
*/
|
||||
CV_WRAP inline
|
||||
TextDetectionModel_DB(const std::string& model, const std::string& config = "")
|
||||
: TextDetectionModel_DB(readNet(model, config)) { /* nothing */ }
|
||||
|
||||
CV_WRAP TextDetectionModel_DB& setBinaryThreshold(float binaryThreshold);
|
||||
CV_WRAP float getBinaryThreshold() const;
|
||||
|
||||
CV_WRAP TextDetectionModel_DB& setPolygonThreshold(float polygonThreshold);
|
||||
CV_WRAP float getPolygonThreshold() const;
|
||||
|
||||
CV_WRAP TextDetectionModel_DB& setUnclipRatio(double unclipRatio);
|
||||
CV_WRAP double getUnclipRatio() const;
|
||||
|
||||
CV_WRAP TextDetectionModel_DB& setMaxCandidates(int maxCandidates);
|
||||
CV_WRAP int getMaxCandidates() const;
|
||||
};
|
||||
|
||||
//! @}
|
||||
CV__DNN_INLINE_NS_END
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user