You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在C++中无法使用OpenCV的LineSegmentDetector问题求助

OpenCV LineSegmentDetector 运行异常问题排查

我尝试使用OpenCV进行直线检测,以提取卫星图像中的植被行。选择OpenCV的LineSegmentDetector是因为它操作简洁,不像霍夫变换那样需要额外预处理工作,但哪怕是最简单的示例代码也无法正常运行。

我的代码如下:

Mat coco = imread("C:/Users/XX/Images/cococo.png", IMREAD_GRAYSCALE);
cv::LineSegmentDetector* lsd = cv::createLineSegmentDetector();
std::vector<cv::Vec4f> lines_std;
lsd->detect(coco, lines_std);
lsd->drawSegments(coco, lines_std);

在第4行lsd->detect(coco, lines_std)处,无论我尝试更换OutputArray类型、改用cv::Mat作为输出等各种调整,都会触发AccessViolationException或NullPointerException。我的代码和官方文档几乎完全一致(可能因版本差异,我没有定义"KeyLine"类型)。

我了解该功能曾因许可问题在旧版OpenCV中被移除:

Implementation has been removed from OpenCV version 3.4.6 to 3.4.15 and version 4.1.0 to 4.5.3 due original code license conflict. restored again after Computation of a NFA code published under the MIT license.

但我使用的是OpenCV 4.6.0,所以应该不存在许可导致的功能缺失问题。我已经在Visual Studio 2022中创建了全新项目,熟悉OpenCV常规配置流程(添加包含目录、链接静态与动态库等),其他针对Mat的操作都能正常执行。请问我忽略了什么细节?

内容的提问来源于stack exchange,提问作者Igb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 05:40:22