Browse Source

Change the data type associate with Matrix to jagged matrix (from multi-dimension matrix)

git-svn-id: https://emgucv.svn.sourceforge.net/svnroot/emgucv/trunk@33 d7f09016-e345-0410-b530-edf29a71df78
UWP10
canming 17 years ago
parent
commit
f732bc24e3
  1. 10
      Emgu.CV.Test/AutoTestMatrix.cs
  2. 8
      Emgu.CV/CameraCalibration/RotationVector.cs
  3. 16
      Emgu.CV/ConvolutionKernelF.cs
  4. 27
      Emgu.CV/Matrix.cs
  5. BIN
      Emgu.CV/PInvoke/CvInvoke.cs
  6. 11
      Emgu.CV/PointAndLine/PointCollection.cs

10
Emgu.CV.Test/AutoTestMatrix.cs

@ -27,17 +27,19 @@ namespace Emgu.CV.Test
foreach (byte v in row)
Assert.AreEqual(254.0, v);
}
/*
[Test]
public void Test_Data()
{
Random r = new Random();
Byte[][] data = new Byte[20][];
Byte[,] data = new Byte[20,30];
for (int i = 0; i < data.Length; i++)
{
data[i] = new Byte[30];
r.NextBytes(data[i]);
r.NextBytes(data);
}
Matrix<Byte> m = new Matrix<byte>(data);
Byte[][] data2 = m.Data;
@ -84,6 +86,6 @@ namespace Emgu.CV.Test
else Assert.AreEqual(0.0, data2[i][j]);
}
}
}
}*/
}
}

8
Emgu.CV/CameraCalibration/RotationVector.cs

@ -26,10 +26,10 @@ namespace Emgu.CV
: this()
{
Debug.Assert(value.Length == 3);
Data = new float[][]
{ new float[] { value[0] },
new float[] { value[1] },
new float[] { value[2] }
Data = new float[,]
{ { value[0] },
{ value[1] },
{ value[2] }
};
}

16
Emgu.CV/ConvolutionKernelF.cs

@ -41,7 +41,7 @@ namespace Emgu.CV
/// Create a convolution kernel using the specific floating point matrix
/// </summary>
/// <param name="kernel">the values for the convolution kernel</param>
public ConvolutionKernelF(float[][] kernel)
public ConvolutionKernelF(float[,] kernel)
: this(kernel, new Point2D<int>(-1, -1))
{
}
@ -51,16 +51,16 @@ namespace Emgu.CV
/// </summary>
/// <param name="kernel">the values for the convolution kernel</param>
/// <param name="center">the center for the convolution kernel</param>
public ConvolutionKernelF(float[][] kernel, Point2D<int> center)
: base( Math.Max(kernel.Length, 2), Math.Max(kernel[0].Length, 2))
public ConvolutionKernelF(float[,] kernel, Point2D<int> center)
: base( Math.Max(kernel.GetLength(0), 2), Math.Max(kernel.GetLength(1), 2))
{
int rows = kernel.Length;
int cols = kernel[0].Length;
int rows = kernel.GetLength(0);
int cols = kernel.GetLength(1);
Debug.Assert(!(rows == 0 || cols == 0));
/*
if (rows == 1)
{
kernel = new float[2][] { kernel[0], new float[cols] };
kernel = new float[2, cols] { kernel[0], new float[cols] };
rows++;
}
@ -71,7 +71,9 @@ namespace Emgu.CV
}
Emgu.Utils.CopyMatrix(kernel, CvMat.data);
*/
throw new System.Exception("Unimplemented");
_center = center;
}

27
Emgu.CV/Matrix.cs

@ -10,19 +10,22 @@ namespace Emgu.CV
/// </summary>
public class Matrix<D> : Array, IEquatable<Matrix<D>> where D : new()
{
private D[,] _array;
private GCHandle _dataHandle;
/// <summary>
/// Create a matrix of the specific rows and columns
/// </summary>
/// <param name="rows">The number of rows (<b>height</b>)</param>
/// <param name="cols">The number of cols (<b>width</b>)</param>
public Matrix(int rows, int cols)
:this( new D[rows, cols])
{
_ptr = CvInvoke.cvCreateMat(rows, cols, CvDepth);
}
///<summary> Create a matrix using the specific <paramref>data</paramref></summary>
public Matrix(D[][] data)
: this(data.Length, data[0].Length)
public Matrix(D[,] data)
//: this(data.Length, data[0].Length)
{
Data = data;
}
@ -64,21 +67,18 @@ namespace Emgu.CV
/// <summary>
/// Get or Set the data for this matrix
/// </summary>
public D[][] Data
public D[,] Data
{
get
{
MCvMat m = CvMat;
int rows = m.rows;
int cols = m.cols;
D[][] res = new D[rows][];
for (int i = 0; i < rows; res[i++] = new D[cols]) ;
Emgu.Utils.CopyMatrix(m.data, res);
return res;
return _array;
}
set
{
Emgu.Utils.CopyMatrix(value, CvMat.data);
FreeUnmanagedObjects();
_array = value;
_dataHandle = GCHandle.Alloc(_array, GCHandleType.Pinned);
_ptr = CvInvoke.cvMat(_array.GetLength(0), _array.GetLength(1), CvDepth, _dataHandle.AddrOfPinnedObject());
}
}
@ -125,7 +125,8 @@ namespace Emgu.CV
/// </summary>
protected override void FreeUnmanagedObjects()
{
CvInvoke.cvReleaseMat(ref _ptr);
if (_ptr != IntPtr.Zero) Marshal.Release(_ptr);
if (_dataHandle != null) _dataHandle.Free();
}
/// <summary>

BIN
Emgu.CV/PInvoke/CvInvoke.cs

11
Emgu.CV/PointAndLine/PointCollection.cs

@ -156,10 +156,15 @@ namespace Emgu.CV
pts.Add(pt.Coordinate);
Debug.Assert(pts.Count > 0);
int rows = pts.Count;
int cols = pts[0].Length;
Matrix<D> res = new Matrix<D>(pts.Count, pts[0].Length);
res.Data = pts.ToArray();
return res;
D[,] array = new D[rows,cols];
for (int i = 0; i <= rows; i++)
for (int j = 0; j <= cols; j++)
array[i, j] = pts[i][j];
return new Matrix<D>(array);
}
/// <summary>

Loading…
Cancel
Save