Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://stackoverflow.com/questions/45305957/modifying-a-function-in-opencv-and-emgucv-by-adding-extra-parameter
- Original OpenCV filter2D signature:
- CV_EXPORTS_W void filter2D(InputArray src
- , OutputArray dst
- , int ddepth
- , InputArray kernel
- , Point anchor = Point(-1,-1)
- , double delta = 0
- , int borderType = BORDER_DEFAULT);
- Modified OpenCV filter2D signature (according to your comment, an extra integer parameter):
- CV_EXPORTS_W void filter2D(InputArray src
- , OutputArray dst
- , int ddepth
- , InputArray kernel
- , Point anchor = Point(-1,-1)
- , double delta = 0
- , int borderType = BORDER_DEFAULT
- , int extra = 0);
- Let's begin with https://github.com/emgucv/emgucv/blob/master/Emgu.CV.Extern/imgproc/imgproc_c.cpp#L24
- void cveFilter2D( cv::_InputArray* src, cv::_OutputArray* dst, cv::_InputArray* kernel, CvPoint* anchor, double delta, int borderType )
- {
- CV_Assert( src->size() == dst->size() && src->channels() == dst->channels() );
- cv::filter2D( *src, *dst, dst->depth(), *kernel, *anchor, delta, borderType );
- }
- becomes
- void cveFilter2D( cv::_InputArray* src, cv::_OutputArray* dst, cv::_InputArray* kernel, CvPoint* anchor, double delta, int borderType, int extra )
- {
- CV_Assert( src->size() == dst->size() && src->channels() == dst->channels() );
- cv::filter2D( *src, *dst, dst->depth(), *kernel, *anchor, delta, borderType, extra );
- }
- We also need to change the associated header: https://github.com/emgucv/emgucv/blob/master/Emgu.CV.Extern/imgproc/imgproc_c.h#L21
- CVAPI(void) cveFilter2D(cv::_InputArray* src, cv::_OutputArray* dst, cv::_InputArray* kernel, CvPoint* anchor, double delta, int borderType );
- becomes
- CVAPI(void) cveFilter2D(cv::_InputArray* src, cv::_OutputArray* dst, cv::_InputArray* kernel, CvPoint* anchor, double delta, int borderType, int extra );
- Next, https://github.com/emgucv/emgucv/blob/master/Emgu.CV/PInvoke/CvInvokeCvextern.cs
- First, let's fix the dll import https://github.com/emgucv/emgucv/blob/master/Emgu.CV/PInvoke/CvInvokeCvextern.cs#L244
- [DllImport(ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
- private static extern void cveFilter2D(IntPtr src, IntPtr dst, IntPtr kernel, ref Point anchor, double delta, Emgu.CV.CvEnum.BorderType borderType);
- becomes
- [DllImport(ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
- private static extern void cveFilter2D(IntPtr src, IntPtr dst, IntPtr kernel, ref Point anchor, double delta, Emgu.CV.CvEnum.BorderType borderType, int extra);
- Now the wrapper function: https://github.com/emgucv/emgucv/blob/master/Emgu.CV/PInvoke/CvInvokeCvextern.cs#L226
- public static void Filter2D(IInputArray src, IOutputArray dst, IInputArray kernel, Point anchor, double delta = 0,
- Emgu.CV.CvEnum.BorderType borderType = CvEnum.BorderType.Default)
- {
- using (InputArray iaSrc = src.GetInputArray())
- using (OutputArray oaDst = dst.GetOutputArray())
- using (InputArray iaKernel = kernel.GetInputArray())
- cveFilter2D(iaSrc, oaDst, iaKernel, ref anchor, delta, borderType);
- }
- becomes (you can fix the documentation comments yourself)
- public static void Filter2D(IInputArray src, IOutputArray dst, IInputArray kernel, Point anchor, double delta = 0,
- Emgu.CV.CvEnum.BorderType borderType = CvEnum.BorderType.Default, int extra = 0)
- {
- using (InputArray iaSrc = src.GetInputArray())
- using (OutputArray oaDst = dst.GetOutputArray())
- using (InputArray iaKernel = kernel.GetInputArray())
- cveFilter2D(iaSrc, oaDst, iaKernel, ref anchor, delta, borderType, extra);
- }
- Finally, Image: https://github.com/emgucv/emgucv/blob/master/Emgu.CV/Image.cs#L3653
- public Image<TColor, Single> Convolution(ConvolutionKernelF kernel)
- {
- Image<TColor, Single> floatImage =
- (typeof(TDepth) == typeof(Single)) ?
- this as Image<TColor, Single>
- : Convert<TColor, Single>();
- Image<TColor, Single> res = new Image<TColor, Single>(Size);
- ForEachDuplicateChannel(
- delegate (IImage srcFloat, IImage dest, int channel)
- {
- //perform the convolution operation
- CvInvoke.Filter2D(
- srcFloat,
- dest,
- kernel,
- kernel.Center,
- 0);
- },
- res);
- if (!object.ReferenceEquals(floatImage, this))
- floatImage.Dispose();
- return res;
- }
- becomes something like this perhaps:
- public Image<TColor, Single> Convolution(ConvolutionKernelF kernel, int extra = 0)
- {
- Image<TColor, Single> floatImage =
- (typeof(TDepth) == typeof(Single)) ?
- this as Image<TColor, Single>
- : Convert<TColor, Single>();
- Image<TColor, Single> res = new Image<TColor, Single>(Size);
- ForEachDuplicateChannel(
- delegate (IImage srcFloat, IImage dest, int channel)
- {
- //perform the convolution operation
- CvInvoke.Filter2D(
- srcFloat,
- dest,
- kernel,
- kernel.Center,
- 0,
- CvEnum.BorderType.Default,
- extra);
- },
- res);
- if (!object.ReferenceEquals(floatImage, this))
- floatImage.Dispose();
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement