OpenCvSharp.Cv2.Merge C# (CSharp) Method

Merge() public static method

makes multi-channel array out of several single-channel arrays
public static Merge ( Mat mv, Mat dst ) : void
mv Mat
dst Mat
return void
        public static void Merge(Mat[] mv, Mat dst)
        {
            if (mv == null)
                throw new ArgumentNullException(nameof(mv));
            if (mv.Length == 0)
                throw new ArgumentException("mv.Length == 0");
            if (dst == null)
                throw new ArgumentNullException(nameof(dst));
            foreach (Mat m in mv)
            {
                if(m == null)
                    throw new ArgumentException("mv contains null element");
                m.ThrowIfDisposed();
            }
            dst.ThrowIfDisposed();

            var mvPtr = new IntPtr[mv.Length];
            for (int i = 0; i < mv.Length; i++)
            {
                mvPtr[i] = mv[i].CvPtr;
            }
            NativeMethods.core_merge(mvPtr, (uint)mvPtr.Length, dst.CvPtr);
            GC.KeepAlive(mv);
            GC.KeepAlive(dst);
        }
        #endregion

Usage Example

コード例 #1
0
 /// <summary>
 ///     Adds transparency channel to source image and writes to output image.
 /// </summary>
 public static void AddAlphaChannel(Mat src, Mat dst, Mat alpha)
 {
     using (ResourceTracker t = new ResourceTracker())
     {
         //split is used for splitting the channels separately
         var bgr  = t.T(Cv2.Split(src));
         var bgra = new[] { bgr[0], bgr[1], bgr[2], alpha };
         Cv2.Merge(bgra, dst);
     }
 }
Cv2