利用opecv 和face_recognition库做实时人脸检测

系统:ubantu16.04

编辑器:pycharm

所需python库:python_opencv,face_recognition

代码如下:

import face_recognition
import cv2
camera=cv2.VideoCapture(0)
n=0
while(1):
    if n<10:
        success,img=camera.read()

        face_locations = face_recognition.face_locations(img)
        face_encodings = face_recognition.face_encodings(img, face_locations)
        print(face_locations)
        if len(face_locations)>=1:
            top = face_locations[0][0]
            right = face_locations[0][1]
            bottom = face_locations[0][2]
            left = face_locations[0][3]
            print(top)
            start = (left, top)
            end = (right, bottom)

            color = (55, 255, 155)
            thickness = 3
            img=cv2.rectangle(img, start, end, color, thickness)
            cv2.imshow('img', img)
            n = n + 1
            key = cv2.waitKey(30) & 0xFF
            print(key)

            if key == 113:
                break

    else:
        break

    print(n)

# camera.release()

cv2.destroyAllWindows()

结果如下:





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值