简单的理解就是首先对纯粹的直线(确实是一条直线,没有断点),根据参数maxLineGap进行连接,然后在对是否满足参数threshold和minLineLength进行判断,最后返回直线。
实例
#include "stdafx.h" #include <cv.h> #include <highgui.h> #include <math.h> using namespace cv; int main(int argc, char** argv) { Mat src, dst, color_dst; src=imread("F:\\pic\\linecjc1.jpg", 0); Canny( src, dst, 50, 200, 3 ); cvtColor( dst, color_dst, CV_GRAY2BGR ); vector<Vec4i> lines; HoughLinesP( dst, lines, 1, CV_PI/180, 10, 10, 0); for( size_t i = 0; i < lines.size(); i++ ) { line( color_dst, Point(lines[i][0], lines[i][1]), Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 1, 8 ); } namedWindow( "Source", 1 ); imshow( "Source", src ); namedWindow( "Detected Lines", 1 ); imshow( "Detected Lines", color_dst ); waitKey(0); return 0; }
OpenCV HoughLinesP函数的使用
时间: 2024-10-09 20:42:26