feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
202
3rdparty/opencv-4.5.4/samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp
vendored
Normal file
202
3rdparty/opencv-4.5.4/samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
#include <opencv2/videoio/videoio.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <atomic>
|
||||
|
||||
using namespace cv;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
|
||||
// Stores frames along with their timestamps
|
||||
struct Frame
|
||||
{
|
||||
int64 timestamp;
|
||||
Mat frame;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
//! [Open streams]
|
||||
// Open depth stream
|
||||
VideoCapture depthStream(CAP_OPENNI2_ASTRA);
|
||||
// Open color stream
|
||||
VideoCapture colorStream(0, CAP_V4L2);
|
||||
//! [Open streams]
|
||||
|
||||
// Check that stream has opened
|
||||
if (!colorStream.isOpened())
|
||||
{
|
||||
cerr << "ERROR: Unable to open color stream" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check that stream has opened
|
||||
if (!depthStream.isOpened())
|
||||
{
|
||||
cerr << "ERROR: Unable to open depth stream" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//! [Setup streams]
|
||||
// Set color and depth stream parameters
|
||||
colorStream.set(CAP_PROP_FRAME_WIDTH, 640);
|
||||
colorStream.set(CAP_PROP_FRAME_HEIGHT, 480);
|
||||
depthStream.set(CAP_PROP_FRAME_WIDTH, 640);
|
||||
depthStream.set(CAP_PROP_FRAME_HEIGHT, 480);
|
||||
depthStream.set(CAP_PROP_OPENNI2_MIRROR, 0);
|
||||
//! [Setup streams]
|
||||
|
||||
// Print color stream parameters
|
||||
cout << "Color stream: "
|
||||
<< colorStream.get(CAP_PROP_FRAME_WIDTH) << "x" << colorStream.get(CAP_PROP_FRAME_HEIGHT)
|
||||
<< " @" << colorStream.get(CAP_PROP_FPS) << " fps" << endl;
|
||||
|
||||
//! [Get properties]
|
||||
// Print depth stream parameters
|
||||
cout << "Depth stream: "
|
||||
<< depthStream.get(CAP_PROP_FRAME_WIDTH) << "x" << depthStream.get(CAP_PROP_FRAME_HEIGHT)
|
||||
<< " @" << depthStream.get(CAP_PROP_FPS) << " fps" << endl;
|
||||
//! [Get properties]
|
||||
|
||||
//! [Read streams]
|
||||
// Create two lists to store frames
|
||||
std::list<Frame> depthFrames, colorFrames;
|
||||
const std::size_t maxFrames = 64;
|
||||
|
||||
// Synchronization objects
|
||||
std::mutex mtx;
|
||||
std::condition_variable dataReady;
|
||||
std::atomic<bool> isFinish;
|
||||
|
||||
isFinish = false;
|
||||
|
||||
// Start depth reading thread
|
||||
std::thread depthReader([&]
|
||||
{
|
||||
while (!isFinish)
|
||||
{
|
||||
// Grab and decode new frame
|
||||
if (depthStream.grab())
|
||||
{
|
||||
Frame f;
|
||||
f.timestamp = cv::getTickCount();
|
||||
depthStream.retrieve(f.frame, CAP_OPENNI_DEPTH_MAP);
|
||||
if (f.frame.empty())
|
||||
{
|
||||
cerr << "ERROR: Failed to decode frame from depth stream" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(mtx);
|
||||
if (depthFrames.size() >= maxFrames)
|
||||
depthFrames.pop_front();
|
||||
depthFrames.push_back(f);
|
||||
}
|
||||
dataReady.notify_one();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Start color reading thread
|
||||
std::thread colorReader([&]
|
||||
{
|
||||
while (!isFinish)
|
||||
{
|
||||
// Grab and decode new frame
|
||||
if (colorStream.grab())
|
||||
{
|
||||
Frame f;
|
||||
f.timestamp = cv::getTickCount();
|
||||
colorStream.retrieve(f.frame);
|
||||
if (f.frame.empty())
|
||||
{
|
||||
cerr << "ERROR: Failed to decode frame from color stream" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(mtx);
|
||||
if (colorFrames.size() >= maxFrames)
|
||||
colorFrames.pop_front();
|
||||
colorFrames.push_back(f);
|
||||
}
|
||||
dataReady.notify_one();
|
||||
}
|
||||
}
|
||||
});
|
||||
//! [Read streams]
|
||||
|
||||
//! [Pair frames]
|
||||
// Pair depth and color frames
|
||||
while (!isFinish)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mtx);
|
||||
while (!isFinish && (depthFrames.empty() || colorFrames.empty()))
|
||||
dataReady.wait(lk);
|
||||
|
||||
while (!depthFrames.empty() && !colorFrames.empty())
|
||||
{
|
||||
if (!lk.owns_lock())
|
||||
lk.lock();
|
||||
|
||||
// Get a frame from the list
|
||||
Frame depthFrame = depthFrames.front();
|
||||
int64 depthT = depthFrame.timestamp;
|
||||
|
||||
// Get a frame from the list
|
||||
Frame colorFrame = colorFrames.front();
|
||||
int64 colorT = colorFrame.timestamp;
|
||||
|
||||
// Half of frame period is a maximum time diff between frames
|
||||
const int64 maxTdiff = int64(1000000000 / (2 * colorStream.get(CAP_PROP_FPS)));
|
||||
if (depthT + maxTdiff < colorT)
|
||||
{
|
||||
depthFrames.pop_front();
|
||||
continue;
|
||||
}
|
||||
else if (colorT + maxTdiff < depthT)
|
||||
{
|
||||
colorFrames.pop_front();
|
||||
continue;
|
||||
}
|
||||
depthFrames.pop_front();
|
||||
colorFrames.pop_front();
|
||||
lk.unlock();
|
||||
|
||||
//! [Show frames]
|
||||
// Show depth frame
|
||||
Mat d8, dColor;
|
||||
depthFrame.frame.convertTo(d8, CV_8U, 255.0 / 2500);
|
||||
applyColorMap(d8, dColor, COLORMAP_OCEAN);
|
||||
imshow("Depth (colored)", dColor);
|
||||
|
||||
// Show color frame
|
||||
imshow("Color", colorFrame.frame);
|
||||
//! [Show frames]
|
||||
|
||||
// Exit on Esc key press
|
||||
int key = waitKey(1);
|
||||
if (key == 27) // ESC
|
||||
{
|
||||
isFinish = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//! [Pair frames]
|
||||
|
||||
dataReady.notify_one();
|
||||
depthReader.join();
|
||||
colorReader.join();
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,212 @@
|
||||
#include <iostream> // for standard I/O
|
||||
#include <string> // for strings
|
||||
#include <iomanip> // for controlling float print precision
|
||||
#include <sstream> // string to number conversion
|
||||
|
||||
#include <opencv2/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
|
||||
#include <opencv2/imgproc.hpp> // Gaussian Blur
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/highgui.hpp> // OpenCV window I/O
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
double getPSNR ( const Mat& I1, const Mat& I2);
|
||||
Scalar getMSSIM( const Mat& I1, const Mat& I2);
|
||||
|
||||
static void help()
|
||||
{
|
||||
cout
|
||||
<< "------------------------------------------------------------------------------" << endl
|
||||
<< "This program shows how to read a video file with OpenCV. In addition, it "
|
||||
<< "tests the similarity of two input videos first with PSNR, and for the frames "
|
||||
<< "below a PSNR trigger value, also with MSSIM." << endl
|
||||
<< "Usage:" << endl
|
||||
<< "./video-input-psnr-ssim <referenceVideo> <useCaseTestVideo> <PSNR_Trigger_Value> <Wait_Between_Frames> " << endl
|
||||
<< "--------------------------------------------------------------------------" << endl
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
help();
|
||||
|
||||
if (argc != 5)
|
||||
{
|
||||
cout << "Not enough parameters" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
stringstream conv;
|
||||
|
||||
const string sourceReference = argv[1], sourceCompareWith = argv[2];
|
||||
int psnrTriggerValue, delay;
|
||||
conv << argv[3] << endl << argv[4]; // put in the strings
|
||||
conv >> psnrTriggerValue >> delay; // take out the numbers
|
||||
|
||||
int frameNum = -1; // Frame counter
|
||||
|
||||
VideoCapture captRefrnc(sourceReference), captUndTst(sourceCompareWith);
|
||||
|
||||
if (!captRefrnc.isOpened())
|
||||
{
|
||||
cout << "Could not open reference " << sourceReference << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!captUndTst.isOpened())
|
||||
{
|
||||
cout << "Could not open case test " << sourceCompareWith << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Size refS = Size((int) captRefrnc.get(CAP_PROP_FRAME_WIDTH),
|
||||
(int) captRefrnc.get(CAP_PROP_FRAME_HEIGHT)),
|
||||
uTSi = Size((int) captUndTst.get(CAP_PROP_FRAME_WIDTH),
|
||||
(int) captUndTst.get(CAP_PROP_FRAME_HEIGHT));
|
||||
|
||||
if (refS != uTSi)
|
||||
{
|
||||
cout << "Inputs have different size!!! Closing." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char* WIN_UT = "Under Test";
|
||||
const char* WIN_RF = "Reference";
|
||||
|
||||
// Windows
|
||||
namedWindow(WIN_RF, WINDOW_AUTOSIZE);
|
||||
namedWindow(WIN_UT, WINDOW_AUTOSIZE);
|
||||
moveWindow(WIN_RF, 400 , 0); //750, 2 (bernat =0)
|
||||
moveWindow(WIN_UT, refS.width, 0); //1500, 2
|
||||
|
||||
cout << "Reference frame resolution: Width=" << refS.width << " Height=" << refS.height
|
||||
<< " of nr#: " << captRefrnc.get(CAP_PROP_FRAME_COUNT) << endl;
|
||||
|
||||
cout << "PSNR trigger value " << setiosflags(ios::fixed) << setprecision(3)
|
||||
<< psnrTriggerValue << endl;
|
||||
|
||||
Mat frameReference, frameUnderTest;
|
||||
double psnrV;
|
||||
Scalar mssimV;
|
||||
|
||||
for(;;) //Show the image captured in the window and repeat
|
||||
{
|
||||
captRefrnc >> frameReference;
|
||||
captUndTst >> frameUnderTest;
|
||||
|
||||
if (frameReference.empty() || frameUnderTest.empty())
|
||||
{
|
||||
cout << " < < < Game over! > > > ";
|
||||
break;
|
||||
}
|
||||
|
||||
++frameNum;
|
||||
cout << "Frame: " << frameNum << "# ";
|
||||
|
||||
///////////////////////////////// PSNR ////////////////////////////////////////////////////
|
||||
psnrV = getPSNR(frameReference,frameUnderTest);
|
||||
cout << setiosflags(ios::fixed) << setprecision(3) << psnrV << "dB";
|
||||
|
||||
//////////////////////////////////// MSSIM /////////////////////////////////////////////////
|
||||
if (psnrV < psnrTriggerValue && psnrV)
|
||||
{
|
||||
mssimV = getMSSIM(frameReference, frameUnderTest);
|
||||
|
||||
cout << " MSSIM: "
|
||||
<< " R " << setiosflags(ios::fixed) << setprecision(2) << mssimV.val[2] * 100 << "%"
|
||||
<< " G " << setiosflags(ios::fixed) << setprecision(2) << mssimV.val[1] * 100 << "%"
|
||||
<< " B " << setiosflags(ios::fixed) << setprecision(2) << mssimV.val[0] * 100 << "%";
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
|
||||
////////////////////////////////// Show Image /////////////////////////////////////////////
|
||||
imshow(WIN_RF, frameReference);
|
||||
imshow(WIN_UT, frameUnderTest);
|
||||
|
||||
char c = (char)waitKey(delay);
|
||||
if (c == 27) break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ![get-psnr]
|
||||
double getPSNR(const Mat& I1, const Mat& I2)
|
||||
{
|
||||
Mat s1;
|
||||
absdiff(I1, I2, s1); // |I1 - I2|
|
||||
s1.convertTo(s1, CV_32F); // cannot make a square on 8 bits
|
||||
s1 = s1.mul(s1); // |I1 - I2|^2
|
||||
|
||||
Scalar s = sum(s1); // sum elements per channel
|
||||
|
||||
double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels
|
||||
|
||||
if( sse <= 1e-10) // for small values return zero
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
double mse = sse / (double)(I1.channels() * I1.total());
|
||||
double psnr = 10.0 * log10((255 * 255) / mse);
|
||||
return psnr;
|
||||
}
|
||||
}
|
||||
// ![get-psnr]
|
||||
|
||||
// ![get-mssim]
|
||||
|
||||
Scalar getMSSIM( const Mat& i1, const Mat& i2)
|
||||
{
|
||||
const double C1 = 6.5025, C2 = 58.5225;
|
||||
/***************************** INITS **********************************/
|
||||
int d = CV_32F;
|
||||
|
||||
Mat I1, I2;
|
||||
i1.convertTo(I1, d); // cannot calculate on one byte large values
|
||||
i2.convertTo(I2, d);
|
||||
|
||||
Mat I2_2 = I2.mul(I2); // I2^2
|
||||
Mat I1_2 = I1.mul(I1); // I1^2
|
||||
Mat I1_I2 = I1.mul(I2); // I1 * I2
|
||||
|
||||
/*************************** END INITS **********************************/
|
||||
|
||||
Mat mu1, mu2; // PRELIMINARY COMPUTING
|
||||
GaussianBlur(I1, mu1, Size(11, 11), 1.5);
|
||||
GaussianBlur(I2, mu2, Size(11, 11), 1.5);
|
||||
|
||||
Mat mu1_2 = mu1.mul(mu1);
|
||||
Mat mu2_2 = mu2.mul(mu2);
|
||||
Mat mu1_mu2 = mu1.mul(mu2);
|
||||
|
||||
Mat sigma1_2, sigma2_2, sigma12;
|
||||
|
||||
GaussianBlur(I1_2, sigma1_2, Size(11, 11), 1.5);
|
||||
sigma1_2 -= mu1_2;
|
||||
|
||||
GaussianBlur(I2_2, sigma2_2, Size(11, 11), 1.5);
|
||||
sigma2_2 -= mu2_2;
|
||||
|
||||
GaussianBlur(I1_I2, sigma12, Size(11, 11), 1.5);
|
||||
sigma12 -= mu1_mu2;
|
||||
|
||||
///////////////////////////////// FORMULA ////////////////////////////////
|
||||
Mat t1, t2, t3;
|
||||
|
||||
t1 = 2 * mu1_mu2 + C1;
|
||||
t2 = 2 * sigma12 + C2;
|
||||
t3 = t1.mul(t2); // t3 = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))
|
||||
|
||||
t1 = mu1_2 + mu2_2 + C1;
|
||||
t2 = sigma1_2 + sigma2_2 + C2;
|
||||
t1 = t1.mul(t2); // t1 =((mu1_2 + mu2_2 + C1).*(sigma1_2 + sigma2_2 + C2))
|
||||
|
||||
Mat ssim_map;
|
||||
divide(t3, t1, ssim_map); // ssim_map = t3./t1;
|
||||
|
||||
Scalar mssim = mean(ssim_map); // mssim = average of ssim map
|
||||
return mssim;
|
||||
}
|
||||
// ![get-mssim]
|
95
3rdparty/opencv-4.5.4/samples/cpp/tutorial_code/videoio/video-write/video-write.cpp
vendored
Normal file
95
3rdparty/opencv-4.5.4/samples/cpp/tutorial_code/videoio/video-write/video-write.cpp
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
#include <iostream> // for standard I/O
|
||||
#include <string> // for strings
|
||||
|
||||
#include <opencv2/core.hpp> // Basic OpenCV structures (cv::Mat)
|
||||
#include <opencv2/videoio.hpp> // Video write
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
static void help()
|
||||
{
|
||||
cout
|
||||
<< "------------------------------------------------------------------------------" << endl
|
||||
<< "This program shows how to write video files." << endl
|
||||
<< "You can extract the R or G or B color channel of the input video." << endl
|
||||
<< "Usage:" << endl
|
||||
<< "./video-write <input_video_name> [ R | G | B] [Y | N]" << endl
|
||||
<< "------------------------------------------------------------------------------" << endl
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
help();
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
cout << "Not enough parameters" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const string source = argv[1]; // the source file name
|
||||
const bool askOutputType = argv[3][0] =='Y'; // If false it will use the inputs codec type
|
||||
|
||||
VideoCapture inputVideo(source); // Open input
|
||||
if (!inputVideo.isOpened())
|
||||
{
|
||||
cout << "Could not open the input video: " << source << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
string::size_type pAt = source.find_last_of('.'); // Find extension point
|
||||
const string NAME = source.substr(0, pAt) + argv[2][0] + ".avi"; // Form the new name with container
|
||||
int ex = static_cast<int>(inputVideo.get(CAP_PROP_FOURCC)); // Get Codec Type- Int form
|
||||
|
||||
// Transform from int to char via Bitwise operators
|
||||
char EXT[] = {(char)(ex & 0XFF) , (char)((ex & 0XFF00) >> 8),(char)((ex & 0XFF0000) >> 16),(char)((ex & 0XFF000000) >> 24), 0};
|
||||
|
||||
Size S = Size((int) inputVideo.get(CAP_PROP_FRAME_WIDTH), // Acquire input size
|
||||
(int) inputVideo.get(CAP_PROP_FRAME_HEIGHT));
|
||||
|
||||
VideoWriter outputVideo; // Open the output
|
||||
if (askOutputType)
|
||||
outputVideo.open(NAME, ex=-1, inputVideo.get(CAP_PROP_FPS), S, true);
|
||||
else
|
||||
outputVideo.open(NAME, ex, inputVideo.get(CAP_PROP_FPS), S, true);
|
||||
|
||||
if (!outputVideo.isOpened())
|
||||
{
|
||||
cout << "Could not open the output video for write: " << source << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cout << "Input frame resolution: Width=" << S.width << " Height=" << S.height
|
||||
<< " of nr#: " << inputVideo.get(CAP_PROP_FRAME_COUNT) << endl;
|
||||
cout << "Input codec type: " << EXT << endl;
|
||||
|
||||
int channel = 2; // Select the channel to save
|
||||
switch(argv[2][0])
|
||||
{
|
||||
case 'R' : channel = 2; break;
|
||||
case 'G' : channel = 1; break;
|
||||
case 'B' : channel = 0; break;
|
||||
}
|
||||
Mat src, res;
|
||||
vector<Mat> spl;
|
||||
|
||||
for(;;) //Show the image captured in the window and repeat
|
||||
{
|
||||
inputVideo >> src; // read
|
||||
if (src.empty()) break; // check if at end
|
||||
|
||||
split(src, spl); // process - extract only the correct channel
|
||||
for (int i =0; i < 3; ++i)
|
||||
if (i != channel)
|
||||
spl[i] = Mat::zeros(S, spl[0].type());
|
||||
merge(spl, res);
|
||||
|
||||
//outputVideo.write(res); //save or
|
||||
outputVideo << res;
|
||||
}
|
||||
|
||||
cout << "Finished writing" << endl;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user