Skip to content

Commit 939d5fe

Browse files
authored
Merge pull request #1877 from shimat/claude/competent-shannon-5acdac
Fix LineSegmentDetector segfault caused by C++/C# calling convention mismatch
2 parents d721631 + 75b4baa commit 939d5fe

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/OpenCvSharpExtern/imgproc_LineSegmentDetector.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ CVAPI(cv::Ptr<cv::LineSegmentDetector>*) imgproc_createLineSegmentDetector(
3838
refine, scale, sigma_scale, quant, ang_th, log_eps, density_th, n_bins));
3939
}
4040

41-
CVAPI(void) imgproc_Ptr_LineSegmentDetector_delete(cv::Ptr<cv::LineSegmentDetector> *obj)
41+
CVAPI(ExceptionStatus) imgproc_Ptr_LineSegmentDetector_delete(cv::Ptr<cv::LineSegmentDetector> *obj)
4242
{
43+
BEGIN_WRAP
4344
delete obj;
45+
END_WRAP
4446
}
4547

46-
CVAPI(cv::LineSegmentDetector*) imgproc_Ptr_LineSegmentDetector_get(cv::Ptr<cv::LineSegmentDetector> *obj)
48+
CVAPI(ExceptionStatus) imgproc_Ptr_LineSegmentDetector_get(cv::Ptr<cv::LineSegmentDetector> *obj, cv::LineSegmentDetector **returnValue)
4749
{
48-
return obj->get();
50+
BEGIN_WRAP
51+
*returnValue = obj->get();
52+
END_WRAP
4953
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Xunit;
2+
3+
namespace OpenCvSharp.Tests.ImgProc;
4+
5+
public class LineSegmentDetectorTest : TestBase
6+
{
7+
[Fact]
8+
public void CreateAndDetect()
9+
{
10+
using var image = new Mat(500, 500, MatType.CV_8UC1, Scalar.All(255));
11+
Cv2.Line(image, new Point(50, 50), new Point(450, 50), new Scalar(0, 0, 0), 2);
12+
13+
using var lsd = LineSegmentDetector.Create();
14+
Assert.NotEqual(IntPtr.Zero, lsd.RawPtr);
15+
16+
lsd.Detect(image, out var lines, out _, out _, out _);
17+
Assert.NotEmpty(lines);
18+
}
19+
20+
[Fact]
21+
public void DetectOutputArray()
22+
{
23+
using var image = new Mat(500, 500, MatType.CV_8UC1, Scalar.All(255));
24+
Cv2.Line(image, new Point(50, 50), new Point(450, 50), new Scalar(0, 0, 0), 2);
25+
26+
using var lsd = LineSegmentDetector.Create();
27+
using var lines = new Mat();
28+
lsd.Detect(image, lines);
29+
Assert.False(lines.Empty());
30+
}
31+
}

0 commit comments

Comments
 (0)