我怎么能得到我的相机视频RGB和其他值实时到我的Python脚本/编辑



我试图创建一个Python程序来获取实时摄像机视频中每个像素的RGB值,然后创建一个新窗口,该窗口将用不同的字符绘制相同的视频,如"x", "!", "-", "等。

问题是,我可以使用的工具,我怎么能让相机视频直接通过我的程序到一个新的窗口?

我尝试过视频编辑库,但没有成功。

你肯定想玩OpenCV

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

捕获网络摄像头的基本示例:

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()

最新更新