Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing 'objdetect.CascadeClassifier.read' #1376

Merged
merged 1 commit into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace OpenCvSharp.Internal
{
static partial class NativeMethods
{
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus objdetect_CascadeClassifier_read(IntPtr obj, IntPtr fn, out int returnValue);

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus objdetect_CascadeClassifier_new(out IntPtr returnValue);

Expand Down
19 changes: 19 additions & 0 deletions src/OpenCvSharp/Modules/objdetect/CascadeClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ public bool Load(string fileName)
return ret != 0;
}

/// <summary>
/// Reads a classifier parameters from a file storage
/// </summary>
/// <param name="fn"></param>
public virtual bool Read(FileNode fn)
{
if (ptr == IntPtr.Zero)
throw new ObjectDisposedException(GetType().Name);
if (fn == null)
throw new ArgumentNullException(nameof(fn));

NativeMethods.HandleException(
NativeMethods.objdetect_CascadeClassifier_read(ptr, fn.CvPtr, out var ret));
GC.KeepAlive(this);
GC.KeepAlive(fn);

return ret != 0;
}

/// <summary>
/// Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/OpenCvSharpExtern/objdetect.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ CVAPI(ExceptionStatus) objdetect_CascadeClassifier_load(
END_WRAP
}

CVAPI(ExceptionStatus) objdetect_CascadeClassifier_read(
cv::CascadeClassifier* obj, cv::FileNode* fn, int* returnValue)
{
BEGIN_WRAP
* returnValue = obj->read(*fn) ? 1 : 0;
END_WRAP
}

CVAPI(ExceptionStatus) objdetect_CascadeClassifier_detectMultiScale1(
cv::CascadeClassifier *obj,
cv::Mat *image, std::vector<cv::Rect> *objects,
Expand Down