python如何制作虚拟相机?
How to make a virtual camera with python?
我正在 python 中试验 openCV,我制作了一个简单的网络摄像头,它只会以黑白显示,但我想知道是否有可能以某种方式将它连接到 discord,所以每当我调用朋友,他看到我是黑白的。`
import cv2
capture = cv2.VideoCapture(0)
capture.set(3, 640)
capture.set(4, 480)
capture.set(10, 300)
while True:
sucess, img = capture.read()
img = cv2.Canny(img, 100, 100)
cv2.imshow("Webcam", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
这可能晚了,但请检查一下 pyvirtualcam
先安装它:
pip install pyvirtualcam
你可以这样做:
import pyvirtualcam
import numpy as np
with pyvirtualcam.Camera(width=1280, height=720, fps=30) as cam:
while True:
frame = np.zeros((cam.height, cam.width, 4), np.uint8) # RGBA
frame[:,:,:3] = cam.frames_sent % 255 # grayscale animation
frame[:,:,3] = 255
cam.send(frame)
cam.sleep_until_next_frame()
cam.sleep_until_next_frame()
我正在 python 中试验 openCV,我制作了一个简单的网络摄像头,它只会以黑白显示,但我想知道是否有可能以某种方式将它连接到 discord,所以每当我调用朋友,他看到我是黑白的。`
import cv2
capture = cv2.VideoCapture(0)
capture.set(3, 640)
capture.set(4, 480)
capture.set(10, 300)
while True:
sucess, img = capture.read()
img = cv2.Canny(img, 100, 100)
cv2.imshow("Webcam", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
这可能晚了,但请检查一下 pyvirtualcam
先安装它:
pip install pyvirtualcam
你可以这样做:
import pyvirtualcam
import numpy as np
with pyvirtualcam.Camera(width=1280, height=720, fps=30) as cam:
while True:
frame = np.zeros((cam.height, cam.width, 4), np.uint8) # RGBA
frame[:,:,:3] = cam.frames_sent % 255 # grayscale animation
frame[:,:,3] = 255
cam.send(frame)
cam.sleep_until_next_frame()
cam.sleep_until_next_frame()