Exemple #1
0
        /// <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();
        }
Exemple #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();
        }
Exemple #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();
        }
Exemple #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);
 }
Exemple #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));
 }
Exemple #6
0
 /// <summary>
 /// Pointer to the InputOutputArray
 /// </summary>
 public InputOutputArray GetInputOutputArray()
 {
     return(new InputOutputArray(UMatInvoke.cveInputOutputArrayFromUMat(_ptr), this));
 }
Exemple #7
0
 /// <summary>
 /// Pointer to the OutputArray
 /// </summary>
 public OutputArray GetOutputArray()
 {
     return(new OutputArray(UMatInvoke.cveOutputArrayFromUMat(_ptr), this));
 }
Exemple #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));
        }
Exemple #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);
 }
Exemple #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);
 }
Exemple #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)
 {
 }
Exemple #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)
 {
 }
Exemple #13
0
 /// <summary>
 /// Create an empty cv::UMat
 /// </summary>
 public UMat()
     : this(UMatInvoke.cveUMatCreate(), true)
 {
 }
Exemple #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)
 {
 }
Exemple #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);
        }
Exemple #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));
 }
Exemple #17
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>
 public void Create(int rows, int cols, CvEnum.DepthType type, int channels)
 {
     UMatInvoke.cvUMatCreateData(_ptr, rows, cols, CvInvoke.MakeType(type, channels));
 }