Home > other >  How can I get my camera video RGB and other values in real time to my Python script / edit
How can I get my camera video RGB and other values in real time to my Python script / edit

Time:12-11

I'm trying to create a Python program to get the RGB values of every pixel in a live camera video and then create a new window that will draw the same video with different characters like "x", "!", "-", "#" etc.

Question is, that tools can I use and how can I get the camera video to come straight trough my program to a new window?

I've tried video editing libraries but without success.

CodePudding user response:

You definitely want to play with OpenCV

https://docs.opencv.org/4.x/dd/d43/tutorial_py_video_display.html

Basic example to capture webcam :

import numpy as np
import cv2 as cv
cap = cv.VideoCapture(0)
if not cap.isOpened():
    print("Cannot open camera")
    exit()
while True:
    # Capture frame-by-frame
    ret, frame = cap.read()
    # if frame is read correctly ret is True
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break
    # Our operations on the frame come here
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    # Display the resulting frame
    cv.imshow('frame', gray)
    if cv.waitKey(1) == ord('q'):
        break
# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
  • Related