Updated sample files documentation inclusions
This commit is contained in:
@@ -47,6 +47,7 @@ int main( int argc, char* argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
//! [dividewith]
|
||||
int divideWith = 0; // convert our input string to number - C++ style
|
||||
stringstream s;
|
||||
s << argv[2];
|
||||
@@ -60,6 +61,7 @@ int main( int argc, char* argv[])
|
||||
uchar table[256];
|
||||
for (int i = 0; i < 256; ++i)
|
||||
table[i] = (uchar)(divideWith * (i/divideWith));
|
||||
//! [dividewith]
|
||||
|
||||
const int times = 100;
|
||||
double t;
|
||||
@@ -106,15 +108,19 @@ int main( int argc, char* argv[])
|
||||
cout << "Time of reducing with the on-the-fly address generation - at function (averaged for "
|
||||
<< times << " runs): " << t << " milliseconds."<< endl;
|
||||
|
||||
//! [table-init]
|
||||
Mat lookUpTable(1, 256, CV_8U);
|
||||
uchar* p = lookUpTable.ptr();
|
||||
for( int i = 0; i < 256; ++i)
|
||||
p[i] = table[i];
|
||||
//! [table-init]
|
||||
|
||||
t = (double)getTickCount();
|
||||
|
||||
for (int i = 0; i < times; ++i)
|
||||
//! [table-use]
|
||||
LUT(I, lookUpTable, J);
|
||||
//! [table-use]
|
||||
|
||||
t = 1000*((double)getTickCount() - t)/getTickFrequency();
|
||||
t /= times;
|
||||
@@ -124,6 +130,7 @@ int main( int argc, char* argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! [scan-c]
|
||||
Mat& ScanImageAndReduceC(Mat& I, const uchar* const table)
|
||||
{
|
||||
// accept only char type matrices
|
||||
@@ -152,7 +159,9 @@ Mat& ScanImageAndReduceC(Mat& I, const uchar* const table)
|
||||
}
|
||||
return I;
|
||||
}
|
||||
//! [scan-c]
|
||||
|
||||
//! [scan-iterator]
|
||||
Mat& ScanImageAndReduceIterator(Mat& I, const uchar* const table)
|
||||
{
|
||||
// accept only char type matrices
|
||||
@@ -182,7 +191,9 @@ Mat& ScanImageAndReduceIterator(Mat& I, const uchar* const table)
|
||||
|
||||
return I;
|
||||
}
|
||||
//! [scan-iterator]
|
||||
|
||||
//! [scan-random]
|
||||
Mat& ScanImageAndReduceRandomAccess(Mat& I, const uchar* const table)
|
||||
{
|
||||
// accept only char type matrices
|
||||
@@ -216,3 +227,4 @@ Mat& ScanImageAndReduceRandomAccess(Mat& I, const uchar* const table)
|
||||
|
||||
return I;
|
||||
}
|
||||
//! [scan-random]
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//! [head]
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
@@ -9,6 +10,7 @@
|
||||
|
||||
using namespace cv; // The new C++ interface API is inside this namespace. Import it.
|
||||
using namespace std;
|
||||
//! [head]
|
||||
|
||||
static void help( char* progName)
|
||||
{
|
||||
@@ -20,6 +22,7 @@ static void help( char* progName)
|
||||
<< progName << " [image-name Default: ../data/lena.jpg]" << endl << endl;
|
||||
}
|
||||
|
||||
//! [start]
|
||||
// comment out the define to use only the latest C++ API
|
||||
#define DEMO_MIXED_API_USE
|
||||
|
||||
@@ -49,15 +52,19 @@ int main( int argc, char** argv )
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
//! [start]
|
||||
|
||||
//! [new]
|
||||
// convert image to YUV color space. The output image will be created automatically.
|
||||
Mat I_YUV;
|
||||
cvtColor(I, I_YUV, COLOR_BGR2YCrCb);
|
||||
|
||||
vector<Mat> planes; // Use the STL's vector structure to store multiple Mat objects
|
||||
split(I_YUV, planes); // split the image into separate color planes (Y U V)
|
||||
//! [new]
|
||||
|
||||
#if 1 // change it to 0 if you want to see a blurred and noisy version of this processing
|
||||
//! [scanning]
|
||||
// Mat scanning
|
||||
// Method 1. process Y plane using an iterator
|
||||
MatIterator_<uchar> it = planes[0].begin<uchar>(), it_end = planes[0].end<uchar>();
|
||||
@@ -80,9 +87,11 @@ int main( int argc, char** argv )
|
||||
Vxy = saturate_cast<uchar>((Vxy-128)/2 + 128);
|
||||
}
|
||||
}
|
||||
//! [scanning]
|
||||
|
||||
#else
|
||||
|
||||
//! [noisy]
|
||||
Mat noisyI(I.size(), CV_8U); // Create a matrix of the specified size and type
|
||||
|
||||
// Fills the matrix with normally distributed random values (around number with deviation off).
|
||||
@@ -117,13 +126,14 @@ int main( int argc, char** argv )
|
||||
|
||||
// Mat::mul replaces cvMul(). Again, no temporary arrays are created in case of simple expressions.
|
||||
planes[0] = planes[0].mul(planes[0], 1./255);
|
||||
//! [noisy]
|
||||
#endif
|
||||
|
||||
|
||||
//! [end]
|
||||
merge(planes, I_YUV); // now merge the results back
|
||||
cvtColor(I_YUV, I, COLOR_YCrCb2BGR); // and produce the output RGB image
|
||||
|
||||
|
||||
namedWindow("image with grain", WINDOW_AUTOSIZE); // use this to create images
|
||||
|
||||
#ifdef DEMO_MIXED_API_USE
|
||||
@@ -133,6 +143,7 @@ int main( int argc, char** argv )
|
||||
#else
|
||||
imshow("image with grain", I); // the new MATLAB style function show
|
||||
#endif
|
||||
//! [end]
|
||||
waitKey();
|
||||
|
||||
// Tip: No memory freeing is required!
|
||||
|
@@ -24,62 +24,90 @@ int main(int,char**)
|
||||
{
|
||||
help();
|
||||
// create by using the constructor
|
||||
//! [constructor]
|
||||
Mat M(2,2, CV_8UC3, Scalar(0,0,255));
|
||||
cout << "M = " << endl << " " << M << endl << endl;
|
||||
//! [constructor]
|
||||
|
||||
// create by using the create function()
|
||||
//! [create]
|
||||
M.create(4,4, CV_8UC(2));
|
||||
cout << "M = "<< endl << " " << M << endl << endl;
|
||||
//! [create]
|
||||
|
||||
// create multidimensional matrices
|
||||
//! [init]
|
||||
int sz[3] = {2,2,2};
|
||||
Mat L(3,sz, CV_8UC(1), Scalar::all(0));
|
||||
//! [init]
|
||||
|
||||
// Cannot print via operator <<
|
||||
|
||||
// Create using MATLAB style eye, ones or zero matrix
|
||||
//! [matlab]
|
||||
Mat E = Mat::eye(4, 4, CV_64F);
|
||||
cout << "E = " << endl << " " << E << endl << endl;
|
||||
|
||||
Mat O = Mat::ones(2, 2, CV_32F);
|
||||
cout << "O = " << endl << " " << O << endl << endl;
|
||||
|
||||
Mat Z = Mat::zeros(3,3, CV_8UC1);
|
||||
cout << "Z = " << endl << " " << Z << endl << endl;
|
||||
//! [matlab]
|
||||
|
||||
// create a 3x3 double-precision identity matrix
|
||||
//! [comma]
|
||||
Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
|
||||
cout << "C = " << endl << " " << C << endl << endl;
|
||||
//! [comma]
|
||||
|
||||
//! [clone]
|
||||
Mat RowClone = C.row(1).clone();
|
||||
cout << "RowClone = " << endl << " " << RowClone << endl << endl;
|
||||
//! [clone]
|
||||
|
||||
// Fill a matrix with random values
|
||||
//! [random]
|
||||
Mat R = Mat(3, 2, CV_8UC3);
|
||||
randu(R, Scalar::all(0), Scalar::all(255));
|
||||
//! [random]
|
||||
|
||||
// Demonstrate the output formating options
|
||||
//! [out-default]
|
||||
cout << "R (default) = " << endl << R << endl << endl;
|
||||
//! [out-default]
|
||||
//! [out-python]
|
||||
cout << "R (python) = " << endl << format(R, Formatter::FMT_PYTHON) << endl << endl;
|
||||
//! [out-python]
|
||||
//! [out-numpy]
|
||||
cout << "R (numpy) = " << endl << format(R, Formatter::FMT_NUMPY ) << endl << endl;
|
||||
//! [out-numpy]
|
||||
//! [out-csv]
|
||||
cout << "R (csv) = " << endl << format(R, Formatter::FMT_CSV ) << endl << endl;
|
||||
//! [out-csv]
|
||||
//! [out-c]
|
||||
cout << "R (c) = " << endl << format(R, Formatter::FMT_C ) << endl << endl;
|
||||
//! [out-c]
|
||||
|
||||
//! [out-point2]
|
||||
Point2f P(5, 1);
|
||||
cout << "Point (2D) = " << P << endl << endl;
|
||||
//! [out-point2]
|
||||
|
||||
//! [out-point3]
|
||||
Point3f P3f(2, 6, 7);
|
||||
cout << "Point (3D) = " << P3f << endl << endl;
|
||||
//! [out-point3]
|
||||
|
||||
|
||||
//! [out-vector]
|
||||
vector<float> v;
|
||||
v.push_back( (float)CV_PI); v.push_back(2); v.push_back(3.01f);
|
||||
|
||||
cout << "Vector of floats via Mat = " << Mat(v) << endl << endl;
|
||||
//! [out-vector]
|
||||
|
||||
//! [out-vector-points]
|
||||
vector<Point2f> vPoints(20);
|
||||
for (size_t i = 0; i < vPoints.size(); ++i)
|
||||
vPoints[i] = Point2f((float)(i * 5), (float)(i % 7));
|
||||
|
||||
cout << "A vector of 2D Points = " << vPoints << endl << endl;
|
||||
//! [out-vector-points]
|
||||
return 0;
|
||||
}
|
||||
|
@@ -19,14 +19,17 @@ Scalar getMSSIM( const Mat& I1, const Mat& I2);
|
||||
double getPSNR_CUDA(const Mat& I1, const Mat& I2); // Basic CUDA versions
|
||||
Scalar getMSSIM_CUDA( const Mat& I1, const Mat& I2);
|
||||
|
||||
//! [psnr]
|
||||
struct BufferPSNR // Optimized CUDA versions
|
||||
{ // Data allocations are very expensive on CUDA. Use a buffer to solve: allocate once reuse later.
|
||||
cuda::GpuMat gI1, gI2, gs, t1,t2;
|
||||
|
||||
cuda::GpuMat buf;
|
||||
};
|
||||
//! [psnr]
|
||||
double getPSNR_CUDA_optimized(const Mat& I1, const Mat& I2, BufferPSNR& b);
|
||||
|
||||
//! [ssim]
|
||||
struct BufferMSSIM // Optimized CUDA versions
|
||||
{ // Data allocations are very expensive on CUDA. Use a buffer to solve: allocate once reuse later.
|
||||
cuda::GpuMat gI1, gI2, gs, t1,t2;
|
||||
@@ -44,6 +47,7 @@ struct BufferMSSIM // Optimized CUDA version
|
||||
|
||||
cuda::GpuMat buf;
|
||||
};
|
||||
//! [ssim]
|
||||
Scalar getMSSIM_CUDA_optimized( const Mat& i1, const Mat& i2, BufferMSSIM& b);
|
||||
|
||||
static void help()
|
||||
@@ -165,7 +169,7 @@ int main(int, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//! [getpsnr]
|
||||
double getPSNR(const Mat& I1, const Mat& I2)
|
||||
{
|
||||
Mat s1;
|
||||
@@ -186,9 +190,9 @@ double getPSNR(const Mat& I1, const Mat& I2)
|
||||
return psnr;
|
||||
}
|
||||
}
|
||||
//! [getpsnr]
|
||||
|
||||
|
||||
|
||||
//! [getpsnropt]
|
||||
double getPSNR_CUDA_optimized(const Mat& I1, const Mat& I2, BufferPSNR& b)
|
||||
{
|
||||
b.gI1.upload(I1);
|
||||
@@ -211,7 +215,9 @@ double getPSNR_CUDA_optimized(const Mat& I1, const Mat& I2, BufferPSNR& b)
|
||||
return psnr;
|
||||
}
|
||||
}
|
||||
//! [getpsnropt]
|
||||
|
||||
//! [getpsnrcuda]
|
||||
double getPSNR_CUDA(const Mat& I1, const Mat& I2)
|
||||
{
|
||||
cuda::GpuMat gI1, gI2, gs, t1,t2;
|
||||
@@ -237,7 +243,9 @@ double getPSNR_CUDA(const Mat& I1, const Mat& I2)
|
||||
return psnr;
|
||||
}
|
||||
}
|
||||
//! [getpsnrcuda]
|
||||
|
||||
//! [getssim]
|
||||
Scalar getMSSIM( const Mat& i1, const Mat& i2)
|
||||
{
|
||||
const double C1 = 6.5025, C2 = 58.5225;
|
||||
@@ -290,7 +298,9 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
|
||||
Scalar mssim = mean( ssim_map ); // mssim = average of ssim map
|
||||
return mssim;
|
||||
}
|
||||
//! [getssim]
|
||||
|
||||
//! [getssimcuda]
|
||||
Scalar getMSSIM_CUDA( const Mat& i1, const Mat& i2)
|
||||
{
|
||||
const float C1 = 6.5025f, C2 = 58.5225f;
|
||||
@@ -359,7 +369,9 @@ Scalar getMSSIM_CUDA( const Mat& i1, const Mat& i2)
|
||||
}
|
||||
return mssim;
|
||||
}
|
||||
//! [getssimcuda]
|
||||
|
||||
//! [getssimopt]
|
||||
Scalar getMSSIM_CUDA_optimized( const Mat& i1, const Mat& i2, BufferMSSIM& b)
|
||||
{
|
||||
const float C1 = 6.5025f, C2 = 58.5225f;
|
||||
@@ -430,3 +442,4 @@ Scalar getMSSIM_CUDA_optimized( const Mat& i1, const Mat& i2, BufferMSSIM& b)
|
||||
}
|
||||
return mssim;
|
||||
}
|
||||
//! [getssimopt]
|
||||
|
@@ -1,23 +1,35 @@
|
||||
//! [includes]
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
//! [includes]
|
||||
|
||||
//! [namespace]
|
||||
using namespace cv;
|
||||
//! [namespace]
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
//! [load]
|
||||
string imageName("../data/HappyFish.jpg"); // by default
|
||||
if( argc > 1)
|
||||
{
|
||||
imageName = argv[1];
|
||||
}
|
||||
//! [load]
|
||||
|
||||
//! [mat]
|
||||
Mat image;
|
||||
//! [mat]
|
||||
|
||||
//! [imread]
|
||||
image = imread(imageName.c_str(), IMREAD_COLOR); // Read the file
|
||||
//! [imread]
|
||||
|
||||
if( image.empty() ) // Check for invalid input
|
||||
{
|
||||
@@ -25,9 +37,16 @@ int main( int argc, char** argv )
|
||||
return -1;
|
||||
}
|
||||
|
||||
//! [window]
|
||||
namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
|
||||
imshow( "Display window", image ); // Show our image inside it.
|
||||
//! [window]
|
||||
|
||||
//! [imshow]
|
||||
imshow( "Display window", image ); // Show our image inside it.
|
||||
//! [imshow]
|
||||
|
||||
//! [wait]
|
||||
waitKey(0); // Wait for a keystroke in the window
|
||||
//! [wait]
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user