Update documentation

This commit is contained in:
Suleyman TURKMEN
2017-12-31 14:13:13 +03:00
parent 71f4281080
commit dcd4f8f5db
8 changed files with 452 additions and 401 deletions
@@ -23,8 +23,8 @@ int main()
Mat m = (Mat_<uchar>(3,2) << 1,2,3,4,5,6);
Mat col_sum, row_sum;
reduce(m, col_sum, 0, CV_REDUCE_SUM, CV_32F);
reduce(m, row_sum, 1, CV_REDUCE_SUM, CV_32F);
reduce(m, col_sum, 0, REDUCE_SUM, CV_32F);
reduce(m, row_sum, 1, REDUCE_SUM, CV_32F);
/*
m =
[ 1, 2;
@@ -40,22 +40,22 @@ int main()
//! [example]
Mat col_average, row_average, col_min, col_max, row_min, row_max;
reduce(m, col_average, 0, CV_REDUCE_AVG, CV_32F);
reduce(m, col_average, 0, REDUCE_AVG, CV_32F);
cout << "col_average =\n" << col_average << endl;
reduce(m, row_average, 1, CV_REDUCE_AVG, CV_32F);
reduce(m, row_average, 1, REDUCE_AVG, CV_32F);
cout << "row_average =\n" << row_average << endl;
reduce(m, col_min, 0, CV_REDUCE_MIN, CV_8U);
reduce(m, col_min, 0, REDUCE_MIN, CV_8U);
cout << "col_min =\n" << col_min << endl;
reduce(m, row_min, 1, CV_REDUCE_MIN, CV_8U);
reduce(m, row_min, 1, REDUCE_MIN, CV_8U);
cout << "row_min =\n" << row_min << endl;
reduce(m, col_max, 0, CV_REDUCE_MAX, CV_8U);
reduce(m, col_max, 0, REDUCE_MAX, CV_8U);
cout << "col_max =\n" << col_max << endl;
reduce(m, row_max, 1, CV_REDUCE_MAX, CV_8U);
reduce(m, row_max, 1, REDUCE_MAX, CV_8U);
cout << "row_max =\n" << row_max << endl;
/*
@@ -86,7 +86,7 @@ int main()
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, CV_REDUCE_SUM, CV_32F);
reduce(m, col_sum_per_channel, 0, REDUCE_SUM, CV_32F);
/*
col_sum_per_channel =
[9, 12]
@@ -0,0 +1,53 @@
#include <opencv2/opencv.hpp>
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]
return 0;
}
@@ -0,0 +1,45 @@
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
static void createAlphaMat(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()
{
// Create mat with alpha channel
Mat mat(480, 640, CV_8UC4);
createAlphaMat(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");
return result ? 0 : 1;
}