日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python dlib 年龄 性别_python dlib学习(一):人脸检测

發布時間:2024/7/23 python 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python dlib 年龄 性别_python dlib学习(一):人脸检测 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、環境安裝

Windows: 舊版本安裝pip install xxx.whl。以下是whl文件地址: ? Python Package Index

? 最新版本安裝:不要嫌麻煩,先裝上visual studio2015 (C++模塊)。

? 具體的記不清了,裝上cmake和boost,然后pip install dlib。

Ubuntu: sudo apt-get install build-essential cmake

? sudo apt-get install libgtk-3-dev

? sudo apt-get install libboost-all-dev

? pip install dlib

? 安裝過程慢,耐心等。

2、程序

? 注:程序中使用了python-opencv、dlib,使用前請配置好環境。 ? 程序中已有注釋。

-*- coding: utf-8 -*-

import sys

import dlib

import cv2

detector = dlib.get_frontal_face_detector() #獲取人臉分類器

# 傳入的命令行參數

for f in sys.argv[1:]:

# opencv 讀取圖片,并顯示

img = cv2.imread(f, cv2.IMREAD_COLOR)

# 摘自官方文檔:

# image is a numpy ndarray containing either an 8bit grayscale or RGB image.

# opencv讀入的圖片默認是bgr格式,我們需要將其轉換為rgb格式;都是numpy的ndarray類。

b, g, r = cv2.split(img) # 分離三個顏色通道

img2 = cv2.merge([r, g, b]) # 融合三個顏色通道生成新圖片

dets = detector(img, 1) #使用detector進行人臉檢測 dets為返回的結果

print("Number of faces detected: {}".format(len(dets))) # 打印識別到的人臉個數

# enumerate是一個Python的內置方法,用于遍歷索引

# index是序號;face是dets中取出的dlib.rectangle類的對象,包含了人臉的區域等信息

# left()、top()、right()、bottom()都是dlib.rectangle類的方法,對應矩形四條邊的位置

for index, face in enumerate(dets):

print('face {}; left {}; top {}; right {}; bottom {}'.format(index,face.left(), face.top(), face.right(), face.bottom()))

# 在圖片中標注人臉,并顯示

left = face.left()

top = face.top()

right = face.right()

bottom = face.bottom()

cv2.rectangle(img, (left, top), (right, bottom), (0, 255, 0), 3)

cv2.namedWindow(f, cv2.WINDOW_AUTOSIZE)

cv2.imshow(f, img)

# 等待按鍵,隨后退出,銷毀窗口

k = cv2.waitKey(0)

cv2.destroyAllWindows()

總結

以上是生活随笔為你收集整理的python dlib 年龄 性别_python dlib学习(一):人脸检测的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。