feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake

1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试
2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程
3.重整权利声明文件,重整代码工程,确保最小化侵权风险

Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake
Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
wangzhengyang
2022-05-10 09:54:44 +08:00
parent ecdd171c6f
commit 718c41634f
10018 changed files with 3593797 additions and 186748 deletions

View File

@ -0,0 +1,42 @@
/**
* @brief It demonstrates the usage of cv::Mat::checkVector.
*/
#include <opencv2/core.hpp>
int main()
{
//! [example-2d]
cv::Mat mat(20, 1, CV_32FC2);
int n = mat.checkVector(2);
CV_Assert(n == 20); // mat has 20 elements
mat.create(20, 2, CV_32FC1);
n = mat.checkVector(1);
CV_Assert(n == -1); // mat is neither a column nor a row vector
n = mat.checkVector(2);
CV_Assert(n == 20); // the 2 columns are considered as 1 element
//! [example-2d]
mat.create(1, 5, CV_32FC1);
n = mat.checkVector(1);
CV_Assert(n == 5); // mat has 5 elements
n = mat.checkVector(5);
CV_Assert(n == 1); // the 5 columns are considered as 1 element
//! [example-3d]
int dims[] = {1, 3, 5}; // 1 plane, every plane has 3 rows and 5 columns
mat.create(3, dims, CV_32FC1); // for 3-d mat, it MUST have only 1 channel
n = mat.checkVector(5); // the 5 columns are considered as 1 element
CV_Assert(n == 3);
int dims2[] = {3, 1, 5}; // 3 planes, every plane has 1 row and 5 columns
mat.create(3, dims2, CV_32FC1);
n = mat.checkVector(5); // the 5 columns are considered as 1 element
CV_Assert(n == 3);
//! [example-3d]
return 0;
}

View File

@ -0,0 +1,36 @@
/**
* @file core_merge.cpp
* @brief It demonstrates the usage of cv::merge.
*
* It shows how to merge 3 single channel matrices into a 3-channel matrix.
*
* @author KUANG Fangjun
* @date August 2017
*/
#include <iostream>
#include <opencv2/core.hpp>
using namespace std;
using namespace cv;
int main()
{
//! [example]
Mat m1 = (Mat_<uchar>(2,2) << 1,4,7,10);
Mat m2 = (Mat_<uchar>(2,2) << 2,5,8,11);
Mat m3 = (Mat_<uchar>(2,2) << 3,6,9,12);
Mat channels[3] = {m1, m2, m3};
Mat m;
merge(channels, 3, m);
/*
m =
[ 1, 2, 3, 4, 5, 6;
7, 8, 9, 10, 11, 12]
m.channels() = 3
*/
//! [example]
return 0;
}

View File

@ -0,0 +1,98 @@
/**
* @file core_reduce.cpp
* @brief It demonstrates the usage of cv::reduce .
*
* It shows how to compute the row sum, column sum, row average,
* column average, row minimum, column minimum, row maximum
* and column maximum of a cv::Mat.
*
* @author KUANG Fangjun
* @date August 2017
*/
#include <iostream>
#include <opencv2/core.hpp>
using namespace std;
using namespace cv;
int main()
{
{
//! [example]
Mat m = (Mat_<uchar>(3,2) << 1,2,3,4,5,6);
Mat col_sum, row_sum;
reduce(m, col_sum, 0, REDUCE_SUM, CV_32F);
reduce(m, row_sum, 1, REDUCE_SUM, CV_32F);
/*
m =
[ 1, 2;
3, 4;
5, 6]
col_sum =
[9, 12]
row_sum =
[3;
7;
11]
*/
//! [example]
Mat col_average, row_average, col_min, col_max, row_min, row_max;
reduce(m, col_average, 0, REDUCE_AVG, CV_32F);
cout << "col_average =\n" << col_average << endl;
reduce(m, row_average, 1, REDUCE_AVG, CV_32F);
cout << "row_average =\n" << row_average << endl;
reduce(m, col_min, 0, REDUCE_MIN, CV_8U);
cout << "col_min =\n" << col_min << endl;
reduce(m, row_min, 1, REDUCE_MIN, CV_8U);
cout << "row_min =\n" << row_min << endl;
reduce(m, col_max, 0, REDUCE_MAX, CV_8U);
cout << "col_max =\n" << col_max << endl;
reduce(m, row_max, 1, REDUCE_MAX, CV_8U);
cout << "row_max =\n" << row_max << endl;
/*
col_average =
[3, 4]
row_average =
[1.5;
3.5;
5.5]
col_min =
[ 1, 2]
row_min =
[ 1;
3;
5]
col_max =
[ 5, 6]
row_max =
[ 2;
4;
6]
*/
}
{
//! [example2]
// two channels
char d[] = {1,2,3,4,5,6};
Mat m(3, 1, CV_8UC2, d);
Mat col_sum_per_channel;
reduce(m, col_sum_per_channel, 0, REDUCE_SUM, CV_32F);
/*
col_sum_per_channel =
[9, 12]
*/
//! [example2]
}
return 0;
}

