【发布时间】:2021-06-20 18:33:26
【问题描述】:
我正在尝试使用 OpenCV 检测人脸并在其周围绘制一个矩形,然后将其输出到虚拟相机。我正在使用pyvirtualcam 但是,我不知道如何将图像从 OpenCV VideoCapture 转换为 pyvirtualcam 使用的图像格式。由于我缺乏知识,我不知道它们中的任何一种是什么格式,或者如何将一种转换为另一种。如何将图像从 OpenCV 转换为我可以输出的东西?
import cv2
import pyvirtualcam
import cvlib as cv
video = cv2.VideoCapture(0)
with pyvirtualcam.Camera(1280, 720, 20) as camera:
while True:
ret, im = video.read()
faces, confidences = cv.detect_face(im)
for face in faces:
Rect(face[0], face[1], face[2], face[3]).draw(im)
camera.send(im)
camera.sleep_until_next_frame()
import cv2
class Rect:
def __init__(self, x0, y0, x1, y1):
self.points = [
(x0, y0),
(x1, y1)
]
self.origin = (x0, y0)
self.width = abs(x1 - x0)
self.height = abs(y1 - y0)
def draw(self, im, color=(0, 255, 0), width=3):
cv2.rectangle(
im,
self.points[0],
self.points[1],
color,
width
)
【问题讨论】: