Browse Source

Added ComputeOrientation and EdgesNms to StructuredEdgeDetection class.

pull/84/merge
Canming Huang 7 years ago
parent
commit
3e7a3468c0
  1. 226
      Emgu.CV.Contrib/XImgproc/StructuredEdgeDetection.cs
  2. 10
      Emgu.CV.Extern/ximgproc/ximgproc_c.cpp
  3. 4
      Emgu.CV.Extern/ximgproc/ximgproc_c.h

226
Emgu.CV.Contrib/XImgproc/StructuredEdgeDetection.cs

@ -13,93 +13,141 @@ using Emgu.Util;
namespace Emgu.CV.XImgproc
{
/// <summary>
/// Class implementing edge detection algorithm from Piotr Dollár and C Lawrence Zitnick. Structured forests for fast edge detection. In Computer Vision (ICCV), 2013 IEEE International Conference on, pages 1841–1848. IEEE, 2013.
/// </summary>
public class StructuredEdgeDetection : UnmanagedObject
{
private IntPtr _sharedPtr;
/// <summary>
/// Create an edge detection algorithm.
/// </summary>
/// <param name="model">name of the file where the model is stored</param>
/// <param name="howToGetFeatures">optional object inheriting from RFFeatureGetter. You need it only if you would like to train your own forest, pass NULL otherwise</param>
public StructuredEdgeDetection(String model, RFFeatureGetter howToGetFeatures)
{
using (CvString sModel = new CvString(model))
_ptr = XImgprocInvoke.cveStructuredEdgeDetectionCreate(sModel, howToGetFeatures, ref _sharedPtr);
}
/// <summary>
/// The function detects edges in src and draw them to dst. The algorithm underlies this function is much more robust to texture presence, than common approaches, e.g. Sobel
/// </summary>
/// <param name="src">source image (RGB, float, in [0;1]) to detect edges</param>
/// <param name="dst">destination image (grayscale, float, in [0;1]) where edges are drawn</param>
public void DetectEdges(Mat src, Mat dst)
{
XImgprocInvoke.cveStructuredEdgeDetectionDetectEdges(_ptr, src, dst);
}
/// <summary>
/// Release the unmanaged memory associated with this object.
/// </summary>
protected override void DisposeObject()
{
if (_ptr != IntPtr.Zero)
{
XImgprocInvoke.cveStructuredEdgeDetectionRelease(ref _ptr, ref _sharedPtr);
}
}
}
/// <summary>
/// Helper class for training part of [P. Dollar and C. L. Zitnick. Structured Forests for Fast Edge Detection, 2013].
/// </summary>
public class RFFeatureGetter : UnmanagedObject
{
private IntPtr _sharedPtr;
/// <summary>
/// Create a default RFFeatureGetter
/// </summary>
public RFFeatureGetter()
{
_ptr = XImgprocInvoke.cveRFFeatureGetterCreate(ref _sharedPtr);
}
/// <summary>
/// Release the unmanaged memory associated with this RFFeatureGetter.
/// </summary>
protected override void DisposeObject()
{
if (_ptr != IntPtr.Zero)
{
XImgprocInvoke.cveRFFeatureGetterRelease(ref _ptr, ref _sharedPtr);
}
}
}
/// <summary>
/// Library to invoke XImgproc functions
/// </summary>
public static partial class XImgprocInvoke
{
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern IntPtr cveStructuredEdgeDetectionCreate(IntPtr model, IntPtr howToGetFeatures, ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveStructuredEdgeDetectionDetectEdges(IntPtr detection, IntPtr src, IntPtr dst);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveStructuredEdgeDetectionRelease(ref IntPtr detection, ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern IntPtr cveRFFeatureGetterCreate(ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveRFFeatureGetterRelease(ref IntPtr getter, ref IntPtr sharedPtr);
}
/// <summary>
/// Class implementing edge detection algorithm from Piotr Dollár and C Lawrence Zitnick. Structured forests for fast edge detection. In Computer Vision (ICCV), 2013 IEEE International Conference on, pages 1841–1848. IEEE, 2013.
/// </summary>
public class StructuredEdgeDetection : UnmanagedObject
{
private IntPtr _sharedPtr;
/// <summary>
/// Create an edge detection algorithm.
/// </summary>
/// <param name="model">name of the file where the model is stored</param>
/// <param name="howToGetFeatures">optional object inheriting from RFFeatureGetter. You need it only if you would like to train your own forest, pass NULL otherwise</param>
public StructuredEdgeDetection(String model, RFFeatureGetter howToGetFeatures)
{
using (CvString sModel = new CvString(model))
_ptr = XImgprocInvoke.cveStructuredEdgeDetectionCreate(sModel, howToGetFeatures, ref _sharedPtr);
}
/// <summary>
/// The function detects edges in src and draw them to dst. The algorithm underlies this function is much more robust to texture presence, than common approaches, e.g. Sobel
/// </summary>
/// <param name="src">source image (RGB, float, in [0;1]) to detect edges</param>
/// <param name="dst">destination image (grayscale, float, in [0;1]) where edges are drawn</param>
public void DetectEdges(IInputArray src, IOutputArray dst)
{
using (InputArray iaSrc = src.GetInputArray())
using (OutputArray oaDst = dst.GetOutputArray())
XImgprocInvoke.cveStructuredEdgeDetectionDetectEdges(_ptr, iaSrc, oaDst);
}
/// <summary>
/// The function computes orientation from edge image.
/// </summary>
/// <param name="src">Edge image.</param>
/// <param name="dst">Orientation image.</param>
public void ComputeOrientation(IInputArray src, IOutputArray dst)
{
using (InputArray iaSrc = src.GetInputArray())
using (OutputArray oaDst = dst.GetOutputArray())
XImgprocInvoke.cveStructuredEdgeDetectionComputeOrientation(_ptr, iaSrc, oaDst);
}
/// <summary>
/// The function edgenms in edge image and suppress edges where edge is stronger in orthogonal direction.
/// </summary>
/// <param name="edgeImage">edge image from DetectEdges function.</param>
/// <param name="orientationImage">orientation image from ComputeOrientation function.</param>
/// <param name="dst">Suppressed image (grayscale, float, in [0;1])</param>
/// <param name="r">Radius for NMS suppression.</param>
/// <param name="s">Radius for boundary suppression.</param>
/// <param name="m">Multiplier for conservative suppression.</param>
/// <param name="isParallel">Enables/disables parallel computing.</param>
public void EdgesNms(IInputArray edgeImage, IInputArray orientationImage, IOutputArray dst, int r = 2, int s = 0, float m = 1, bool isParallel = true)
{
using (InputArray iaEdgeImage = edgeImage.GetInputArray())
using (InputArray iaOrientationImage = orientationImage.GetInputArray())
using (OutputArray oaDst = dst.GetOutputArray())
{
XImgprocInvoke.cveStructuredEdgeDetectionEdgesNms(_ptr, iaEdgeImage, iaOrientationImage, oaDst, r, s, m, isParallel);
}
}
/// <summary>
/// Release the unmanaged memory associated with this object.
/// </summary>
protected override void DisposeObject()
{
if (_ptr != IntPtr.Zero)
{
XImgprocInvoke.cveStructuredEdgeDetectionRelease(ref _ptr, ref _sharedPtr);
}
}
}
/// <summary>
/// Helper class for training part of [P. Dollar and C. L. Zitnick. Structured Forests for Fast Edge Detection, 2013].
/// </summary>
public class RFFeatureGetter : UnmanagedObject
{
private IntPtr _sharedPtr;
/// <summary>
/// Create a default RFFeatureGetter
/// </summary>
public RFFeatureGetter()
{
_ptr = XImgprocInvoke.cveRFFeatureGetterCreate(ref _sharedPtr);
}
/// <summary>
/// Release the unmanaged memory associated with this RFFeatureGetter.
/// </summary>
protected override void DisposeObject()
{
if (_ptr != IntPtr.Zero)
{
XImgprocInvoke.cveRFFeatureGetterRelease(ref _ptr, ref _sharedPtr);
}
}
}
/// <summary>
/// Library to invoke XImgproc functions
/// </summary>
public static partial class XImgprocInvoke
{
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern IntPtr cveStructuredEdgeDetectionCreate(IntPtr model, IntPtr howToGetFeatures, ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveStructuredEdgeDetectionDetectEdges(IntPtr detection, IntPtr src, IntPtr dst);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveStructuredEdgeDetectionRelease(ref IntPtr detection, ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern IntPtr cveRFFeatureGetterCreate(ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveRFFeatureGetterRelease(ref IntPtr getter, ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveStructuredEdgeDetectionComputeOrientation(IntPtr detection, IntPtr src, IntPtr dst);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveStructuredEdgeDetectionEdgesNms(
IntPtr detection,
IntPtr edgeImage,
IntPtr orientationImage,
IntPtr dst,
int r,
int s,
float m,
[MarshalAs(CvInvoke.BoolMarshalType)]
bool isParallel);
}
}

10
Emgu.CV.Extern/ximgproc/ximgproc_c.cpp

@ -95,10 +95,18 @@ cv::ximgproc::StructuredEdgeDetection* cveStructuredEdgeDetectionCreate(cv::Stri
*sharedPtr = new cv::Ptr<cv::ximgproc::StructuredEdgeDetection>(ptr);
return ptr.get();
}
void cveStructuredEdgeDetectionDetectEdges(cv::ximgproc::StructuredEdgeDetection* detection, cv::Mat* src, cv::Mat* dst)
void cveStructuredEdgeDetectionDetectEdges(cv::ximgproc::StructuredEdgeDetection* detection, cv::_InputArray* src, cv::_OutputArray* dst)
{
detection->detectEdges(*src, *dst);
}
void cveStructuredEdgeDetectionComputeOrientation(cv::ximgproc::StructuredEdgeDetection* detection, cv::_InputArray* src, cv::_OutputArray* dst)
{
detection->computeOrientation(*src, *dst);
}
void cveStructuredEdgeDetectionEdgesNms(cv::ximgproc::StructuredEdgeDetection* detection, cv::_InputArray* edgeImage, cv::_InputArray* orientationImage, cv::_OutputArray* dst, int r, int s, float m, bool isParallel)
{
detection->edgesNms(*edgeImage, *orientationImage, *dst, r, s, m, isParallel);
}
void cveStructuredEdgeDetectionRelease(cv::ximgproc::StructuredEdgeDetection** detection, cv::Ptr<cv::ximgproc::StructuredEdgeDetection>** sharedPtr)
{
delete *sharedPtr;

4
Emgu.CV.Extern/ximgproc/ximgproc_c.h

@ -40,7 +40,9 @@ CVAPI(cv::ximgproc::RFFeatureGetter*) cveRFFeatureGetterCreate(cv::Ptr<cv::ximgp
CVAPI(void) cveRFFeatureGetterRelease(cv::ximgproc::RFFeatureGetter** getter, cv::Ptr<cv::ximgproc::RFFeatureGetter>** sharedPtr);
CVAPI(cv::ximgproc::StructuredEdgeDetection*) cveStructuredEdgeDetectionCreate(cv::String* model, cv::ximgproc::RFFeatureGetter* howToGetFeatures, cv::Ptr<cv::ximgproc::StructuredEdgeDetection>** sharedPtr);
CVAPI(void) cveStructuredEdgeDetectionDetectEdges(cv::ximgproc::StructuredEdgeDetection* detection, cv::Mat* src, cv::Mat* dst);
CVAPI(void) cveStructuredEdgeDetectionDetectEdges(cv::ximgproc::StructuredEdgeDetection* detection, cv::_InputArray* src, cv::_OutputArray* dst);
CVAPI(void) cveStructuredEdgeDetectionComputeOrientation(cv::ximgproc::StructuredEdgeDetection* detection, cv::_InputArray* src, cv::_OutputArray* dst);
CVAPI(void) cveStructuredEdgeDetectionEdgesNms(cv::ximgproc::StructuredEdgeDetection* detection, cv::_InputArray* edgeImage, cv::_InputArray* orientationImage, cv::_OutputArray* dst, int r, int s, float m, bool isParallel);
CVAPI(void) cveStructuredEdgeDetectionRelease(cv::ximgproc::StructuredEdgeDetection** detection, cv::Ptr<cv::ximgproc::StructuredEdgeDetection>** sharedPtr);
CVAPI(cv::ximgproc::SuperpixelSEEDS*) cveSuperpixelSEEDSCreate(

Loading…
Cancel
Save