Home > Software engineering >  The extraction of image contour points
The extraction of image contour points

Time:09-20


Could you tell me how to extract the contour points, small white to solve, thank you

CodePudding user response:

@ 4 teachers, zhao

CodePudding user response:

It is best to opencv

CodePudding user response:

The contour, to extract the image is to use opencv, may refer to https://blog.csdn.net/sac761/article/details/52003513

CodePudding user response:

Fyi:
 # include "opencv2/highgui/highgui. HPP" 
# include "opencv2/imgproc/imgproc HPP"
# include "opencv2/imgproc/imgproc_c. H"
using namespace std;
Using the namespace CV;
Mat img, smallImg, gray, bw;
VectorVector Contours.
Int threshval=128;
The Rect r;
The Rect maxrect brect;
Int independence idx, n;
Const static Scalar colors [15]={
CV_RGB (0, 0128),
CV_RGB (0128, 0),
CV_RGB (0128128),
CV_RGB (128, 0, 0),
CV_RGB (128, 0128),
CV_RGB (128128, 0),
CV_RGB (128128128),
CV_RGB (160160160),
CV_RGB (0, 0255),
CV_RGB (0255, 0),
CV_RGB (0255255),
CV_RGB (255, 0, 0),
CV_RGB (255, 0255),
CV_RGB (255255, 0),
CV_RGB (255255255),
};
Scalar color;
Void gamma_correct (Mat& Img, Mat& DST, double gamma) {
Mat temp.
CvMat TMP.

Img. ConvertTo (temp, CV_32FC1, 1.0/255.0, 0.0);
TMP=temp;
CvPow (& amp; TMP, & amp; TMP, gamma);
Temp. ConvertTo (DST, CV_8UC1, 255.0, 0.0);
}
Int main () {
CvNamedWindow (" display ", 1);
Img=imread (" image. JPG ", 1);
R.x=img. Cols/10;
R.y=img. Rows/3;
Truly idth=img. Cols * 8/10;
R.h. eight=img. Rows * 2/3;
SmallImg=img (r);
CvtColor (smallImg, gray, CV_BGR2GRAY);
//medianBlur (gray, gray, 5);
EqualizeHist (gray, gray);
Gamma_correct (gray, gray, 4.0);
Imshow (" display ", gray);
WaitKey (0);

Bw=(gray> Threshval);
Imshow (" display ", bw);
WaitKey (0);

Mat Structure0=getStructuringElement (MORPH_RECT, Size (3, 3));
Erode (bw, bw, Structure0, Point (1, 1));
Mat Structure1=getStructuringElement (MORPH_RECT, Size (6, 6));
Dilate (bw, bw, Structure1, Point (1, 1));
Imshow (" display ", bw);
WaitKey (0);

FindContours (bw, contours, hierarchy, RETR_EXTERNAL CHAIN_APPROX_SIMPLE);
if (! Contours. The empty () & amp; & ! Hierarchy. The empty ()) {
Independence idx=0;
N=0;
Vector Approx.
For (; Idx>=0; Independence idx=hierarchy [independence idx] [0]) {
Color=colors [15] independence idx %;
//drawContours (smallImg, contours, independence idx, color, and 1, 8, hierarchy);
ApproxPolyDP (Mat (contours [independence idx]), approx, arcLength (Mat (contours [independence idx]), true) * 0.005, true);//0.005 will flash straightening coefficient
Const Point * p=& amp; Approx [0].
Int m=(int) approx. The size ();
Polylines (smallImg, & amp; P, & amp; M, 1, true, color);
Circle (smallImg, Point (p [0]. X, p [0]. Y), 3, color);
Circle (smallImg, Point (p [1]. X, p [1]. Y), 2, color);
For (int I=2; in++;
If (1==n) {
Maxrect=boundingRect (Mat (contours [independence idx]));
} else {
Brect=boundingRect (Mat (contours [independence idx]));
CvRect Mr (maxrect), br (brect);
Maxrect=cvMaxRect (& amp; Mr, & amp; Br);
}
}
Circle (smallImg, Point (maxrect. X + maxrect. Width/2, maxrect. Y + maxrect. Height/2), 2, CV_RGB (0, 255));
}
Imshow (" display ", smallImg);
WaitKey (0);
CvDestroyWindow (" display ");
return 0;
}

CodePudding user response:

Opencv findcontours function can output all coordinates points directly,

CodePudding user response:

reference 5 floor SCSJHKXX reply:
opencv findcontours function can output all coordinates points directly,

Have you got any specific code, I use this function to draw the outline, but do not know how the output coordinate points

CodePudding user response:

refer to 6th floor qq_37199787 response:
Quote: refer to the fifth floor SCSJHKXX reply:
opencv findcontours function can output all coordinates points directly,

Have you got any specific code, I use this function to draw the outline, but do not know how to coordinate point output


You don't find the contours of is an array, from the array X, Y can't take? .

CodePudding user response:

Do you find?
  • Related