Ejemplo n.º 1
0
        /// <summary>
        /// Makes multi-channel array out of several single-channel arrays
        /// </summary>
        ///<param name="gpuMats">
        ///An array of single channel GpuMat where each item
        ///in the array represent a single channel of the GpuMat
        ///</param>
        /// <param name="stream">Use a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).</param>
        public void MergeFrom(GpuMat <TDepth>[] gpuMats, Stream stream)
        {
            Debug.Assert(NumberOfChannels == gpuMats.Length, "Number of channels does not agrees with the length of gpuMats");
            //If single channel, perform a copy
            if (NumberOfChannels == 1)
            {
                if (stream == null)
                {
                    GpuInvoke.Copy(gpuMats[0].Ptr, _ptr, IntPtr.Zero);
                }
                else
                {
                    stream.Copy <TDepth>(gpuMats[0], this);
                }
            }

            //handle multiple channels
            Size size = Size;

            IntPtr[] ptrs = new IntPtr[gpuMats.Length];
            for (int i = 0; i < gpuMats.Length; i++)
            {
                Debug.Assert(gpuMats[i].Size == size, "Size mismatch");
                ptrs[i] = gpuMats[i].Ptr;
            }
            GCHandle handle = GCHandle.Alloc(ptrs, GCHandleType.Pinned);

            GpuInvoke.Merge(handle.AddrOfPinnedObject(), _ptr, stream);
            handle.Free();
        }
Ejemplo n.º 2
0
        ///<summary>
        ///Split current Image into an array of gray scale images where each element
        ///in the array represent a single color channel of the original image
        ///</summary>
        ///<param name="gpuMats">
        ///An array of single channel GpuMat where each item
        ///in the array represent a single channel of the original GpuMat
        ///</param>
        /// <param name="stream">Use a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).</param>
        public void SplitInto(GpuMat <TDepth>[] gpuMats, Stream stream)
        {
            Debug.Assert(NumberOfChannels == gpuMats.Length, "Number of channels does not agrees with the length of gpuMats");

            if (NumberOfChannels == 1)
            {
                //If single channel, return a copy
                if (stream == null)
                {
                    GpuInvoke.Copy(_ptr, gpuMats[0], IntPtr.Zero);
                }
                else
                {
                    stream.Copy <TDepth>(this, gpuMats[0]);
                }
            }
            else
            {
                //handle multiple channels
                Size     size = Size;
                IntPtr[] ptrs = new IntPtr[gpuMats.Length];
                for (int i = 0; i < ptrs.Length; i++)
                {
                    Debug.Assert(gpuMats[i].Size == size, "Size mismatch");
                    ptrs[i] = gpuMats[i].Ptr;
                }
                GCHandle handle = GCHandle.Alloc(ptrs, GCHandleType.Pinned);
                GpuInvoke.Split(_ptr, handle.AddrOfPinnedObject(), stream);
                handle.Free();
            }
        }