public static float[] histogramFeatures(Image <Bgr, byte> src, Image <Gray, byte> mask) { Image <Lab, Byte> dst = src.Convert <Lab, Byte>(); DenseHistogram histo = new DenseHistogram(255, new RangeF(0, 255)); Image <Gray, Byte>[] channels = dst.Split(); histo.Calculate(new Image <Gray, Byte>[] { channels[0] }, true, mask); CvInvoke.Normalize(histo, histo); MatND <float> mat = new MatND <float>(255); histo.CopyTo(mat); float[] binValuesB = (float[])mat.ManagedArray; histo.Clear(); histo.Calculate(new Image <Gray, Byte>[] { channels[1] }, true, mask); CvInvoke.Normalize(histo, histo); mat = new MatND <float>(255); histo.CopyTo(mat); float[] binValuesG = (float[])mat.ManagedArray; histo.Clear(); histo.Calculate(new Image <Gray, Byte>[] { channels[2] }, true, mask); CvInvoke.Normalize(histo, histo); mat = new MatND <float>(255); histo.CopyTo(mat); float[] binValuesR = (float[])mat.ManagedArray; histo.Clear(); return(binValuesB.Concat(binValuesG).Concat(binValuesR).ToArray()); }
private static void DebugVisualizer() { using (MatND <float> mat = new MatND <float>(3, 5, 1)) { mat.SetRandNormal(new MCvScalar(), new MCvScalar(255)); VisualizerDevelopmentHost myHost = new VisualizerDevelopmentHost(mat, typeof(MatNDVisualizer)); myHost.ShowVisualizer(); } }
private static void DebugVisualizer() { using (MatND<float> mat = new MatND<float>(3, 5, 1)) { mat.SetRandNormal(new MCvScalar(), new MCvScalar(255)); VisualizerDevelopmentHost myHost = new VisualizerDevelopmentHost(mat, typeof(MatNDVisualizer)); myHost.ShowVisualizer(); } }
public static float[] imageFeatures(Image <Bgr, byte> src, int w = 20, int h = 20) { Image <Bgr, float> copy = src.Convert <Bgr, float>(); copy = copy.Resize(w, h, Emgu.CV.CvEnum.Inter.Linear, false); Mat[] channels = copy.Mat.Split(); int n = copy.Rows * copy.Cols; float[] vectorOfFeature = new float[n * 3]; for (int i = 0; i < channels.Length; i++) { Mat c = channels[0].Reshape(1, n); MatND <float> temp = new MatND <float>(n); c.CopyTo(temp); float[] partition = (float[])temp.ManagedArray; partition.CopyTo(vectorOfFeature, i * n); c.Dispose(); temp.Dispose(); } channels = null; copy.Dispose(); return(vectorOfFeature); }
public void TestMatNDRuntimeSerialization() { using (MatND<float> mat = new MatND<float>(2, 3, 4, 5)) { using (MemoryStream ms = new MemoryStream()) { mat.SetRandNormal(new MCvScalar(100), new MCvScalar(50)); mat.SerializationCompressionRatio = 6; System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); formatter.Serialize(ms, mat); Byte[] bytes = ms.GetBuffer(); using (MemoryStream ms2 = new MemoryStream(bytes)) { Object o = formatter.Deserialize(ms2); MatND<float> mat2 = (MatND<float>)o; Assert.IsTrue(mat.Equals(mat2)); } } } }
public void TestMatND() { using (MatND<float> mat = new MatND<float>(3, 5, 1)) { mat.SetRandNormal(new MCvScalar(), new MCvScalar(255)); MatND<double> matD = mat.Convert<double>(); MCvMatND matND = matD.MCvMatND; int rows = matND.dim[0].Size; int cols = matND.dims >= 2 ? matND.dim[1].Size : 1; int channels = matND.dims >= 3 ? matND.dim[2].Size : 1; Matrix<double> matrix = new Matrix<double>(rows, cols, channels); CvInvoke.cvCopy(matD, matrix, IntPtr.Zero); //using (MatrixViewer viewer = new MatrixViewer()) { //viewer.Matrix = matrix; //viewer.ShowDialog(); } } }
protected override Arr CreateArr(int channels, Depth depth, int dim0, int dim1) { return(mat = new MatND(new[] { dim0, dim1 }, depth, channels)); }
internal static extern IntPtr cvCloneMatND(MatND mat);