文章地址:https://blog.csdn.net/zaibeijixing/article/details/80595184
文章地址:https://blog.csdn.net/zaibeijixing/article/details/80595184
Win10 + vs2015 + dlib-19.7 + CMake_cmd
(配置新電腦,把之前筆記整理髮布、分享)
一:必備
(1)下載並解壓當前最新版本dlib-19.7。
(2)下載並解壓cmake-3.10.0-win64-x64,添加系統環境變量:Path——D:\tool_2\cmake310\cmake-3.10.0-win64-x64\bin
二:cmake
用命令行的形式將dlib-19.7文件生成.lib文件。詳細步驟如下:
①在dlib-版本號文件夾下打開命令提示符(shift加右鍵),以添加make命令
②mkdir build (作用:在當前文件夾下新建“build”文件夾)
③cd build (命令行切換到build文件夾路徑)
④cmake -G “Visual Studio 14 2015 Win64” (用win64版vs2015(代號14) 編譯 )
⑤cmake --build . -- config Release (生成Relaese版本.lib)
【注】四行代碼一行一行添加,否則④佔用時間長,⑤執行不到;⑤的Release改爲Debug即可生成Debug版.lib;生成的文件在新建的build\dlib文件夾內。
三:新建VS程序,項目配置屬性 (使用Release_x64模式)
只需要添加庫目錄和附加依賴項即可。
(1)添加庫目錄
(2)附加依賴項
(3)其它雜項
四:運行(Release_x64)
#include<dlib/image_processing/frontal_face_detector.h>
#include<dlib\image_processing\render_face_detections.h>
#include<dlib\image_processing.h>
#include<dlib\gui_widgets.h>
#include<dlib\image_io.h>
#include<iostream>
#include<vector>
using namespace dlib;
using namespace std;
int main(int argc, char **argv)
{
try
{
frontal_face_detector detector = get_frontal_face_detector();
image_window win;//一個顯示窗口
array2d<unsigned char> img;
cout << "processing image" << argv[1] << endl;
load_image(img, argv[1]);//加載一張圖片
pyramid_up(img);//對圖像進行上採樣,檢測更小的人臉
//開始檢測,返回一系列的邊界框
std::vector<rectangle> dets = detector(img);//detector()函數檢測人臉,返回一系列邊界盒子
cout << "Number of faces detected:" << dets.size() << endl;//re
//在原圖上顯示結果
win.clear_overlay();
win.set_image(img);
win.add_overlay(dets, rgb_pixel(255, 0, 0));
cout << "Hit enter to process the next image..." << endl;
cin.get();
}
catch (const std::exception& e)
{
cout << "\nexception thrown!" << endl;
cout << e.what() << endl;
}
getchar();
}
運行結果:
可以轉載分享,但需在文章開頭註明本文原始鏈接:https://blog.csdn.net/zaibeijixing/article/details/80595184