Home > Software engineering >  Help you a great god, and how to detect the endpoint?
Help you a great god, and how to detect the endpoint?

Time:09-25


As shown in figure, I want to test the left endpoint detected this picture is very good, but there was an obvious mistake, below is want to consult everybody a great god what method?

CodePudding user response:

I will give below artwork to you, is like this:
Help you a great god, in this thank you

CodePudding user response:

I am using the sift feature point detecting

CodePudding user response:

If there are multiple, take the top that?

CodePudding user response:

reference zhao4zhong1 reply: 3/f
if there are multiple, take the top that?

Thanks to miss zhao's reply, I just want to test I marked in red the endpoint,

Tried to SIFT, but the effect is not ideal, can't accurately get the feature points, so, don't know how to do, sincerely help miss zhao, hope to get your advice, give me some ideas, in this thank you,

CodePudding user response:

 # 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=180;
The Rect r;
The Rect brect toprect;
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 (" TMP. PNG ", 1);
R.x=img. Cols/10;
R.y=img. Rows * 2/10;
Truly idth=img. Cols * 3/10;
R.h. eight=img. Rows * 6/10;
SmallImg=img (r);
CvtColor (smallImg, gray, CV_BGR2GRAY);
//medianBlur (gray, gray, 5);
EqualizeHist (gray, gray);
Gamma_correct (gray, gray, 10.0);
//imshow (" display ", gray);
//waitKey (0);

Bw=(gray> Threshval);
//imshow (" display ", bw);
//waitKey (0);

//Mat Structure1=getStructuringElement (MORPH_RECT, Size (3, 3));
//dilate (bw, bw, Structure1, Point (1, 1));
//Mat Structure0=getStructuringElement (MORPH_RECT, Size (3, 3));
//erode (bw, bw, Structure0, 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.01, true);
/*
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; i*/
N++;
If (1==n) {
Toprect=boundingRect (Mat (contours [independence idx]));
} else {
Brect=boundingRect (Mat (contours [independence idx]));
If (toprect. Y> Brect. Y) toprect=brect;
}
}
Circle (img, Point (img. Cols/10 + toprect. X, img. Rows * 2/10 + toprect. Y + toprect. Height - 2), 2, CV_RGB (0, 255));
}
//imshow (" display ", smallImg);
Imshow (" display ", img);
WaitKey (0);
CvDestroyWindow (" display ");
return 0;
}
  • Related