Skip to content

Commit

Permalink
added MeanStdDev overload (out Scalar)
Browse files Browse the repository at this point in the history
  • Loading branch information
shimat committed Sep 18, 2014
1 parent ee86382 commit 7ea0b33
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 341 deletions.
35 changes: 32 additions & 3 deletions src/OpenCvSharp.CPlusPlus/Cv2/Cv2_core.cs
Expand Up @@ -614,8 +614,8 @@ public static Scalar Mean(InputArray src, InputArray mask = null)
/// <param name="mean">The output parameter: computed mean value</param>
/// <param name="stddev">The output parameter: computed standard deviation</param>
/// <param name="mask">The optional operation mask</param>
public static void MeanStdDev(InputArray src, OutputArray mean,
OutputArray stddev, InputArray mask = null)
public static void MeanStdDev(
InputArray src, OutputArray mean, OutputArray stddev, InputArray mask = null)
{
if (src == null)
throw new ArgumentNullException("src");
Expand All @@ -626,9 +626,38 @@ public static Scalar Mean(InputArray src, InputArray mask = null)
src.ThrowIfDisposed();
mean.ThrowIfNotReady();
stddev.ThrowIfNotReady();
NativeMethods.core_meanStdDev(src.CvPtr, mean.CvPtr, stddev.CvPtr, ToPtr(mask));

NativeMethods.core_meanStdDev_OutputArray(src.CvPtr, mean.CvPtr, stddev.CvPtr, ToPtr(mask));

mean.Fix();
stddev.Fix();
GC.KeepAlive(src);
GC.KeepAlive(mask);
}

/// <summary>
/// computes mean value and standard deviation of all or selected array elements
/// </summary>
/// <param name="src">The source array; it should have 1 to 4 channels
/// (so that the results can be stored in Scalar's)</param>
/// <param name="mean">The output parameter: computed mean value</param>
/// <param name="stddev">The output parameter: computed standard deviation</param>
/// <param name="mask">The optional operation mask</param>
public static void MeanStdDev(
InputArray src, out Scalar mean, out Scalar stddev, InputArray mask = null)
{
if (src == null)
throw new ArgumentNullException("src");

src.ThrowIfDisposed();

CvScalar mean0, stddev0;
NativeMethods.core_meanStdDev_Scalar(src.CvPtr, out mean0, out stddev0, ToPtr(mask));
mean = mean0;
stddev = stddev0;

GC.KeepAlive(src);
GC.KeepAlive(mask);
}
#endregion
#region Norm
Expand Down
9 changes: 7 additions & 2 deletions src/OpenCvSharp.CPlusPlus/PInvoke/core/NativeMethods_core.cs
Expand Up @@ -77,9 +77,14 @@ static partial class NativeMethods
public static extern void core_findNonZero(IntPtr src, IntPtr idx);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern CvScalar core_mean(IntPtr src, IntPtr mask);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void core_meanStdDev_OutputArray(
IntPtr src, IntPtr mean, IntPtr stddev, IntPtr mask);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void core_meanStdDev(IntPtr src, IntPtr mean,
IntPtr stddev, IntPtr mask);
public static extern void core_meanStdDev_Scalar(
IntPtr src, out CvScalar mean, out CvScalar stddev, IntPtr mask);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, EntryPoint = "core_norm1")]
public static extern double core_norm(IntPtr src1, int normType, IntPtr mask);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, EntryPoint = "core_norm2")]
Expand Down
Expand Up @@ -147,21 +147,25 @@ static partial class NativeMethods
public static extern IntPtr core_InputArray_new_byDouble(double val);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr core_InputArray_new_byGpuMat(IntPtr mat);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void core_InputArray_delete(IntPtr ia);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr core_OutputArray_new_byMat(IntPtr mat);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr core_OutputArray_new_byGpuMat(IntPtr mat);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr core_OutputArray_new_byScalar(CvScalar val);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void core_OutputArray_delete(IntPtr oa);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int core_InputArray_kind(IntPtr ia);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr core_OutputArray_getMat(IntPtr oa);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern CvScalar core_OutputArray_getScalar(IntPtr oa);
#endregion

#region FileStorage
Expand Down
1 change: 1 addition & 0 deletions src/OpenCvSharp.CPlusPlus/modules/core/OutputArray.cs
Expand Up @@ -152,6 +152,7 @@ protected override void Dispose(bool disposing)
{
return new OutputArray(mat);
}

#endregion

#region Operators
Expand Down
39 changes: 30 additions & 9 deletions src/OpenCvSharp.Sandbox/Program.cs
Expand Up @@ -23,6 +23,36 @@ internal class Program
{
[STAThread]
private static void Main(string[] args)
{
Mat src = new Mat("data/lenna.png", LoadMode.GrayScale);
Mat zoom = new Mat();
Mat f32 = new Mat();

Cv2.Resize(src, zoom, new Size(960, 1280), 0, 0, Interpolation.Cubic);
zoom.ConvertTo(f32, MatType.CV_32FC1);

Scalar mean, stddev;
Cv2.MeanStdDev(f32, out mean, out stddev);
Console.WriteLine(mean[0]);
Console.WriteLine(stddev[0]);

Mat meanm = new Mat(), stddevm = new Mat();
Cv2.MeanStdDev(f32, meanm, stddevm);
Console.WriteLine(meanm.At<double>(0));
Console.WriteLine(stddevm.At<double>(0));
meanm.ToString();

/*var img1 = new IplImage("data/lenna.png", LoadMode.Color);
var img2 = new IplImage("data/match2.png", LoadMode.Color);
Surf(img1, img2);*/

//Mat[] mats = StitchingPreprocess(400, 400, 10);
//Stitching(mats);
//Track();
//Run();
}

private static void Clahe()
{
Mat src = new Mat("data/tsukuba_left.png", LoadMode.GrayScale);
Mat dst20 = new Mat();
Expand All @@ -40,15 +70,6 @@ private static void Main(string[] args)
}

Window.ShowImages(src, dst20, dst40, dst44);

/*var img1 = new IplImage("data/lenna.png", LoadMode.Color);
var img2 = new IplImage("data/match2.png", LoadMode.Color);
Surf(img1, img2);*/

//Mat[] mats = StitchingPreprocess(400, 400, 10);
//Stitching(mats);
//Track();
//Run();
}

private static void Surf(IplImage img1, IplImage img2)
Expand Down
Binary file modified src/OpenCvSharp.Sandbox/dll/x86/OpenCvSharpExtern.dll
Binary file not shown.

0 comments on commit 7ea0b33

Please sign in to comment.