示例#1
0
文件: UMat.cs 项目: ersinkecis/EmguCV
        /// <summary>
        /// Copy data from managed array to this Mat
        /// </summary>
        /// <typeparam name="T">The type of managed data array</typeparam>
        /// <param name="data">The managed array where data will be copied from</param>
        public void SetTo <T>(T[] data)
        {
            Debug.Assert(
                data.Length == Total.ToInt32() * ElementSize / Toolbox.SizeOf <T>(), String.Format("Invalid data length, expecting {0} but was {1}", Total.ToInt32() * ElementSize / Toolbox.SizeOf <T>(), data.Length));
            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            UMatInvoke.cveUMatCopyDataFrom(this, handle.AddrOfPinnedObject());
            handle.Free();
        }
示例#2
0
        /// <summary>
        /// Copy data from this Mat to the managed array
        /// </summary>
        /// <typeparam name="T">The type of managed data array</typeparam>
        /// <param name="data">The managed array where data will be copied to.</param>
        public void CopyTo <T>(T[] data)
        {
            Debug.Assert(
                Toolbox.SizeOf <T>() * data.Length >= Total.ToInt32() * ElementSize,
                String.Format("Size of data is not enough, required at least {0}, but was {1} ", Total.ToInt32() * ElementSize / Toolbox.SizeOf <T>(), data.Length));
            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            UMatInvoke.cveUMatCopyDataTo(this, handle.AddrOfPinnedObject());
            handle.Free();
        }
示例#3
0
        /// <summary>
        /// Release all the unmanaged memory associated with this object.
        /// </summary>
        protected override void DisposeObject()
        {
            if (_needDispose && _ptr != IntPtr.Zero)
            {
                UMatInvoke.cveUMatRelease(ref _ptr);
            }

            //if (_oclMatAllocator != IntPtr.Zero)
            //    MatDataAllocatorInvoke.cveMatAllocatorRelease(ref _oclMatAllocator);

            base.DisposeObject();
        }
示例#4
0
 /// <summary>
 /// Converts an array to another data type with optional scaling.
 /// </summary>
 /// <param name="m">Output matrix; if it does not have a proper size or type before the operation, it is reallocated.</param>
 /// <param name="rtype">Desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.</param>
 /// <param name="alpha">Optional scale factor.</param>
 /// <param name="beta">Optional delta added to the scaled values.</param>
 public void ConvertTo(IOutputArray m, CvEnum.DepthType rtype, double alpha = 1.0, double beta = 0.0)
 {
     using (OutputArray oaM = m.GetOutputArray())
         UMatInvoke.cveUMatConvertTo(Ptr, oaM, rtype, alpha, beta);
 }
示例#5
0
 /// <summary>
 /// Changes the shape and/or the number of channels of a 2D matrix without copying the data.
 /// </summary>
 /// <param name="cn">New number of channels. If the parameter is 0, the number of channels remains the same.</param>
 /// <param name="rows">New number of rows. If the parameter is 0, the number of rows remains the same.</param>
 /// <returns>A new mat header that has different shape</returns>
 public UMat Reshape(int cn, int rows = 0)
 {
     return(new UMat(UMatInvoke.cveUMatReshape(Ptr, cn, rows), true));
 }
示例#6
0
 /// <summary>
 /// Pointer to the InputOutputArray
 /// </summary>
 public InputOutputArray GetInputOutputArray()
 {
     return(new InputOutputArray(UMatInvoke.cveInputOutputArrayFromUMat(_ptr), this));
 }
示例#7
0
 /// <summary>
 /// Pointer to the OutputArray
 /// </summary>
 public OutputArray GetOutputArray()
 {
     return(new OutputArray(UMatInvoke.cveOutputArrayFromUMat(_ptr), this));
 }
示例#8
0
        /*
         * /// <summary>
         * /// Copies the values of the <paramref name="data"/> to Mat.
         * /// </summary>
         * /// <param name="data">The data storage, must match the size of the Mat</param>
         * public void SetTo(Array data)
         * {
         * if (IsEmpty)
         * {
         *    int dimension = data.Rank;
         *
         *    DepthType dt = Mat.GetDepthTypeFromArray(data);
         *    if (dt == DepthType.Default)
         *       throw new Exception("The specific data type is not supported.");
         *
         *    if (dimension == 1)
         *    {
         *       this.Create(data.GetLength(0), 1, dt, 1);
         *    }
         *    else if (dimension == 2)
         *    {
         *       this.Create(data.GetLength(0), data.GetLength(1), dt, 1);
         *    }
         *    else if (dimension == 3)
         *    {
         *       this.Create(data.GetLength(0), data.GetLength(1), dt, 1);
         *    }
         *    else
         *    {
         *       throw new Exception("The Mat has to be pre-allocated");
         *    }
         * }
         *
         * using (Mat.MatWithHandle m = Mat.PrepareArrayForCopy(Depth, Size, NumberOfChannels, data))
         *    m.CopyTo(this);
         * }*/

        /// <summary>
        /// Return the Mat representation of the UMat
        /// </summary>
        public Mat GetMat(CvEnum.AccessType access)
        {
            return(new Mat(UMatInvoke.cveUMatGetMat(_ptr, access), true, false));
        }
