簡要:
LBPH(Local Binary PatternsHistograms)局部二進制編碼直方圖,建立在LBPH基礎(chǔ)之上的人臉識別法基本思想如下:首先以每個像素為中心,判斷與周圍像素灰度值大小關(guān)系,對其進行二進制編碼,從而獲得整幅圖像的LBP編碼圖像;再將LBP圖像分為個區(qū)域,獲取每個區(qū)域的LBP編碼直方圖,繼而得到整幅圖像的LBP編碼直方圖,通過比較不同人臉圖像LBP編碼直方圖達到人臉識別的目的,其優(yōu)點是不會受到光照、縮放、旋轉(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ù),用來訓練的圖像vector<Mat>images和標簽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); //將最后一個樣本作為測試樣本 Mat testSample = images[images.size() - 1]; int testLabel = labels[labels.size() - 1]; //刪除列表末尾的元素 images.pop_back(); labels.pop_back(); //加載,訓練,預(yù)測 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; }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站jinyejixie.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)頁標題:OpencvLBPH人臉識別算法詳解-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://jinyejixie.com/article16/depogg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、面包屑導航、服務(wù)器托管、軟件開發(fā)、品牌網(wǎng)站制作、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)