nareshmlx/opencv-pr huggingface dataset:
**File:** samples/dnn/scene_text_spotting.cpp
**Change Type:** added
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition
**Review Line:** 26

**Code Changes:**
```diff
+        "{ binaryThreshold bt               |0.3| Confidence threshold of the binary map. }"
+        "{ polygonThreshold pt              |0.5| Confidence threshold of polygons. }"
+        "{ maxCandidate max                 |200| Max candidates of polygons. }"
+        "{ unclipRatio ratio                |2.0| unclip ratio. }"
+        "{ vocabularyPath vp                | alphabet_36.txt | Path to benchmarks for evaluation. "
+            "Download links are provided in doc/tutorials/dnn/dnn_text_spotting/dnn_text_spotting.markdown}";
+
+void fourPointsTransform(const Mat& frame, const Point2f vertices[], Mat& result);
+bool sortPts(const Point& p1, const Point& p2);
+
+int main(int argc, char** argv)
```

Review comment:
The methods of scene text detection can be divided into (1) regression-based method and (2) segmentation-based method. The original method (EAST) in text_detection.cpp is a regression-based method, while the new method is a segmentation-based method. Different post-processing is needed in the inference for them, so we can not directly rewrite the text_detection.cpp with my API. We should add at least two post-processing in the `TextDetectionModel` for the mentioned two kinds of methods. The methods of scene text recognition can be divided into (1) CTC-based method and (2) Attention-based method. All of the samples adopts the CTC-based method (CRNN) for recognition because the current DNN module can not support some layers. In the following months, I will put some issues about them which are quite needed. As you see, this is the first version of APIs for text detection and recognition. I will keep working on it and add more methods to make it as flexible as possible in the future.
**File:** samples/dnn/scene_text_detection.cpp
**Change Type:** added
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -0,0 +1,151 @@
+#include <iostream>
+#include <fstream>
+#include <regex>
+
+#include <opencv2/imgproc.hpp>
+#include <opencv2/highgui.hpp>
+#include <opencv2/dnn/dnn.hpp>
+
+using namespace cv;
```

Review comment:
I have updated all `imread` with `samples::findFile()`
**File:** doc/tutorials/dnn/table_of_content_dnn.markdown
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -79,4 +79,14 @@ Deep Neural Networks (dnn module) {#tutorial_table_of_content_dnn}
 
     *Author:* Zihao Mu
 
-    In this tutorial you will learn how to use opencv_dnn module using custom OCR models.
\ No newline at end of file
+    In this tutorial you will learn how to use opencv_dnn module using custom OCR models.
+
+-   @subpage tutorial_dnn_text_spotting
+
```

Review comment:
I have changed it to 4.5
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
User should know the options so it must be documented or we can add enum
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
I mean that this line is then converted to documentation so users should know how this parameter changes the behavior
**File:** samples/dnn/scene_text_spotting.cpp
**Change Type:** added
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition
**Review Line:** 26

**Code Changes:**
```diff
+        "{ binaryThreshold bt               |0.3| Confidence threshold of the binary map. }"
+        "{ polygonThreshold pt              |0.5| Confidence threshold of polygons. }"
+        "{ maxCandidate max                 |200| Max candidates of polygons. }"
+        "{ unclipRatio ratio                |2.0| unclip ratio. }"
+        "{ vocabularyPath vp                | alphabet_36.txt | Path to benchmarks for evaluation. "
+            "Download links are provided in doc/tutorials/dnn/dnn_text_spotting/dnn_text_spotting.markdown}";
+
+void fourPointsTransform(const Mat& frame, const Point2f vertices[], Mat& result);
+bool sortPts(const Point& p1, const Point& p2);
+
+int main(int argc, char** argv)
```

Review comment:
I just worry that we introduce an API which is not generic. Initial idea for the High Level API to help users start fast. Initially, we designed it for object detection networks which also have different post-processing depends on network family.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
I have updated the parameter description for a better understanding.
**File:** samples/dnn/scene_text_spotting.cpp
**Change Type:** added
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition
**Review Line:** 26

**Code Changes:**
```diff
+        "{ binaryThreshold bt               |0.3| Confidence threshold of the binary map. }"
+        "{ polygonThreshold pt              |0.5| Confidence threshold of polygons. }"
+        "{ maxCandidate max                 |200| Max candidates of polygons. }"
+        "{ unclipRatio ratio                |2.0| unclip ratio. }"
+        "{ vocabularyPath vp                | alphabet_36.txt | Path to benchmarks for evaluation. "
+            "Download links are provided in doc/tutorials/dnn/dnn_text_spotting/dnn_text_spotting.markdown}";
+
+void fourPointsTransform(const Mat& frame, const Point2f vertices[], Mat& result);
+bool sortPts(const Point& p1, const Point& p2);
+
+int main(int argc, char** argv)
```

