python调用BaiDu-Api和opencv进行人脸检测

BaiDu-API人脸检测:

import cv2  
from aip import AipFace  
""" 你的 APPID AK SK """  
APP_ID = ' '  
API_KEY = ' '  
SECRET_KEY = ' '  
client = AipFace(APP_ID, API_KEY, SECRET_KEY)  
def get_file_content(filePath):  
    with open(filePath, 'rb') as fp:  
        return fp.read()  
image = get_file_content(r'2.jpg')  
""" 如果有可选参数 """  
options = {}  
options["max_face_num"] = 30  
""" 带参数调用人脸检测 """  
result=client.detect(image, options)  
print(result['result_num'])  
img=cv2.imread(r'2.jpg')  
for i in xrange(result['result_num']):  
    x=result['result'][i]['location']['left']  
    h=result['result'][i]['location']['height']  
    y=result['result'][i]['location']['top']-int(h*0.5)  
    w=result['result'][i]['location']['width']  
    cv2.rectangle(img,(x,y),(x+w,y+h+int(h*0.5)),(0,0,255),2)  
cv2.imshow("result",img)  
cv2.waitKey(0) 

opencv人脸检测:

import cv2  
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')  
img = cv2.imread('2.jpg')  
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  
faces = face_cascade.detectMultiScale(gray, 1.1, 3)  
for (x,y,w,h) in faces:  
  img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)  
cv2.imshow('img',img)  
cv2.waitKey(0) 

BaiDu-API脸检测结果:


opencv人脸检测结果:


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值