如何在 openCV 中使用视频输入获取屏幕大小?

How to get size of screen with videoinput in openCV?

我正在使用 OpenCV 进行人脸检测,我需要获取屏幕上人脸位置的坐标。如何用python得到它?

由于您似乎还没有浏览任何其他内容,我建议您首先对相同的内容进行一些研究。

参考文献 1:Haar Cascades, 参考2:Dlib, Reference 3: Face Recognition

以下代码将帮助您使用 haar 级联方法进行人脸检测。

import numpy as np
import cv2

# the xml files are present in the data folder of the opencv installation, should load automatically.
# You can download the xml from:
# https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_default.xml

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

img = cv2.imread('image.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
    print (x, y, w, h) #Print location of the face => x co-ord, y co-ord, width and height