Skip to content

Commit b545253

Browse files
committed
Add HoughLinesPointSet test
1 parent 641de5f commit b545253

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/OpenCvSharp/Modules/core/Mat/Mat.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3516,7 +3516,7 @@ private void CheckArgumentsForConvert<T>(Array data)
35163516
throw new OpenCvSharpException(
35173517
$"Provided data element number ({data.Length}) should be multiple of the Mat channels count ({t.Channels})");
35183518

3519-
if (acceptableTypes is not null && acceptableTypes.Length > 0)
3519+
if (acceptableTypes.Length > 0)
35203520
{
35213521
var isValidDepth = acceptableTypes.Any(type => type == t);
35223522
if (!isValidDepth)

test/OpenCvSharp.Tests/imgproc/ImgProcTest.cs

+56
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void BuildPyramidTest()
1515
Cv2.BuildPyramid(src, dst, 2);
1616
Assert.Equal(3, dst.Size);
1717
}
18+
1819
[Fact]
1920
public void MorphologyExDilate()
2021
{
@@ -689,6 +690,61 @@ public void HoughLinesP()
689690
}
690691
}
691692

693+
[Fact]
694+
public void HoughLinesPointSet()
695+
{
696+
Vec2f[] points =
697+
[
698+
new(0.0f, 369.0f),
699+
new(10.0f, 364.0f),
700+
new(20.0f, 358.0f),
701+
new(30.0f, 352.0f),
702+
new(40.0f, 346.0f),
703+
new(50.0f, 341.0f),
704+
new(60.0f, 335.0f),
705+
new(70.0f, 329.0f),
706+
new(80.0f, 323.0f),
707+
new(90.0f, 318.0f),
708+
new(100.0f, 312.0f),
709+
new(110.0f, 306.0f),
710+
new(120.0f, 300.0f),
711+
new(130.0f, 295.0f),
712+
new(140.0f, 289.0f),
713+
new(150.0f, 284.0f),
714+
new(160.0f, 277.0f),
715+
new(170.0f, 271.0f),
716+
new(180.0f, 266.0f),
717+
new(190.0f, 260.0f)
718+
];
719+
720+
const int
721+
linesMax = 20,
722+
threshold = 1;
723+
const double
724+
rhoMin = 0.0f,
725+
rhoMax = 360.0f,
726+
rhoStep = 1,
727+
thetaMin = 0.0f,
728+
thetaMax = Cv2.PI / 2.0f,
729+
thetaStep = Cv2.PI / 180.0f;
730+
731+
using var pointsMat = new Mat(points.Length, 1, MatType.CV_32FC2);
732+
pointsMat.SetArray(points);
733+
using var linesMat = new Mat();
734+
Cv2.HoughLinesPointSet(pointsMat, linesMat, linesMax, threshold, rhoMin, rhoMax, rhoStep, thetaMin, thetaMax, thetaStep);
735+
736+
Assert.False(linesMat.Empty());
737+
Assert.Equal(MatType.CV_64FC3, linesMat.Type());
738+
739+
Assert.True(linesMat.GetArray(out Vec3d[] lines));
740+
Assert.NotEmpty(lines);
741+
742+
var (votes, rho, theta) = lines[0];
743+
Assert.True(votes > 10);
744+
Assert.Equal(320, rho, 6);
745+
Assert.Equal(1.0471975803375244, theta, 6);
746+
}
747+
692748
[Fact]
693749
public void Integral()
694750
{

0 commit comments

Comments
 (0)