/// <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(); }