Profile found (find contour)
Profile found is to find an object's outline basic image edge extraction based methods.
Therefore, the threshold value of the selected edge extraction will affect the final outline findings
// find the profile cv :: findContours ( BINIMG InputOutputArray, // the input image, the pixel is regarded as non-zero pixel values remain unchanged 1,0, 'bit. 8- OutputArrayOfArrays Contours, // entire contour of the object found outputArray, hierachy // view of the topology, can be selected, the profile discovery algorithm is the image topology implementation. int MODE, // Contour mode int Method, // discovery method Point Point offset = () // displacement contour pixel, the default (0, 0) no displacement ) // Draw the outline drawContours ( BINIMG InputOutputArray, // output image OutputArrayOfArrays Contours, // entire contour of the object found Int contourIdx // contour index const the Scalar & Color, // when rendering color int Thickness, // draw a line width int lineType, // the type of line LINE_8 InputArray Hierarchy, // topology int maxLevel, // maximum number of layers, the current drawn 0, 1 represents a drawing and drawing current contour embedded Point Point offset = () // contour displacement, optionally }
Mat src, dst; int threshold_value = 100; int threshold_max = 255; RNG rng; void Demo_Contours(int, void*); int main(int argc, char** argv) { src = imread(STRPAHT); if (src.empty()) { printf("could not load image...\n"); return -1; } cvtColor(src, src, CV_BGR2GRAY); createTrackbar("Threshold Value:", "findcontours - demo", &threshold_value, threshold_max, Demo_Contours); Demo_Contours(0, 0); waitKey(0); return 0; } void Demo_Contours(int, void*) { Mat canny_output; vector<vector<Point>> contours; vector<Vec4i> hierachy; Canny(src, canny_output, threshold_value, threshold_value * 2, 3, false);
//发现 findContours(canny_output, contours, hierachy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0)); dst = Mat::zeros(src.size(), CV_8UC3); RNG rng(12345); for (size_t i = 0; i < contours.size(); i++) { Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
//绘制 drawContours(dst, contours, i, color, 2, 8, hierachy, 0, Point(0, 0)); } imshow("output_win", dst); }