#include <iostream>
#include <fstream>
const char* keys =
"{ help h | | Print help message. }"
"{ input i | | Path to input image or video file. Skip this argument to capture frames from a camera.}"
"{ detModel dmp | | Path to a binary .pb file contains trained detector network.}"
"{ width | 320 | Preprocess input image by resizing to a specific width. It should be multiple by 32. }"
"{ height | 320 | Preprocess input image by resizing to a specific height. It should be multiple by 32. }"
"{ thr | 0.5 | Confidence threshold. }"
"{ nms | 0.4 | Non-maximum suppression threshold. }"
"{ recModel rmp | | Path to a binary .onnx file contains trained CRNN text recognition model. "
"Download links are provided in doc/tutorials/dnn/dnn_text_spotting/dnn_text_spotting.markdown}"
"{ RGBInput rgb |0| 0: imread with flags=IMREAD_GRAYSCALE; 1: imread with flags=IMREAD_COLOR. }"
"{ 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);
int main(int argc, char** argv)
{
parser.about("Use this script to run TensorFlow implementation (https://github.com/argman/EAST) of "
"EAST: An Efficient and Accurate Scene Text Detector (https://arxiv.org/abs/1704.03155v2)");
if (argc == 1 || parser.has("help"))
{
parser.printMessage();
return 0;
}
float confThreshold = parser.get<float>("thr");
float nmsThreshold = parser.get<float>("nms");
int width = parser.get<int>("width");
int height = parser.get<int>("height");
int imreadRGB = parser.get<int>("RGBInput");
if (!parser.check())
{
parser.printErrors();
return 1;
}
CV_Assert(!detModelPath.empty() && !recModelPath.empty());
detector.setConfidenceThreshold(confThreshold)
.setNMSThreshold(nmsThreshold);
std::ifstream vocFile;
std::vector<String> vocabulary;
while (std::getline(vocFile, vocLine)) {
vocabulary.push_back(vocLine);
}
recognizer.setVocabulary(vocabulary);
recognizer.setDecodeType("CTC-greedy");
double recScale = 1.0 / 127.5;
recognizer.setInputParams(recScale, recInputSize, recMean);
double detScale = 1.0;
Size detInputSize =
Size(width, height);
bool swapRB = true;
detector.setInputParams(detScale, detInputSize, detMean, swapRB);
bool openSuccess = parser.has(
"input") ? cap.
open(parser.get<
String>(
"input")) : cap.
open(0);
static const std::string kWinName = "EAST: An Efficient and Accurate Scene Text Detector";
{
cap >> frame;
if (frame.empty())
{
break;
}
std::cout << frame.size << std::endl;
std::vector< std::vector<Point> > detResults;
detector.detect(frame, detResults);
if (detResults.size() > 0) {
if (!imreadRGB) {
} else {
recInput = frame;
}
std::vector< std::vector<Point> > contours;
for (
uint i = 0; i < detResults.size(); i++)
{
const auto& quadrangle = detResults[i];
contours.emplace_back(quadrangle);
std::vector<Point2f> quadrangle_2f;
for (int j = 0; j < 4; j++)
quadrangle_2f.emplace_back(quadrangle[j]);
fourPointsTransform(recInput, &quadrangle_2f[0], cropped);
std::string recognitionResult = recognizer.recognize(cropped);
std::cout << i << ": '" << recognitionResult << "'" << std::endl;
}
}
}
return 0;
}
void fourPointsTransform(
const Mat& frame,
const Point2f vertices[],
Mat& result)
{
};
}