Life2Coding
Split Video Channels into RGB components using OpenCV in Python

This post will be helpful in learning OpenCV using Python programming. Here I will show how to implement OpenCV functions and apply it in various aspects using some examples. Then the output will be shown with some comparisons as well.

Requirements:

First, you need to setup your Python Environment with OpenCV. You can easily do it by following Life2Coding’s tutorial on YouTube: Linking OpenCV 3 with Python 3

Goals:

In this tutorial, I will show you how split the 3 channels of a color webcam video feed using OpenCV library and Python coding.

Documentation:

Python: cv2.split(m[, mv]) → mv

Divides a multi-channel array into several single-channel arrays.

Parameters:

  • m– input multi-channel array.
  • mv – output array or vector of arrays; in the first variant of the function the number of arrays must match channels() the arrays themselves are reallocated, if needed. The function cv2.split() splits a multi-channel array into separate single-channel arrays

Python: cv2.merge(mv[, dst]) → dst

Creates one multichannel array out of several single-channel ones.

Parameters:

  • mv– input array or vector of matrices to be merged; all the matrices in mv must have the same size and the same depth.
  • count– number of input matrices when mv is a plain C array; it must be greater than zero.
  • dst– output array of the same size and the same depth as mv[0]; The number of channels will be the total number of channels in the matrix array.

Steps:

  • Initialize webcam feed using cv2.VideoCapture()
  • Read webcam images using cv2.VideoCapture. read()
  • Split the BGR channels using cv2.split()
  • Merge the single channel with two zero matrix channels to create a color image using cv2.merge()
  • Display the output channel separately image using cv2.imshow()
  • Wait for keyboard button press using cv2.waitKey()
  • Exit window and destroy all windows using cv2.destroyAllWindows()

Example Code:

Output:

Capture-2 Split Video Channels into RGB components using OpenCV in Python

life2coding_icon [] Split Video Channels into RGB components using OpenCV in Python

Life2Coding

Technology Related Blog at Life2Coding
Feel free to contact us for your any kind of technical problems. We are here to help you.
life2coding_icon [] Split Video Channels into RGB components using OpenCV in Python

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.