Review comment:
I understand it, and I also have the aspiration to bring the latest topologies and algorithms to OpenCV. As I discussed with the mentors before GSoC, we agreed on the current APIs to be the first version. I think it is a work in progress, and it is needed to be updated with more algorithms in the future.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
`const Mat& prediction, const String& decodeType`
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
`const String&`
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
`= {}`
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
what does it mean "official code"?
**File:** modules/dnn/src/model.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -4,7 +4,6 @@
 
 #include "precomp.hpp"
 #include <algorithm>
-#include <iostream>
 #include <utility>
 #include <iterator>
 
@@ -37,9 +36,10 @@ struct Model::Impl
     virtual void setPreferableBackend(Backend backendId) { net.setPreferableBackend(backendId); }
```

Review comment:
do not use `this->` for class fields
**File:** modules/dnn/src/model.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -4,7 +4,6 @@
 
 #include "precomp.hpp"
 #include <algorithm>
-#include <iostream>
 #include <utility>
 #include <iterator>
 
@@ -37,9 +36,10 @@ struct Model::Impl
     virtual void setPreferableBackend(Backend backendId) { net.setPreferableBackend(backendId); }
```

Review comment:
please reduce code duplication - create a vector of inputs and process it after
**File:** modules/dnn/src/model.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -4,7 +4,6 @@
 
 #include "precomp.hpp"
 #include <algorithm>
-#include <iostream>
 #include <utility>
 #include <iterator>
 
@@ -37,9 +36,10 @@ struct Model::Impl
     virtual void setPreferableBackend(Backend backendId) { net.setPreferableBackend(backendId); }
```

Review comment:
Just use `std::min` and `std::max`
**File:** samples/dnn/scene_text_spotting.cpp
**Change Type:** added
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition
**Review Line:** 26

**Code Changes:**
```diff
+        "{ binaryThreshold bt               |0.3| Confidence threshold of the binary map. }"
+        "{ polygonThreshold pt              |0.5| Confidence threshold of polygons. }"
+        "{ maxCandidate max                 |200| Max candidates of polygons. }"
+        "{ unclipRatio ratio                |2.0| unclip ratio. }"
+        "{ vocabularyPath vp                | alphabet_36.txt | Path to benchmarks for evaluation. "
+            "Download links are provided in doc/tutorials/dnn/dnn_text_spotting/dnn_text_spotting.markdown}";
+
+void fourPointsTransform(const Mat& frame, const Point2f vertices[], Mat& result);
+bool sortPts(const Point& p1, const Point& p2);
+
+int main(int argc, char** argv)
```

Review comment:
> we agreed on the current APIs to be the first version we cannot merge something draft in `opencv/opencv`. API should be scalable and at least cover all the known topologies. There are multiple text detection and recognition network already supported by OpenCV (see the notes from https://github.com/opencv/opencv/blob/master/samples/dnn/text_detection.cpp). So introduced API should manage them.
**File:** samples/dnn/scene_text_spotting.cpp
**Change Type:** added
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition
**Review Line:** 26

**Code Changes:**
```diff
+        "{ binaryThreshold bt               |0.3| Confidence threshold of the binary map. }"
+        "{ polygonThreshold pt              |0.5| Confidence threshold of polygons. }"
+        "{ maxCandidate max                 |200| Max candidates of polygons. }"
+        "{ unclipRatio ratio                |2.0| unclip ratio. }"
+        "{ vocabularyPath vp                | alphabet_36.txt | Path to benchmarks for evaluation. "
+            "Download links are provided in doc/tutorials/dnn/dnn_text_spotting/dnn_text_spotting.markdown}";
+
+void fourPointsTransform(const Mat& frame, const Point2f vertices[], Mat& result);
+bool sortPts(const Point& p1, const Point& p2);
+
+int main(int argc, char** argv)
```

Review comment:
Ok, I will add those topologies to my API in this month. I have to prepare for a test this week.
**File:** modules/dnn/test/test_model.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition
**Review Line:** 610

**Code Changes:**
```diff
+    // Detection algorithm parameters
+    float confThresh = 0.5;
+    float nmsThresh = 0.4;
+
+    testTextDetectionModelByEAST(weightPath, "", imgPath, gt, confThresh, nmsThresh, size, mean, scale, swapRB);
+}
+
 INSTANTIATE_TEST_CASE_P(/**/, Test_Model, dnnBackendsAndTargets());
 
 }} // namespace
