python - 如何在openCV中获取带有视频输入的屏幕大小?
问题描述
我正在使用 OpenCV 进行人脸检测,我需要获取屏幕上人脸位置的坐标。如何用python得到它?
解决方案
由于您似乎尚未浏览任何其他内容,因此我建议您首先对其进行一些研究。
参考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
推荐阅读
- django - 如何使用 Google Drive 为部署在 Heroku 中的 Django 应用程序保存媒体文件?
- android - Android Studio 中突出显示的 RxAndroid `Observable...subscribe`
- android - XML重复属性android studio
- python-3.x - WTForms HiddenField() POST 后不包含任何数据
- json - 如何将 URLSession 中的嵌套原始 JSON 发送到 Vapor API?
- ios - xcodebuild 在仅请求 tvOS 时构建 iOS 和 tvOS 目标
- methods - 是否有方法注释表明它与指定的功能接口匹配?
- excel - 从 For Next 循环中剪切和粘贴的代码。我怎样才能专门使用 For Each 循环来做到这一点?
- apache-spark - 火花数据框查询总和
- javascript - 使用 javascript 中的正则表达式过滤降价中的列表标记