Opening multiple colored windows for capturing using OpenCV in Python

OpenCV — is an open source computer vision library that works with many programming languages ​​and provides a wide range of opportunities for understanding the subject of computer vision. In this example, we will be using OpenCV to open the system camera and capture video in two different colors. 
Approach: with the libraries available in OpenCV-Python below, we will open two different windows, one of which will display live results from the camera in color and the other — in black and white (black and white). 
Used libraries:

  • CV2
  • NumPy

The cv2 library is installed automatically when you install openCV. To install numpy, use the following command in a cmd / linux terminal:
pip install numpy

# import of required modules

import cv2

import numpy as np

 
# capture from the first attached camera

cap = cv2.VideoCapture ( 0 )

  
# will continue capturing until the" q "key is pressed

while True :

  ret, frame = cap.read ()

 

# Capture in grayscale

gray = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY)

 

cv2.imshow ( `frame` , frame)

cv2.imshow ( `gray` , gray)

  

# The program will exit when you press the q key

  if cv2.waitKey ( 1 ) & amp;  0xFF = = ord ( `q` ):

break

  
# Release all resources
cap.release ()
cv2.destroyAllWindows ()

Output: