求助各位大神,这个端点如何检测出来?

Doraemon____ 2018-02-02 06:16:04

如图我想检测左边的端点。这个图片很好的检测出来了,但是下图就很明显有错误。想请教各位大神有什么办法?
...全文
295 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2018-02-05
  • 打赏
  • 举报
回复
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
using namespace std;
using namespace cv;
Mat img,smallImg,gray,bw;
vector<Vec4i> hierarchy;
vector<vector<Point> > contours;
int threshval=180;
Rect r;
Rect brect,toprect;
int idx,n;
const static Scalar colors[15]={
	CV_RGB(  0,  0,128),
	CV_RGB(  0,128,  0),
	CV_RGB(  0,128,128),
	CV_RGB(128,  0,  0),
	CV_RGB(128,  0,128),
	CV_RGB(128,128,  0),
	CV_RGB(128,128,128),
	CV_RGB(160,160,160),
	CV_RGB(  0,  0,255),
	CV_RGB(  0,255,  0),
	CV_RGB(  0,255,255),
	CV_RGB(255,  0,  0),
	CV_RGB(255,  0,255),
	CV_RGB(255,255,  0),
	CV_RGB(255,255,255),
};
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(&tmp,	&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;
	r.width=img.cols*3/10;
	r.height=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.empty()&&!hierarchy.empty()) {
		idx=0;
		n=0;
		vector<Point> approx;
		for (;idx>=0;idx=hierarchy[idx][0]) {
			color=colors[idx%15];
			//          drawContours(smallImg,contours,idx,color,1,8,hierarchy);
			approxPolyDP(Mat(contours[idx]), approx, arcLength(Mat(contours[idx]), true)*0.01, true);
/*
			const Point* p = &approx[0];
			int m=(int)approx.size();
			polylines(smallImg, &p, &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<m;i++) circle(smallImg,Point(p[i].x,p[i].y),1,color);
*/			
			n++;
			if (1==n) {
				toprect=boundingRect(Mat(contours[idx]));
			} else {
				brect=boundingRect(Mat(contours[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(255,0,0));
	}
	//imshow("display",smallImg);
	imshow("display",img);
	waitKey(0);
	cvDestroyWindow("display");
	return 0;
}
Doraemon____ 2018-02-03
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
若有多个,取最上面那个?

感谢赵老师的回复,我就是想检测我标记为红色的端点。

试过SIFT,但是效果不理想,无法准确的得到这个特征点,所以,不知道该如何办了,诚心求助赵老师,希望能得到您的指点,给我一点思路,在此谢谢了。
赵4老师 2018-02-03
  • 打赏
  • 举报
回复
若有多个,取最上面那个?
Doraemon____ 2018-02-02
  • 打赏
  • 举报
回复
我是用的sift特征点检测
Doraemon____ 2018-02-02
  • 打赏
  • 举报
回复
我将下面图的原图给大家。是这样子的:
求助各位大神,在此谢谢了

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