用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);
}
}
我想要得到角度.之后根据这个角度对图像进行旋转.
程序如下:
#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);
}
}
我想要得到角度.之后根据这个角度对图像进行旋转.
你的图是怎样的?
cvHoughLines2能得到多个直线段,你要的到哪个角度啊?
cvHoughLines2能得到多个直线段,你要的到哪个角度啊?
简单的matlab手势识别中,用hough变换检测出直线条数,然后如何判断有几类直线也就是手指数目?
如何用openCV进行坐标变换
求hough变换问题如何利用hough变换求解变换后的图形的特性,比如圆形经过摄像投影变成椭圆,如何求出圆心在变换后的坐
作者很擅长描写景物,试根据课文填空,并体会作者是怎样变换角度来描写景物的
得到y=sin2x的图像,需要将函数y=sin^2x的图像进行怎样的变换?
求解opencv怎么画旋转一定角度的矩形呢?
得到二维otsu法的阈值(二元组)后怎样做图像分割?怎么在opencv中实现?
为什么要进行傅立叶变换,变换后得到的函数究竟是什么?
给定一个点坐标,和一个角度(即斜率),如何在一幅图上画出这条直线?用opencv或C实现
opencv 给出图上两点的坐标,在这张图上画直线
opencv做目标跟踪的时候,怎样把目标用矩形圈出来
摄像机标定之后的参数怎么载入摄像机,我是用opencv控制的摄像头进行拍照的