private void InitializeComponent(MatND <float> matND, RangeF[] ranges) { _matND = matND; MCvMatND cvMatND = _matND.MCvMatND; Debug.Assert( ranges.Length == cvMatND.dims, "incompatible dimension"); _ptr = Marshal.AllocHGlobal(StructSize.MCvHistogram); #region parse the ranges to appropriate format GCHandle rangesHandle = GCHandle.Alloc(ranges, GCHandleType.Pinned); IntPtr[] rangesPts = new IntPtr[ranges.Length]; Int64 address = rangesHandle.AddrOfPinnedObject().ToInt64(); for (int i = 0; i < rangesPts.Length; i++) { rangesPts[i] = new IntPtr(address + i * StructSize.RangF); } #endregion CvInvoke.cvMakeHistHeaderForArray( cvMatND.dims, Array.ConvertAll <MCvMatND.Dimension, int>(cvMatND.dim, delegate(MCvMatND.Dimension d) { return(d.Size); }), //binSizes _ptr, _matND.MCvMatND.data, rangesPts, 1); rangesHandle.Free(); }
/// <summary> /// Constructor used to deserialize runtime serialized object /// </summary> /// <param name="info">The serialization info</param> /// <param name="context">The streaming context</param> public DenseHistogram(SerializationInfo info, StreamingContext context) { MatND <float> matND = new MatND <float>(info, context); RangeF[] ranges = (RangeF[])info.GetValue("Ranges", typeof(RangeF[])); InitializeComponent(matND, ranges); }
/// <summary> /// Convert this matrix to different depth /// </summary> /// <typeparam name="TOtherDepth">The depth type to convert to</typeparam> /// <returns>Matrix of different depth</returns> public MatND <TOtherDepth> Convert <TOtherDepth>() where TOtherDepth : new() { MatND <TOtherDepth> res = new MatND <TOtherDepth>(GetDimension()); CvInvoke.cvConvertScale(Ptr, res.Ptr, 1.0, 0.0); return(res); }
/// <summary> /// Release the managed resources associated with this dense histogram /// </summary> protected override void ReleaseManagedResources() { if (_matND != null) { _matND.Dispose(); _matND = null; } }
/// <summary> /// Return true if the two DenseHistogram equals /// </summary> /// <param name="other">The other DenseHistogram to compare with</param> /// <returns>True if the two DenseHistogram equals</returns> public bool Equals(DenseHistogram other) { RangeF[] ranges1 = Ranges; RangeF[] ranges2 = other.Ranges; if (ranges1.Length != ranges2.Length) { return(false); } for (int i = 0; i < ranges1.Length; i++) { if (!ranges1[i].Equals(ranges2[i])) { return(false); } } return(MatND.Equals(other.MatND)); }
/// <summary> /// Check if the two MatND are equal /// </summary> /// <param name="other">The other MatND to compares to</param> /// <returns>True if the two MatND equals</returns> public bool Equals(MatND <TDepth> other) { #region check if the two MatND has equal dimension int[] dim1 = GetDimension(); int[] dim2 = other.GetDimension(); if (dim1.Length != dim2.Length) { return(false); } for (int i = 0; i < dim1.Length; i++) { if (dim1[i] != dim2[i]) { return(false); } } #endregion using (MatND <TDepth> diff = new MatND <TDepth>(dim1)) { CvInvoke.cvXor(_ptr, other.Ptr, diff.Ptr, IntPtr.Zero); return(Array.TrueForAll(diff.Bytes, delegate(Byte b) { return b == 0; })); } }