创建网站的成本,企业开发网站公司,网站备案号 信息,地推团队联系方式操作系统#xff1a;ubuntu22.04 OpenCV版本#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言#xff1a;C11
算法描述
在一组点中使用标准霍夫变换查找直线。 该函数使用霍夫变换的一种改进方法在一组点中查找直线。
HoughLinesPointSet 是 OpenCV 中的一个函数ubuntu22.04 OpenCV版本OpenCV4.9 IDE:Visual Studio Code 编程语言C11
算法描述
在一组点中使用标准霍夫变换查找直线。 该函数使用霍夫变换的一种改进方法在一组点中查找直线。
HoughLinesPointSet 是 OpenCV 中的一个函数用于从一组点中检测直线。这个函数特别适用于处理不连续的点集它可以检测这些点集中的直线。与 HoughLines 和 HoughLinesP 不同HoughLinesPointSet 专门设计用于处理点集而不是边缘图像。
函数原型 void cv::HoughLinesPointSet
(InputArray point,OutputArray lines,int lines_max,int threshold,double min_rho,double max_rho,double rho_step,double min_theta,double max_theta,double theta_step
)
参数 参数point: 输入的点向量。每个点必须编码为 Point 向量x, y。类型必须是 CV_32FC2 或 CV_32SC2。 参数lines: 输出的已找到的直线向量。每个向量编码为 Vec3d 向量votes, rho, theta。‘votes’ 的值越大霍夫直线的可靠性越高。 参数lines_max: 霍夫直线的最大数量。 参数threshold: 累加器的阈值参数。只有那些获得足够投票数threshold的直线才会被返回。 参数min_rho: 累加器中 ρ 的最小值注意ρ 可以是负数。绝对值 |ρ| 是直线到原点的距离。 参数max_rho: 累加器中 ρ 的最大值。 参数rho_step: 累加器的距离分辨率。 参数min_theta: 累加器中角度的最小值以弧度为单位。 参数max_theta: 累加器中角度的上限以弧度为单位。实际的最大角度可能稍微小于 max_theta具体取决于 min_theta 和 theta_step 参数。 参数theta_step: 累加器的角度分辨率以弧度为单位。
代码示例 #include opencv2/core.hpp
#include opencv2/imgproc.hpp
using namespace cv;
using namespace std;
int main()
{Mat lines;vector Vec3d line3d;vector Point2f point;const static float Points[ 20 ][ 2 ] { { 0.0f, 369.0f }, { 10.0f, 364.0f }, { 20.0f, 358.0f }, { 30.0f, 352.0f }, { 40.0f, 346.0f }, { 50.0f, 341.0f }, { 60.0f, 335.0f },{ 70.0f, 329.0f }, { 80.0f, 323.0f }, { 90.0f, 318.0f }, { 100.0f, 312.0f }, { 110.0f, 306.0f }, { 120.0f, 300.0f }, { 130.0f, 295.0f },{ 140.0f, 289.0f }, { 150.0f, 284.0f }, { 160.0f, 277.0f }, { 170.0f, 271.0f }, { 180.0f, 266.0f }, { 190.0f, 260.0f } };for ( int i 0; i 20; i ){point.push_back( Point2f( Points[ i ][ 0 ], Points[ i ][ 1 ] ) );}double rhoMin 0.0f, rhoMax 360.0f, rhoStep 1;double thetaMin 0.0f, thetaMax CV_PI / 2.0f, thetaStep CV_PI / 180.0f;HoughLinesPointSet( point, lines, 20, 1, rhoMin, rhoMax, rhoStep, thetaMin, thetaMax, thetaStep );lines.copyTo( line3d );printf( votes投票数:%d, rho距离:%.7f, theta角度:%.7f\n, ( int )line3d.at( 0 ).val[ 0 ], line3d.at( 0 ).val[ 1 ], line3d.at( 0 ).val[ 2 ] );
}运行结果
votes投票数:19, rho距离:320.0000000, theta角度:1.0471976