View File

@ -0,0 +1,39 @@
/**
* @file core_split.cpp
* @brief It demonstrates the usage of cv::split .
*
* It shows how to split a 3-channel matrix into a 3 single channel matrices.
*
* @author KUANG Fangjun
* @date August 2017
*/
#include <iostream>
#include <opencv2/core.hpp>
using namespace std;
using namespace cv;
int main()
{
//! [example]
char d[] = {1,2,3,4,5,6,7,8,9,10,11,12};
Mat m(2, 2, CV_8UC3, d);
Mat channels[3];
split(m, channels);
/*
channels[0] =
[ 1, 4;
7, 10]
channels[1] =
[ 2, 5;
8, 11]
channels[2] =
[ 3, 6;
9, 12]
*/
//! [example]
return 0;
}

View File

@ -0,0 +1,84 @@
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
//! [Algorithm]
Ptr<Feature2D> sbd = SimpleBlobDetector::create();
FileStorage fs_read("SimpleBlobDetector_params.xml", FileStorage::READ);
if (fs_read.isOpened()) // if we have file with parameters, read them
{
sbd->read(fs_read.root());
fs_read.release();
}
else // else modify the parameters and store them; user can later edit the file to use different parameters
{
fs_read.release();
FileStorage fs_write("SimpleBlobDetector_params.xml", FileStorage::WRITE);
sbd->write(fs_write);
fs_write.release();
}
Mat result, image = imread("../data/detect_blob.png", IMREAD_COLOR);
vector<KeyPoint> keypoints;
sbd->detect(image, keypoints, Mat());
drawKeypoints(image, keypoints, result);
for (vector<KeyPoint>::iterator k = keypoints.begin(); k != keypoints.end(); ++k)
circle(result, k->pt, (int)k->size, Scalar(0, 0, 255), 2);
imshow("result", result);
waitKey(0);
//! [Algorithm]
//! [RotatedRect_demo]
Mat test_image(200, 200, CV_8UC3, Scalar(0));
RotatedRect rRect = RotatedRect(Point2f(100,100), Size2f(100,50), 30);
Point2f vertices[4];
rRect.points(vertices);
for (int i = 0; i < 4; i++)
line(test_image, vertices[i], vertices[(i+1)%4], Scalar(0,255,0), 2);
Rect brect = rRect.boundingRect();
rectangle(test_image, brect, Scalar(255,0,0), 2);
imshow("rectangles", test_image);
waitKey(0);
//! [RotatedRect_demo]
{
//! [TickMeter_total]
TickMeter tm;
tm.start();
// do something ...
tm.stop();
cout << "Total time: " << tm.getTimeSec() << endl;
//! [TickMeter_total]
}
{
const int COUNT = 100;
//! [TickMeter_average]
TickMeter tm;
for (int i = 0; i < COUNT; i++)
{
tm.start();
// do something ...
tm.stop();
}
cout << "Average time per iteration in seconds: " << tm.getAvgTimeSec() << endl;
cout << "Average FPS: " << tm.getFPS() << endl;
//! [TickMeter_average]
}
return 0;
}

View File

