作业帮 > 综合 > 作业

用opencv 进行hough 变换,怎样得到并输出直线的角度?

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/18 07:04:57
用opencv 进行hough 变换,怎样得到并输出直线的角度?
程序如下:
#include "cv.h"
#include "highgui.h"
#include
int main(int argc,char** argv)
{
IplImage* src;
//if( argc == 2 && (src=cvLoadImage(argv[1],0))!= 0)
if(src=cvLoadImage(argc > argv[1] :"c:\\TestImages\\pic1.png",0))
{
IplImage* dst = cvCreateImage( cvGetSize(src),8,1 );
IplImage* color_dst = cvCreateImage( cvGetSize(src),8,3 );
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* lines = 0;
int i;
cvCanny( src,dst,50,200,3 );
cvCvtColor( dst,color_dst,CV_GRAY2BGR );
#if 1
lines = cvHoughLines2( dst,storage,CV_HOUGH_STANDARD,1,CV_PI/180,150,0,0 );
for( i = 0; i < lines->total; i++ )
{
float* line = (float*)cvGetSeqElem(lines,i);
float rho = line[0];
float theta = line[1];
CvPoint pt1,pt2;
double a = cos(theta),b = sin(theta);
if( fabs(b) < 0.001 )
{
pt1.x = pt2.x = cvRound(rho);
pt1.y = 0;
pt2.y = color_dst->height;
}
else if( fabs(a) < 0.001 )
{
pt1.y = pt2.y = cvRound(rho);
pt1.x = 0;
pt2.x = color_dst->width;
}
else
{
pt1.x = 0;
pt1.y = cvRound(rho/b);
pt2.x = cvRound(rho/a);
pt2.y = 0;
}
cvLine( color_dst,pt1,pt2,CV_RGB(255,0,0),1,8 );
}
#endif
cvNamedWindow( "Source",1 );
cvShowImage( "Source",src );
cvNamedWindow( "Hough",1 );
cvShowImage( "Hough",color_dst );
cvWaitKey(0);
}
}
我想要得到角度.之后根据这个角度对图像进行旋转.
用opencv 进行hough 变换,怎样得到并输出直线的角度?
你的图是怎样的?
cvHoughLines2能得到多个直线段,你要的到哪个角度啊?