mirror of
https://github.com/opencv/opencv.git
synced 2026-07-25 21:33:04 +04:00
Update documentation
This commit is contained in:
@@ -73,15 +73,15 @@ int main()
|
||||
//! [bin]
|
||||
// Create binary image from source image
|
||||
Mat bw;
|
||||
cvtColor(src, bw, CV_BGR2GRAY);
|
||||
threshold(bw, bw, 40, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);
|
||||
cvtColor(src, bw, COLOR_BGR2GRAY);
|
||||
threshold(bw, bw, 40, 255, THRESH_BINARY | THRESH_OTSU);
|
||||
imshow("Binary Image", bw);
|
||||
//! [bin]
|
||||
|
||||
//! [dist]
|
||||
// Perform the distance transform algorithm
|
||||
Mat dist;
|
||||
distanceTransform(bw, dist, CV_DIST_L2, 3);
|
||||
distanceTransform(bw, dist, DIST_L2, 3);
|
||||
|
||||
// Normalize the distance image for range = {0.0, 1.0}
|
||||
// so we can visualize and threshold it
|
||||
@@ -92,7 +92,7 @@ int main()
|
||||
//! [peaks]
|
||||
// Threshold to obtain the peaks
|
||||
// This will be the markers for the foreground objects
|
||||
threshold(dist, dist, .4, 1., CV_THRESH_BINARY);
|
||||
threshold(dist, dist, .4, 1., THRESH_BINARY);
|
||||
|
||||
// Dilate a bit the dist image
|
||||
Mat kernel1 = Mat::ones(3, 3, CV_8UC1);
|
||||
@@ -108,7 +108,7 @@ int main()
|
||||
|
||||
// Find total markers
|
||||
vector<vector<Point> > contours;
|
||||
findContours(dist_8u, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
|
||||
findContours(dist_8u, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
|
||||
|
||||
// Create the marker image for the watershed algorithm
|
||||
Mat markers = Mat::zeros(dist.size(), CV_32SC1);
|
||||
@@ -165,4 +165,4 @@ int main()
|
||||
|
||||
waitKey(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user