Opencv LBPH人臉識(shí)別算法詳解
簡(jiǎn)要:
LBPH(Local Binary PatternsHistograms)局部二進(jìn)制編碼直方圖,建立在LBPH基礎(chǔ)之上的人臉識(shí)別法基本思想如下:首先以每個(gè)像素為中心,判斷與周?chē)袼鼗叶戎荡笮£P(guān)系,對(duì)其進(jìn)行二進(jìn)制編碼,從而獲得整幅圖像的LBP編碼圖像;再將LBP圖像分為個(gè)區(qū)域,獲取每個(gè)區(qū)域的LBP編碼直方圖,繼而得到整幅圖像的LBP編碼直方圖,通過(guò)比較不同人臉圖像LBP編碼直方圖達(dá)到人臉識(shí)別的目的,其優(yōu)點(diǎn)是不會(huì)受到光照、縮放、旋轉(zhuǎn)和平移的影響。
#include<opencv2\opencv.hpp> #include<opencv2\face.hpp> using namespace cv; using namespace face; using namespace std; char win_title[40] = {}; int main(int arc, char** argv) { //namedWindow("input",CV_WINDOW_AUTOSIZE); //讀入模型需要輸入的數(shù)據(jù),用來(lái)訓(xùn)練的圖像vector<Mat>images和標(biāo)簽vector<int>labels string filename = string("path.txt"); ifstream file(filename); if (!file) { printf("could not load file"); } vector<Mat>images; vector<int>labels; char separator = ';'; string line,path, classlabel; while (getline(file,line)) { stringstream lines(line); getline(lines, path, separator); getline(lines, classlabel); //printf("%d\n", atoi(classlabel.c_str())); images.push_back(imread(path, 0)); labels.push_back(atoi(classlabel.c_str()));//atoi(ASCLL to int)將字符串轉(zhuǎn)換為整數(shù)型 } int height = images[0].rows; int width = images[0].cols; printf("height:%d,width:%d\n", height, width); //將最后一個(gè)樣本作為測(cè)試樣本 Mat testSample = images[images.size() - 1]; int testLabel = labels[labels.size() - 1]; //刪除列表末尾的元素 images.pop_back(); labels.pop_back(); //加載,訓(xùn)練,預(yù)測(cè) Ptr<LBPHFaceRecognizer> model = LBPHFaceRecognizer::create(); model->train(images, labels); int predictedLabel = model->predict(testSample); printf("actual label:%d,predict label :%d\n", testLabel, predictedLabel); int radius = model->getRadius(); int neibs = model->getNeighbors(); int grad_x = model->getGridX(); int grad_y = model->getGridY(); double t = model->getThreshold(); printf("radius:%d\n", radius); printf("neibs:%d\n", neibs); printf("grad_x:%d\n", grad_x); printf("grad_y:%d\n", grad_y); printf("threshold:%.2f\n", t); waitKey(0); return 0; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- OpenCV + MFC實(shí)現(xiàn)簡(jiǎn)單人臉識(shí)別
- Kears+Opencv實(shí)現(xiàn)簡(jiǎn)單人臉識(shí)別
- opencv實(shí)現(xiàn)簡(jiǎn)單人臉識(shí)別
- opencv 做人臉識(shí)別 opencv 人臉匹配分析
- 基于OpenCV的PHP圖像人臉識(shí)別技術(shù)
- OPENCV+JAVA實(shí)現(xiàn)人臉識(shí)別
- python+opencv實(shí)現(xiàn)的簡(jiǎn)單人臉識(shí)別代碼示例
- 詳解如何用OpenCV + Python 實(shí)現(xiàn)人臉識(shí)別
- OpenCV實(shí)現(xiàn)人臉識(shí)別
- OpenCV實(shí)現(xiàn)人臉識(shí)別簡(jiǎn)單程序
相關(guān)文章
C++ string和wstring相互轉(zhuǎn)換方式
這篇文章主要介紹了C++ string和wstring相互轉(zhuǎn)換方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02C++動(dòng)態(tài)調(diào)用動(dòng)態(tài)鏈接庫(kù)(DLL或SO)的方法實(shí)現(xiàn)
動(dòng)態(tài)鏈接庫(kù)是一種Windows操作系統(tǒng)下常見(jiàn)的可執(zhí)行文件格式,它包含了一些可被其他應(yīng)用程序調(diào)用的函數(shù)和數(shù)據(jù),本文主要介紹了C++動(dòng)態(tài)調(diào)用動(dòng)態(tài)鏈接庫(kù)(DLL或SO),感興趣的可以了解一下2024-01-01MATLAB實(shí)現(xiàn)五子棋游戲(雙人對(duì)戰(zhàn)、可悔棋)
這篇文章主要為大家詳細(xì)介紹了MATLAB實(shí)現(xiàn)五子棋游戲,可以進(jìn)行雙人對(duì)戰(zhàn)、也可悔棋,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-06-06C++實(shí)現(xiàn)快捷店會(huì)員管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)快捷店會(huì)員管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03