首页 > 解决方案 > 如何在openCV中获取带有视频输入的屏幕大小?

问题描述

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

标签: pythonopencv

解决方案


由于您似乎尚未浏览任何其他内容,因此我建议您首先对其进行一些研究。

参考1:Haar Cascades,参考2:Dlib,参考3:人脸识别

以下代码将帮助您使用 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

推荐阅读