OpenCV 4.12.0
开源计算机视觉
加载中...
搜索中...
无匹配项
cv::ximgproc::FastLineDetector 类参考抽象类

实现 [158] 中描述的 FLD(快速直线检测器)算法的类。 更多...

#include <opencv2/ximgproc/fast_line_detector.hpp>

cv::ximgproc::FastLineDetector 的协作图

公共成员函数

virtual ~FastLineDetector ()
 
virtual void detect (InputArray image, OutputArray lines)=0
 在输入图像中查找直线。 这是上述图像算法的默认参数的输出。
 
virtual void drawSegments (InputOutputArray image, InputArray lines, bool draw_arrow=false, Scalar linecolor=Scalar(0, 0, 255), int linethickness=1)=0
 在给定图像上绘制线段。
 
- 从 cv::Algorithm 继承的公共成员函数
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 清除算法状态。
 
virtual bool empty () const
 如果 Algorithm 为空(例如,在最开始或读取失败后),则返回 true。
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 从文件存储中读取算法参数。
 
virtual void save (const String &filename) const
 
void write (const Ptr< FileStorage > &fs, const String &name=String()) const
 
virtual void write (FileStorage &fs) const
 将算法参数存储到文件存储中。
 
void write (FileStorage &fs, const String &name) const
 

附加的继承成员

- 从 cv::Algorithm 继承的静态公共成员函数
template<typename _Tp >
static Ptr< _Tpload (const String &filename, const String &objname=String())
 从文件中加载算法。
 
template<typename _Tp >
static Ptr< _TploadFromString (const String &strModel, const String &objname=String())
 从字符串加载算法。
 
template<typename _Tp >
static Ptr< _Tpread (const FileNode &fn)
 从文件节点读取算法。
 
- 从 cv::Algorithm 继承的保护成员函数
void writeFormat (FileStorage &fs) const
 

详细描述

实现 [158] 中描述的 FLD(快速直线检测器)算法的类。

#include <iostream>
using namespace std;
using namespace cv;
using namespace cv::ximgproc;
int main(int argc, char** argv)
{
string in;
CommandLineParser parser(argc, argv, "{@input|corridor.jpg|输入图像}{help h||显示帮助消息}");
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
in = samples::findFile(parser.get<string>("@input"));
Mat image = imread(in, IMREAD_GRAYSCALE);
if( image.empty() )
{
parser.printMessage();
return -1;
}
// 创建 FLD 检测器
// 参数 默认值 描述
// length_threshold 10 - 将丢弃比此值短的线段
// distance_threshold 1.41421356 - 从假设线放置的点
// 距离大于此值的线段将被视为异常值
// canny_th1 50 - Canny() 中迟滞过程的第一个阈值
// canny_th2 50 - Canny() 中迟滞过程的第二个阈值
// canny_aperture_size 3 - Canny() 中 sobel 算子的 Aperturesize。
// 如果为零,则不应用 Canny(),并且输入图像被视为边缘图像。
// canny_aperture_size 3 - Canny() 中 sobel 算子的 Aperturesize。
// do_merge false - 如果为 true,将执行线段的增量合并
// 将被执行
int length_threshold = 10;
float distance_threshold = 1.41421356f;
double canny_th1 = 50.0;
double canny_th2 = 50.0;
int canny_aperture_size = 3;
bool do_merge = false;
Ptr<FastLineDetector> fld = createFastLineDetector(length_threshold,
distance_threshold, canny_th1, canny_th2, canny_aperture_size,
do_merge);
vector<Vec4f> lines;
// 由于某些 CPU 的电源策略,似乎算法的第一次运行需要更长的时间。
// 因此,我们在此处运行该算法 5 次,以查看算法在充分预热后的处理时间
// CPU 性能。
for (int run_count = 0; run_count < 5; run_count++) {
double freq = getTickFrequency();
lines.clear();
int64 start = getTickCount();
// 使用 FLD 检测直线
fld->detect(image, lines);
double duration_ms = double(getTickCount() - start) * 1000 / freq;
cout << "FLD 经过的时间 " << duration_ms << " 毫秒。" << endl;
// 使用 FLD 显示找到的直线
Mat line_image_fld(image);
fld->drawSegments(line_image_fld, lines);
imshow("FLD 结果", line_image_fld);
}
waitKey();
cv::CommandLineParser
专为命令行解析而设计。
定义 utility.hpp:890
cv::Mat::empty
return 0;
}
如果数组没有元素,则返回 true。
int64_t int64
n 维密集数组类
定义 mat.hpp:830
cv::getTickFrequency
double getTickFrequency()
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
cv::getTickCount
int64 getTickCount()
ximgproc.hpp
返回时钟周期数。
◆ ~FastLineDetector()
从文件加载图像。
int main(int argc, char *argv[])
定义 highgui_qt.cpp:3
定义 core.hpp:107
STL 命名空间。
◆ detect()

构造函数 & 析构函数文档

virtual void cv::ximgproc::FastLineDetector::detect

cv.ximgproc.FastLineDetector.detect( ( )
image[, lines]

成员函数文档

灰度 (CV_8UC1) 输入图像。 如果只需要选择一个 roi,请使用: fld_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);

一个 Vec4f 元素的向量,用于指定直线的起点和终点。 其中 Vec4f 是 (x1, y1, x2, y2),点 1 是起点,点 2 是终点。 返回的直线是有方向的,因此较亮的一侧在其左侧。 ( InputArray image,
OutputArray lines )
纯虚函数
Python
◆ drawSegments()virtual void cv::ximgproc::FastLineDetector::drawSegments) -> 输出向量,包含与另一图像中点对应的对极线。每条线\(ax + by + c=0\)由3个数字\((a, b, c)\)编码。

在输入图像中查找直线。 这是上述图像算法的默认参数的输出。

image
参数
imagedraw_arrow = false,
输出向量,包含与另一图像中点对应的对极线。每条线\(ax + by + c=0\)由3个数字\((a, b, c)\)编码。linecolor = Scalar(0, 0, 255),

linethickness = 1 )

cv.ximgproc.FastLineDetector.drawSegments( ( InputOutputArray image,
InputArray 输出向量,包含与另一图像中点对应的对极线。每条线\(ax + by + c=0\)由3个数字\((a, b, c)\)编码。,
bool image, lines[, draw_arrow[, linecolor[, linethickness]]]
Scalar 将在其上绘制直线的图像。 应该大于或等于找到直线的图像。
int 需要绘制的直线的向量。
纯虚函数
Python
draw_arrow如果为 true,则将绘制箭头。) -> image

在给定图像上绘制线段。

参数
imagelinecolor
输出向量,包含与另一图像中点对应的对极线。每条线\(ax + by + c=0\)由3个数字\((a, b, c)\)编码。线条颜色。
linethickness线条粗细。
此类文档由以下文件生成opencv2/ximgproc/fast_line_detector.hpp
在 2025 年 7 月 3 日星期四 12:14:40 为 OpenCV 生成,作者是 doxygen 1.12.0线条粗细。

此类文档由以下文件生成