OpenCV在视频文件中找出你需要的面孔

《OpenCV系列教程》
项目位置:OpenCV-Sample
代码位置:23-LearnEigenFace.py
同时所需要的资源也都在项目里面

import cv2
import os

cameraCapture = cv2.VideoCapture('./res/test.mp4')

detector = cv2.CascadeClassifier(os.getcwd() + '/XML/haarcascade_frontalface_alt_tree.xml')

model_zxc = cv2.face.EigenFaceRecognizer_create()
model_zxc.read(os.getcwd() + '/XML/actor_zxc.xml')
print(os.getcwd() + '/XML/actor_cl.xml')

cv2.namedWindow('Test camera')
success, frame = cameraCapture.read()
while success:
    success, frame = cameraCapture.read()
    rects = detector.detectMultiScale(frame, scaleFactor=1.1, minNeighbors=2, minSize=(100, 100),
                                      flags=cv2.CASCADE_SCALE_IMAGE)
    if len(rects) > 0:
        for (x, y, w, h) in rects:
            face = cv2.resize(frame[y:y+h, x:x+w], (200, 200))
            gray = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
            params = model_zxc.predict(gray)
            print(params)
            if params[1] < 5500.0:
                cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 1)
            else:
                cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 1)
        if cv2.waitKey(1) == 27:
            break
        cv2.imshow('Test camera', frame)

cv2.destroyAllWindows()
cameraCapture.release()

测试结果和上一篇查找图片效果的差不多,还是很差。闸值5500.0是我自己设定的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值