Updated sample files documentation inclusions

This commit is contained in:
Maksim Shabunin
2014-12-26 14:35:46 +03:00
parent ec9a17e71a
commit b4050c775e
28 changed files with 171 additions and 183 deletions

View File

@@ -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]

View File

@@ -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!

View File

@@ -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;
}