Skip to content

Commit 66690b1

Browse files
committed
Expose FaceDetectorYN.SetInputSize
1 parent eb41039 commit 66690b1

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/OpenCvSharp/Internal/PInvoke/NativeMethods/objdetect/NativeMethods_objdetect_FaceDetectorYN.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public static partial ExceptionStatus objdetect_FaceDetectorYN_create(
2828
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
2929
public static partial ExceptionStatus objdetect_Ptr_FaceDetectorYN_get(IntPtr ptr, out IntPtr returnValue);
3030

31+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
32+
internal static partial ExceptionStatus objdetect_FaceDetectorYN_setInputSize(
33+
OpenCvSafeHandle obj, Size inputSize);
34+
3135
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
3236
internal static partial ExceptionStatus objdetect_FaceDetectorYN_detect(
3337
OpenCvSafeHandle obj, in InputArrayProxy image, in OutputArrayProxy faces, out int returnValue);

src/OpenCvSharp/Modules/objdetect/FaceDetectorYN.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ public static FaceDetectorYN Create(
5656
return new FaceDetectorYN(smartPtr, rawPtr);
5757
}
5858

59+
/// <summary>
60+
/// Sets the network input size, overwriting the size specified when the detector was created.
61+
/// </summary>
62+
/// <param name="inputSize">The size of the input image.</param>
63+
public void SetInputSize(Size inputSize)
64+
{
65+
ThrowIfDisposed();
66+
NativeMethods.HandleException(
67+
NativeMethods.objdetect_FaceDetectorYN_setInputSize(Handle, inputSize));
68+
}
69+
70+
/// <summary>
71+
/// Sets the network input size, overwriting the size specified when the detector was created.
72+
/// </summary>
73+
/// <param name="width">The input image width.</param>
74+
/// <param name="height">The input image height.</param>
75+
public void SetInputSize(int width, int height) => SetInputSize(new Size(width, height));
76+
5977
/// <summary>
6078
/// A simple interface to detect face from given image.
6179
/// </summary>

src/OpenCvSharpExtern/objdetect_FaceDetectorYN.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ CVAPI(ExceptionStatus) objdetect_Ptr_FaceDetectorYN_get(cv::Ptr<cv::FaceDetector
4646
});
4747
}
4848

49+
CVAPI(ExceptionStatus) objdetect_FaceDetectorYN_setInputSize(
50+
cv::FaceDetectorYN* obj,
51+
const interop::Size inputSize)
52+
{
53+
return cvTry([&] {
54+
obj->setInputSize(cpp(inputSize));
55+
});
56+
}
57+
4958
CVAPI(ExceptionStatus) objdetect_FaceDetectorYN_detect(
5059
cv::FaceDetectorYN* obj,
5160
const interop::InputArrayProxy* image,

test/OpenCvSharp.Tests/objdetect/FaceDetectorYNTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ public void CreateWithParameters()
4949
Assert.NotNull(detector);
5050
}
5151

52+
[Fact]
53+
public void SetInputSize()
54+
{
55+
using var image = LoadImage("lenna.png");
56+
using var detector = FaceDetectorYN.Create(
57+
ModelPath,
58+
config: "",
59+
inputSize: new Size(320, 320));
60+
61+
detector.SetInputSize(image.Width, image.Height);
62+
63+
using var faces = new Mat();
64+
Assert.Equal(1, detector.Detect(image, faces));
65+
Assert.False(faces.Empty());
66+
}
67+
5268
[Fact]
5369
public void DisposeTwice()
5470
{

0 commit comments

Comments
 (0)