@ -0,0 +1,54 @@
#include <opencv2/imgcodecs.hpp>
using namespace cv;
using namespace std;
static void paintAlphaMat(Mat &mat)
{
CV_Assert(mat.channels() == 4);
for (int i = 0; i < mat.rows; ++i)
{
for (int j = 0; j < mat.cols; ++j)
{
Vec4b& bgra = mat.at<Vec4b>(i, j);
bgra[0] = UCHAR_MAX; // Blue
bgra[1] = saturate_cast<uchar>((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX); // Green
bgra[2] = saturate_cast<uchar>((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); // Red
bgra[3] = saturate_cast<uchar>(0.5 * (bgra[1] + bgra[2])); // Alpha
}
}
}
int main()
{
Mat mat(480, 640, CV_8UC4); // Create a matrix with alpha channel
paintAlphaMat(mat);
vector<int> compression_params;
compression_params.push_back(IMWRITE_PNG_COMPRESSION);
compression_params.push_back(9);
bool result = false;
try
{
result = imwrite("alpha.png", mat, compression_params);
}
catch (const cv::Exception& ex)
{
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
if (result)
printf("Saved PNG file with alpha data.\n");
else
printf("ERROR: Can't save PNG file.\n");
vector<Mat> imgs;
imgs.push_back(mat);
imgs.push_back(~mat);
imgs.push_back(mat(Rect(0, 0, mat.cols / 2, mat.rows / 2)));
imwrite("test.tiff", imgs);
printf("Multiple files saved in test.tiff\n");
return result ? 0 : 1;
}

View File

@ -0,0 +1,33 @@
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <math.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat img, gray;
if( argc != 2 || !(img=imread(argv[1], 1)).data)
return -1;
cvtColor(img, gray, COLOR_BGR2GRAY);
// smooth it, otherwise a lot of false circles may be detected
GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
vector<Vec3f> circles;
HoughCircles(gray, circles, HOUGH_GRADIENT,
2, gray.rows/4, 200, 100 );
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// draw the circle center
circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
// draw the circle outline
circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
namedWindow( "circles", 1 );
imshow( "circles", img );
waitKey(0);
return 0;
}

View File

@ -0,0 +1,31 @@
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat src, dst, color_dst;
if( argc != 2 || !(src=imread(argv[1], 0)).data)
return -1;
Canny( src, dst, 50, 200, 3 );
cvtColor( dst, color_dst, COLOR_GRAY2BGR );
vector<Vec4i> lines;
HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
for( size_t i = 0; i < lines.size(); i++ )
{
line( color_dst, Point(lines[i][0], lines[i][1]),
Point( lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
}
namedWindow( "Source", 1 );
imshow( "Source", src );
namedWindow( "Detected Lines", 1 );
imshow( "Detected Lines", color_dst );
waitKey(0);
return 0;
}

View File

@ -0,0 +1,34 @@
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat lines;
vector<Vec3d> line3d;
vector<Point2f> point;
const static float Points[20][2] = {
{ 0.0f, 369.0f }, { 10.0f, 364.0f }, { 20.0f, 358.0f }, { 30.0f, 352.0f },
{ 40.0f, 346.0f }, { 50.0f, 341.0f }, { 60.0f, 335.0f }, { 70.0f, 329.0f },
{ 80.0f, 323.0f }, { 90.0f, 318.0f }, { 100.0f, 312.0f }, { 110.0f, 306.0f },
{ 120.0f, 300.0f }, { 130.0f, 295.0f }, { 140.0f, 289.0f }, { 150.0f, 284.0f },
{ 160.0f, 277.0f }, { 170.0f, 271.0f }, { 180.0f, 266.0f }, { 190.0f, 260.0f }
};
for (int i = 0; i < 20; i++)
{
point.push_back(Point2f(Points[i][0],Points[i][1]));
}
double rhoMin = 0.0f, rhoMax = 360.0f, rhoStep = 1;
double thetaMin = 0.0f, thetaMax = CV_PI / 2.0f, thetaStep = CV_PI / 180.0f;
HoughLinesPointSet(point, lines, 20, 1,
rhoMin, rhoMax, rhoStep,
thetaMin, thetaMax, thetaStep);
lines.copyTo(line3d);
printf("votes:%d, rho:%.7f, theta:%.7f\n",(int)line3d.at(0).val[0], line3d.at(0).val[1], line3d.at(0).val[2]);
}

View File

@ -0,0 +1,32 @@
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
// We need an input image. (can be grayscale or color)
if (argc < 2)
{
cerr << "We need an image to process here. Please run: colorMap [path_to_image]" << endl;
return -1;
}
Mat img_in = imread(argv[1]);
if(img_in.empty())
{
cerr << "Sample image (" << argv[1] << ") is empty. Please adjust your path, so it points to a valid input image!" << endl;
return -1;
}
// Holds the colormap version of the image:
Mat img_color;
// Apply the colormap:
applyColorMap(img_in, img_color, COLORMAP_JET);
// Show the result:
imshow("colorMap", img_color);
waitKey(0);
return 0;
}

View File

@ -0,0 +1,55 @@
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
int main( int argc, char** argv )
{
Mat src, hsv;
if( argc != 2 || !(src=imread(argv[1], 1)).data )
return -1;
cvtColor(src, hsv, COLOR_BGR2HSV);
// Quantize the hue to 30 levels
// and the saturation to 32 levels
int hbins = 30, sbins = 32;
int histSize[] = {hbins, sbins};
// hue varies from 0 to 179, see cvtColor
float hranges[] = { 0, 180 };
// saturation varies from 0 (black-gray-white) to
// 255 (pure spectrum color)
float sranges[] = { 0, 256 };
const float* ranges[] = { hranges, sranges };
MatND hist;
// we compute the histogram from the 0-th and 1-st channels
int channels[] = {0, 1};
calcHist( &hsv, 1, channels, Mat(), // do not use mask
hist, 2, histSize, ranges,
true, // the histogram is uniform
false );
double maxVal=0;
minMaxLoc(hist, 0, &maxVal, 0, 0);
int scale = 10;
Mat histImg = Mat::zeros(sbins*scale, hbins*10, CV_8UC3);
for( int h = 0; h < hbins; h++ )
for( int s = 0; s < sbins; s++ )
{
float binVal = hist.at<float>(h, s);
int intensity = cvRound(binVal*255/maxVal);
rectangle( histImg, Point(h*scale, s*scale),
Point( (h+1)*scale - 1, (s+1)*scale - 1),
Scalar::all(intensity),
-1 );
}
namedWindow( "Source", 1 );
imshow( "Source", src );
namedWindow( "H-S Histogram", 1 );
imshow( "H-S Histogram", histImg );
waitKey();
}

View File

@ -0,0 +1,39 @@
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
Mat src;
// the first command-line parameter must be a filename of the binary
// (black-n-white) image
if( argc != 2 || !(src=imread(argv[1], 0)).data)
return -1;
Mat dst = Mat::zeros(src.rows, src.cols, CV_8UC3);
src = src > 1;
namedWindow( "Source", 1 );
imshow( "Source", src );
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( src, contours, hierarchy,
RETR_CCOMP, CHAIN_APPROX_SIMPLE );
// iterate through all the top-level contours,
// draw each connected component with its own random color
int idx = 0;
for( ; idx >= 0; idx = hierarchy[idx][0] )
{
Scalar color( rand()&255, rand()&255, rand()&255 );
drawContours( dst, contours, idx, color, FILLED, 8, hierarchy );
}
namedWindow( "Components", 1 );
imshow( "Components", dst );
waitKey(0);
}

View File

@ -0,0 +1,35 @@
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc/segmentation.hpp"
using namespace cv;
static
void usage_example_intelligent_scissors()
{
Mat image(Size(1920, 1080), CV_8UC3, Scalar::all(128));
//! [usage_example_intelligent_scissors]
segmentation::IntelligentScissorsMB tool;
tool.setEdgeFeatureCannyParameters(16, 100) // using Canny() as edge feature extractor
.setGradientMagnitudeMaxLimit(200);
// calculate image features
tool.applyImage(image);
// calculate map for specified source point
Point source_point(200, 100);
tool.buildMap(source_point);
// fast fetching of contours
// for specified target point and the pre-calculated map (stored internally)
Point target_point(400, 300);
std::vector<Point> pts;
tool.getContour(target_point, pts);
//! [usage_example_intelligent_scissors]
}
int main()
{
usage_example_intelligent_scissors();
return 0;
}