flandmark人臉檢測庫的用法

2021-08-08 22:36:07 字數 1832 閱讀 5605

之前用dlib庫檢測人臉的68個特徵點,雖然特徵點比較準確,但如果被檢測比較大,效率就比較低。而且臉部模型資料檔案shape_predictor_68_face_landmarks.dat有95mb太大了。

後來發現flandmark這樣乙個輕量級的人臉檢測庫,大概只有5mb左右。檢測的特徵點少一些,只有8個。不過如果作一般用途,這8個點足夠了。下面簡單貼出相關**。

主要參考來自於:

宣告所需的變數

#include "libflandmark/flandmark_detector.h"

/** 5 1 2 6**

* 0/7**

* 3 4**/

cvhaarclassifiercascade* facecascade;

flandmark_model * model;

初始化:

hsfaceflandmark::hsfaceflandmark()

model = flandmark_init(flandmarkmodelfilename);

if (model == 0)

}

8個關鍵點檢測的api

int detectfaceinimage(iplimage *orig, cv::mat& img, double *landmarks)

; // smallest face size.

cvsize minfeaturesize = cvsize(80, 80);

int flags = cv_haar_do_canny_pruning;

// how detailed should the search be.

float search_scale_factor = 1.1f;

cvmemstorage* storage;

cvseq* rects;

int nfaces;

storage = cvcreatememstorage(0);

cvclearmemstorage(storage);

// detect all the faces in the greyscale image.

rects = cvhaardetectobjects(input, facecascade, storage, search_scale_factor, 2, flags, minfeaturesize);

nfaces = rects->total;

for (int iface = 0; iface < (rects ? nfaces : 0); ++iface)

}// if (nfaces > 0)

//

cvreleasememstorage(&storage);

cvreleaseimage(&input);

return nfaces;

}

用法:

//cv::mat& img 這裡就是需要檢測人臉的,我這裡都是用cv::mat作為輸入格式

iplimage frameret = iplimage(img);

//這裡存放檢測到人臉8個特徵點的座標

double landmarks[max_landmark_point * 2] = ;

int facenum = detectfaceinimage(&frameret, img, landmarks);

if(facenum > 0)

}//我這裡只需要8個點座標,frameret其實沒什麼用

Python Dlib庫人臉檢測

一些關於dlib的介紹 import dlib import cv2 使用 dlib 的正面人臉檢測器 frontal face detector detector dlib.get frontal face detector 所在路徑 生成 dlib 的影象視窗 win dlib.image wi...

使用Dlib庫進行人臉檢測,人臉對齊和人臉識別

在之前的部落格中,我已經介紹了如何使用dlib 18.17進行人臉檢測和人臉對齊。windows10 vs2013環境下dlib庫的編譯與使用 鄔小陽 使用dlib庫進行人臉檢測與對齊 鄔小陽 最近又看dlib官網時,發現dlib 19.3開始又加入了人臉識別dnn模型,而且在lfw上取得了99.3...

使用Dlib庫進行人臉檢測,人臉對齊和人臉識別

在之前的部落格中,我已經介紹了如何使用dlib 18.17進行人臉檢測和人臉對齊。windows10 vs2013環境下dlib庫的編譯與使用 鄔小陽 使用dlib庫進行人臉檢測與對齊 鄔小陽 最近又看dlib官網時,發現dlib 19.3開始又加入了人臉識別dnn模型,而且在lfw上取得了99.3...