```

Review comment:
The API can support EAST now, and there is a code testing for EAST in test_model.cpp. `TEST_P(Test_Model, TextDetectionByEAST)` I have applied my APIs to samples/dnn/text_detection.cpp and tested it successfully with the previous models. But, I am not sure about how to change the file name, because the text_detection.cpp and scene_text_spotting.cpp do the same thing with different algorithms. Do you have any suggestions?
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
I have checked all my codes to update some input parameters with `const &`.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
I have put the official code's URL of this algorithm at the top of these comments.
**File:** modules/dnn/src/model.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -4,7 +4,6 @@
 
 #include "precomp.hpp"
 #include <algorithm>
-#include <iostream>
 #include <utility>
 #include <iterator>
 
@@ -37,9 +36,10 @@ struct Model::Impl
     virtual void setPreferableBackend(Backend backendId) { net.setPreferableBackend(backendId); }
```

Review comment:
shouldn't it be: (float)frame.rows() / impl->size.height;
**File:** modules/dnn/src/model.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -4,7 +4,6 @@
 
 #include "precomp.hpp"
 #include <algorithm>
-#include <iostream>
 #include <utility>
 #include <iterator>
 
@@ -37,9 +36,10 @@ struct Model::Impl
     virtual void setPreferableBackend(Backend backendId) { net.setPreferableBackend(backendId); }
```

Review comment:
Yes, I am sorry about it. The input width and height are the same, so I did not find it.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
OpenCV Public API should not expose internal implementation details. Such details should be moved into .cpp files
**File:** samples/dnn/text_detection.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition
**Review Line:** 7

**Code Changes:**
```diff
-
-    More converted onnx text recognition models can be downloaded directly here:
+    Text recognition models can be downloaded directly here:
     Download link: https://drive.google.com/drive/folders/1cTbQ3nuZG-EKWak6emD_s8_hHXWz7lAr?usp=sharing
-    And these models taken from here:https://github.com/clovaai/deep-text-recognition-benchmark
+    and doc/tutorials/dnn/dnn_text_spotting/dnn_text_spotting.markdown
 
+    How to convert from pb to onnx:
+    Using classes from here: https://github.com/meijieru/crnn.pytorch/blob/master/models/crnn.py
     import torch
     from models.crnn import CRNN
```

Review comment:
Why is this information dropped?
**File:** samples/dnn/text_detection.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition
**Review Line:** 7

**Code Changes:**
```diff
-
-    More converted onnx text recognition models can be downloaded directly here:
+    Text recognition models can be downloaded directly here:
     Download link: https://drive.google.com/drive/folders/1cTbQ3nuZG-EKWak6emD_s8_hHXWz7lAr?usp=sharing
-    And these models taken from here:https://github.com/clovaai/deep-text-recognition-benchmark
+    and doc/tutorials/dnn/dnn_text_spotting/dnn_text_spotting.markdown
 
+    How to convert from pb to onnx:
+    Using classes from here: https://github.com/meijieru/crnn.pytorch/blob/master/models/crnn.py
     import torch
     from models.crnn import CRNN
```

Review comment:
The previous models are taken from this link, but I also provide some other models. How about putting this information into the tutorial in detail? or just leave it here? Do you have any suggestions?
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
I feel confused here, because the `vocabulary` is a member of the `TextRecognitionModel` class. If both of the private and protected members are not allowed, I should define such details as static local variants/functions? For a better understanding, can you show me any proper implementation manners in other existing files?
**File:** samples/dnn/scene_text_detection.cpp
**Change Type:** added
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -0,0 +1,151 @@
+#include <iostream>
+#include <fstream>
+#include <regex>
+
+#include <opencv2/imgproc.hpp>
+#include <opencv2/highgui.hpp>
+#include <opencv2/dnn/dnn.hpp>
+
+using namespace cv;
```

Review comment:
sry, I will check it again.
**File:** modules/dnn/include/opencv2/dnn/dnn.hpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -1309,6 +1309,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.
```

Review comment:
Something like this: https://github.com/opencv/opencv/blob/c3e8a82c9c0b18432627fe100db332b42d64b8d3/modules/dnn/src/model.cpp#L16
**File:** modules/dnn/src/model.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition

**Code Changes:**
```diff
@@ -4,7 +4,6 @@
 
 #include "precomp.hpp"
 #include <algorithm>
-#include <iostream>
 #include <utility>
 #include <iterator>
 
@@ -37,9 +36,10 @@ struct Model::Impl
     virtual void setPreferableBackend(Backend backendId) { net.setPreferableBackend(backendId); }
```

Review comment:
Why we need this?
**File:** modules/dnn/src/model.cpp
**Change Type:** modified
**Context:** PR #17570: [GSoC] High Level API and Samples for Scene Text Detection and Recognition
**Review Line:** 512

**Code Changes:**
```diff
+
+    inline
+    void setVocabulary(const std::vector<std::string>& inputVoc)
+    {
+        vocabulary = inputVoc;
+    }
+
+    inline
+    void setDecodeType(const std::string& type)
+    {
+        decodeType = type;
```

Review comment:
Please use `stl` - resize and insert