Skip to content

Commit

Permalink
Add HoughLinesPointSet test
Browse files Browse the repository at this point in the history
  • Loading branch information
shimat committed Dec 8, 2024
1 parent 641de5f commit b545253
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OpenCvSharp/Modules/core/Mat/Mat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3516,7 +3516,7 @@ private void CheckArgumentsForConvert<T>(Array data)
throw new OpenCvSharpException(
$"Provided data element number ({data.Length}) should be multiple of the Mat channels count ({t.Channels})");

if (acceptableTypes is not null && acceptableTypes.Length > 0)
if (acceptableTypes.Length > 0)
{
var isValidDepth = acceptableTypes.Any(type => type == t);
if (!isValidDepth)
Expand Down
56 changes: 56 additions & 0 deletions test/OpenCvSharp.Tests/imgproc/ImgProcTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void BuildPyramidTest()
Cv2.BuildPyramid(src, dst, 2);
Assert.Equal(3, dst.Size);
}

[Fact]
public void MorphologyExDilate()
{
Expand Down Expand Up @@ -689,6 +690,61 @@ public void HoughLinesP()
}
}

[Fact]
public void HoughLinesPointSet()
{
Vec2f[] points =
[
new(0.0f, 369.0f),
new(10.0f, 364.0f),
new(20.0f, 358.0f),
new(30.0f, 352.0f),
new(40.0f, 346.0f),
new(50.0f, 341.0f),
new(60.0f, 335.0f),
new(70.0f, 329.0f),
new(80.0f, 323.0f),
new(90.0f, 318.0f),
new(100.0f, 312.0f),
new(110.0f, 306.0f),
new(120.0f, 300.0f),
new(130.0f, 295.0f),
new(140.0f, 289.0f),
new(150.0f, 284.0f),
new(160.0f, 277.0f),
new(170.0f, 271.0f),
new(180.0f, 266.0f),
new(190.0f, 260.0f)
];

const int
linesMax = 20,
threshold = 1;
const double
rhoMin = 0.0f,
rhoMax = 360.0f,
rhoStep = 1,
thetaMin = 0.0f,
thetaMax = Cv2.PI / 2.0f,
thetaStep = Cv2.PI / 180.0f;

using var pointsMat = new Mat(points.Length, 1, MatType.CV_32FC2);
pointsMat.SetArray(points);
using var linesMat = new Mat();
Cv2.HoughLinesPointSet(pointsMat, linesMat, linesMax, threshold, rhoMin, rhoMax, rhoStep, thetaMin, thetaMax, thetaStep);

Assert.False(linesMat.Empty());
Assert.Equal(MatType.CV_64FC3, linesMat.Type());

Assert.True(linesMat.GetArray(out Vec3d[] lines));
Assert.NotEmpty(lines);

var (votes, rho, theta) = lines[0];
Assert.True(votes > 10);
Assert.Equal(320, rho, 6);
Assert.Equal(1.0471975803375244, theta, 6);
}

[Fact]
public void Integral()
{
Expand Down

0 comments on commit b545253

Please sign in to comment.