I am trying to perform line detection, using OpenCV, in order to select rows of vegetation in satellite imagery.
I decided to use OpenCV LineSegmentDetector since it seemed to provide just what I need in a single code line, as opposed to using Hough Transform or other more complex methods that require some additional work and preprocessing.
However, I am unable to make it work even in the simplest example.
My code:
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);
in the 4th line:
lsd->detect(coco, lines_std)
I get either an AccessViolationException or a NullPointerException no matter what i try (different types in the OutputArray, using a cv::Mat as output, etc). The code is almost exactly the same as here: https://docs.opencv.org/4.6.0/df/dfa/tutorial_line_descriptor_main.html (probably with an older version since I do not have the "KeyLine" type defined)
I am aware this feature was removed in prior OpenCV versions due to licensing issues, as can be seen in the official docs:
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.
...but since I am using OpenCV 4.6.0 i suspect that is not the issue.
I have configured a fresh project in Visual Studio 2022 for this test, and I am familiar with the usual OpenCV things (add include folders, static and dynamic libs in linker, etc.). Other operations on Mats work just fine.
What am I missing?