Open In App

Opening multiple color windows to capture using OpenCV in Python

Last Updated : 11 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Opening multiple color windows is a useful technique in computer vision applications. With OpenCV in Python, we can capture video from the system’s camera and display it simultaneously in different color formats such as grayscale, HSV or RGB. This approach helps in real-time analysis, color detection and image processing tasks, allowing developers to better understand how different color spaces represent the same video feed.

Approach

  1. Use OpenCV to capture live video from the system’s default camera.
  2. Create two separate display windows: one for the colored video feed and another for the grayscale video feed (converted using OpenCV).
  3. Keep the capture running in a loop until the user presses the ‘q’ key.
  4. Release resources and close windows properly after termination.

Libraries Used:

Installation

To install the required libraries, run:

pip install opencv-python numpy

Python Code Implementation

Python
import cv2
import numpy as np

cap = cv2.VideoCapture(0)  # open camera

while True:
    ret, frame = cap.read()  # read frame
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)  # convert to grayscale
    
    cv2.imshow('frame', frame)  # show color
    cv2.imshow('gray', gray)    # show grayscale

    if cv2.waitKey(1) & 0xFF == ord('q'): # quit on 'q'
        break

cap.release()  # release camera
cv2.destroyAllWindows()  # close windows

Output

Run the above code on your own system so that you can install the required libraries and more


Practice Tags :

Similar Reads