2个回答
展开全部
int main()
{
IplImage* src;
src=cvLoadImage("D:\\image\\line.jpg");
{
IplImage* dst = cvCreateImage( cvGetSize(src), 8, 1 );
IplImage* color_dst = cvCreateImage( cvGetSize(src), 8, 3 );
CvMemStorage* storage = cvCreateMemStorage(0);//存储检测到线段,当然可以是N*1的矩阵数列,如果实际的直线数量多余N,那么最大可能数目的线段被返回
CvSeq* lines = 0;
int i;
IplImage* src1=cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,1);
cvCvtColor(src, src1, CV_BGR2GRAY); //把src转换成灰度图像保存在src1中,注意进行边缘检测一定要换成灰度图
cvCanny( src1, dst, 50, 200, 3 );//参数50,200的灰度变换
cvCvtColor( dst, color_dst, CV_GRAY2BGR );
lines = cvHoughLines2( dst, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 80, 30, 10 );
for( i = 0; i < lines->total; i++ )
{
CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
cvLine( color_dst, line[0], line[1], CV_RGB(255,255,0), 3, 8 );
double k=(double)(line[1].y-line[0].y)/(double)(line[1].x-line[0].x);
double d=line[0].y-line[0].x*k;
printf("This is the %d line, this line is y = %.2f x + %.2f \n",i+1,k,d);
}
cvNamedWindow( "Source", 1 );
cvShowImage( "Source", src );
cvNamedWindow( "Hough", 1 );
cvShowImage( "Hough", color_dst );
cvWaitKey(0);
}
}
{
IplImage* src;
src=cvLoadImage("D:\\image\\line.jpg");
{
IplImage* dst = cvCreateImage( cvGetSize(src), 8, 1 );
IplImage* color_dst = cvCreateImage( cvGetSize(src), 8, 3 );
CvMemStorage* storage = cvCreateMemStorage(0);//存储检测到线段,当然可以是N*1的矩阵数列,如果实际的直线数量多余N,那么最大可能数目的线段被返回
CvSeq* lines = 0;
int i;
IplImage* src1=cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,1);
cvCvtColor(src, src1, CV_BGR2GRAY); //把src转换成灰度图像保存在src1中,注意进行边缘检测一定要换成灰度图
cvCanny( src1, dst, 50, 200, 3 );//参数50,200的灰度变换
cvCvtColor( dst, color_dst, CV_GRAY2BGR );
lines = cvHoughLines2( dst, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 80, 30, 10 );
for( i = 0; i < lines->total; i++ )
{
CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
cvLine( color_dst, line[0], line[1], CV_RGB(255,255,0), 3, 8 );
double k=(double)(line[1].y-line[0].y)/(double)(line[1].x-line[0].x);
double d=line[0].y-line[0].x*k;
printf("This is the %d line, this line is y = %.2f x + %.2f \n",i+1,k,d);
}
cvNamedWindow( "Source", 1 );
cvShowImage( "Source", src );
cvNamedWindow( "Hough", 1 );
cvShowImage( "Hough", color_dst );
cvWaitKey(0);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
东莞大凡
2024-08-07 广告
2024-08-07 广告
OpenCV标定板是东莞市大凡光学科技有限公司在相机标定中常用的工具。它通常由黑白格点按一定规则排列在平面上组成,如棋盘格或圆形格等。在相机标定时,将标定板置于不同位置和姿态下拍摄图像,利用OpenCV库中的函数检测标定板上的角点或圆心,进...
点击进入详情页
本回答由东莞大凡提供
展开全部
采纳后请留意百度HI
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询