#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 a multiple of 32. }"
"{ height | 320 | Preprocess input image by resizing to a specific height. It should be a multiple of 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("使用此指令碼執行TensorFlow實現 (https://github.com/argman/EAST) 的 "
"EAST: 一種高效且準確的場景文字檢測器 (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;
vocFile.open(samples::findFile(vocPath));
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: 一種高效且準確的場景文字檢測器";
{
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;
putText(frame2, recognitionResult, quadrangle[3], FONT_HERSHEY_SIMPLEX, 1.5,
Scalar(0, 0, 255), 2);
}
}
}
return 0;
}
void fourPointsTransform(
const Mat& frame,
const Point2f vertices[],
Mat& result)
{
};
}
#define CV_CheckEQ(v1, v2, msg)
支援以下型別的值:int、float、double。
定義 check.hpp:118
如果陣列沒有元素,則返回 true。
int64_t int64
CV_NODISCARD_STD Mat clone() const
建立陣列及其底層資料的完整副本。
MatSize size
定義 mat.hpp:2187
用於指定影像或矩形大小的模板類。
Definition types.hpp:335
_Tp height
高度
Definition types.hpp:363
_Tp width
寬度
Definition types.hpp:362
用於從影片檔案、影像序列或攝像頭捕獲影片的類。
Definition videoio.hpp:772
virtual bool open(const String &filename, int apiPreference=CAP_ANY)
開啟一個影片檔案或捕獲裝置或IP影片流以進行影片捕獲。
此類表示與EAST模型相容的文字檢測DL網路的高階API。
定義 dnn.hpp:1840
此類表示文字識別網路的高階API。
定義 dnn.hpp:1684
std::string String
定義 cvstd.hpp:151
uint32_t uint
定義 interface.h:42
#define CV_Assert(expr)
在執行時檢查條件,如果失敗則丟擲異常。
定義 base.hpp:423
void imshow(const String &winname, InputArray mat)
在指定視窗中顯示影像。
int waitKey(int delay=0)
等待按鍵按下。
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0, AlgorithmHint hint=cv::ALGO_HINT_DEFAULT)
將影像從一個顏色空間轉換為另一個顏色空間。
@ COLOR_BGR2GRAY
在RGB/BGR和灰度之間轉換,顏色轉換
定義 imgproc.hpp:557
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
繪製文字字串。
void polylines(InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
繪製多條多邊形曲線。
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3