add opencv code
Browse files- DB_IC15.cpp +45 -0
- readme.txt +16 -0
DB_IC15.cpp
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# OpenCV >= 4.5
|
| 3 |
+
|
| 4 |
+
#include <iostream>
|
| 5 |
+
#include <fstream>
|
| 6 |
+
|
| 7 |
+
#include <opencv2/imgproc.hpp>
|
| 8 |
+
#include <opencv2/highgui.hpp>
|
| 9 |
+
#include <opencv2/dnn.hpp>
|
| 10 |
+
|
| 11 |
+
using namespace cv;
|
| 12 |
+
using namespace cv::dnn;
|
| 13 |
+
|
| 14 |
+
// Load model weights
|
| 15 |
+
TextDetectionModel_DB model("./DB_IC15_resnet50.onnx");
|
| 16 |
+
|
| 17 |
+
// Post-processing parameters
|
| 18 |
+
float binThresh = 0.3;
|
| 19 |
+
float polyThresh = 0.5;
|
| 20 |
+
uint maxCandidates = 200;
|
| 21 |
+
double unclipRatio = 2.0;
|
| 22 |
+
model.setBinaryThreshold(binThresh)
|
| 23 |
+
.setPolygonThreshold(polyThresh)
|
| 24 |
+
.setMaxCandidates(maxCandidates)
|
| 25 |
+
.setUnclipRatio(unclipRatio)
|
| 26 |
+
;
|
| 27 |
+
|
| 28 |
+
// Normalization parameters
|
| 29 |
+
double scale = 1.0 / 255.0;
|
| 30 |
+
Scalar mean = Scalar(122.67891434, 116.66876762, 104.00698793);
|
| 31 |
+
|
| 32 |
+
// The input shape
|
| 33 |
+
Size inputSize = Size(736, 736);
|
| 34 |
+
|
| 35 |
+
model.setInputParams(scale, inputSize, mean);
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
std::vector<std::vector<Point>> detResults;
|
| 39 |
+
model.detect(detResults);
|
| 40 |
+
|
| 41 |
+
// Visualization
|
| 42 |
+
polylines(frame, results, true, Scalar(0, 255, 0), 2);
|
| 43 |
+
imshow("Text Detection", image);
|
| 44 |
+
waitKey();
|
| 45 |
+
|
readme.txt
CHANGED
|
@@ -2,3 +2,19 @@
|
|
| 2 |
see doc\lang\programming\pytorch\文本检测\DBNET 论文代码都有
|
| 3 |
|
| 4 |
see 深入理解神经网络:从逻辑回归到CNN.md -> DBNet 可微分二值化
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
see doc\lang\programming\pytorch\文本检测\DBNET 论文代码都有
|
| 3 |
|
| 4 |
see 深入理解神经网络:从逻辑回归到CNN.md -> DBNet 可微分二值化
|
| 5 |
+
|
| 6 |
+
see https://docs.opencv.org/4.x/d4/d43/tutorial_dnn_text_spotting.html
|
| 7 |
+
|
| 8 |
+
- DB_IC15_resnet50.onnx:
|
| 9 |
+
url: https://drive.google.com/uc?export=dowload&id=17_ABp79PlFt9yPCxSaarVc_DKTmrSGGf
|
| 10 |
+
sha: bef233c28947ef6ec8c663d20a2b326302421fa3
|
| 11 |
+
recommended parameter setting: -inputHeight=736, -inputWidth=1280;
|
| 12 |
+
description: This model is trained on ICDAR2015, so it can only detect English text instances.
|
| 13 |
+
|
| 14 |
+
- DB_IC15_resnet18.onnx:
|
| 15 |
+
url: https://drive.google.com/uc?export=dowload&id=1vY_KsDZZZb_svd5RT6pjyI8BS1nPbBSX
|
| 16 |
+
sha: 19543ce09b2efd35f49705c235cc46d0e22df30b
|
| 17 |
+
recommended parameter setting: -inputHeight=736, -inputWidth=1280;
|
| 18 |
+
description: This model is trained on ICDAR2015, so it can only detect English text instances.
|
| 19 |
+
|
| 20 |
+
|