示例#9
0
 /// <summary>
 /// Copy the data in this umat to the other mat
 /// </summary>
 /// <param name="mask">Operation mask. Its non-zero elements indicate which matrix elements need to be copied.</param>
 /// <param name="m">The input array to copy to</param>
 public void CopyTo(IOutputArray m, IInputArray mask = null)
 {
     using (OutputArray oaM = m.GetOutputArray())
         using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
             UMatInvoke.cveUMatCopyTo(this, oaM, iaMask);
 }
示例#10
0
 /// <summary>
 /// Allocates new array data if needed.
 /// </summary>
 /// <param name="rows">New number of rows.</param>
 /// <param name="cols">New number of columns.</param>
 /// <param name="type">New matrix element depth type.</param>
 /// <param name="channels">New matrix number of channels</param>
 /// <param name="usage">Allocation Usage</param>
 public void Create(int rows, int cols, CvEnum.DepthType type, int channels, Usage usage = Usage.Default)
 {
     UMatInvoke.cveUMatCreateData(_ptr, rows, cols, CvInvoke.MakeType(type, channels), usage);
 }
示例#11
0
 /// <summary>
 /// Create a umat header for the specific ROI
 /// </summary>
 /// <param name="umat">The umat where the new UMat header will share data from</param>
 /// <param name="rowRange">The region of interest</param>
 /// <param name="colRange">The region of interest</param>
 public UMat(UMat umat, Range rowRange, Range colRange)
     : this(UMatInvoke.cveUMatCreateFromRange(umat.Ptr, ref rowRange, ref colRange), true)
 {
 }
示例#12
0
 /// <summary>
 /// Get the Umat header for the specific roi of the parent
 /// </summary>
 /// <param name="parent">The parent Umat</param>
 /// <param name="roi">The region of interest</param>
 public UMat(UMat parent, Rectangle roi)
     : this(UMatInvoke.cveUMatCreateFromRect(parent.Ptr, ref roi), true)
 {
 }
示例#13
0
 /// <summary>
 /// Create an empty cv::UMat
 /// </summary>
 public UMat()
     : this(UMatInvoke.cveUMatCreate(), true)
 {
 }
示例#14
0
 /// <summary>
 /// Create a umat header for the specific ROI
 /// </summary>
 /// <param name="umat">The umat where the new UMat header will share data from</param>
 /// <param name="rowRange">The region of interest</param>
 /// <param name="colRange">The region of interest</param>
 public UMat(UMat umat, Emgu.CV.Structure.Range rowRange, Emgu.CV.Structure.Range colRange)
     : this(UMatInvoke.cveUMatCreateFromRange(umat.Ptr, ref rowRange, ref colRange), true)
 {
 }
示例#15
0
        /*
         * /// <summary>
         * /// Copies the values of the UMat to <paramref name="data"/>.
         * /// </summary>
         * /// <param name="data">The data storage, must match the size of the UMat</param>
         * public void CopyTo(Array data)
         * {
         * if (IsEmpty)
         * {
         *    throw new Exception("The UMat is empty");
         * }
         *
         * using (Mat.MatWithHandle m = Mat.PrepareArrayForCopy(Depth, Size, NumberOfChannels, data))
         *    CopyTo(m);
         * }*/

        /// <summary>
        /// Sets all or some of the array elements to the specified value.
        /// </summary>
        /// <param name="value">Assigned scalar converted to the actual array type.</param>
        /// <param name="mask">Operation mask of the same size as the umat.</param>
        public void SetTo(IInputArray value, IInputArray mask = null)
        {
            using (InputArray iaValue = value.GetInputArray())
                using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
                    UMatInvoke.cveUMatSetTo(Ptr, iaValue, iaMask);
        }
示例#16
0
 /// <summary>
 /// Computes the dot product of two mats
 /// </summary>
 /// <param name="mat">The matrix to compute dot product with</param>
 /// <returns>The dot product</returns>
 public double Dot(IInputArray mat)
 {
     using (InputArray iaMat = mat.GetInputArray())
         return(UMatInvoke.cveUMatDot(Ptr, iaMat));
 }
示例#17
0
文件: UMat.cs 项目: gxliu/emgucv-code
 /// <summary>
 /// Allocates new array data if needed.
 /// </summary>
 /// <param name="rows">New number of rows.</param>
 /// <param name="cols">New number of columns.</param>
 /// <param name="type">New matrix element depth type.</param>
 /// <param name="channels">New matrix number of channels</param>
 public void Create(int rows, int cols, CvEnum.DepthType type, int channels)
 {
     UMatInvoke.cvUMatCreateData(_ptr, rows, cols, CvInvoke.MakeType(type, channels));
 }