///<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 single channel, return a copy if (NumberOfChannels == 1) { if (stream == null) { GpuInvoke.Copy(_ptr, gpuMats[0], IntPtr.Zero); } else { stream.Copy <TDepth>(this, gpuMats[0]); } } //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.Split(_ptr, handle.AddrOfPinnedObject(), stream); handle.Free(); }