关闭页面特效

安装dlib C++

1|0环境


  • Ubuntu18.04
  • dlib19

2|0下载安装


2|1下载


从github下载 dlib

git clone https://github.com/davisking/dlib.git

2|2安装


在dlib目录下, 依次执行。

mkdir build; cd build; cmake .. ; cmake --build .

3|0Python使用


python setup.py install

安装成功

python_examples 目录下有很多例子, 可以试试

python opencv_webcam_face_detection.py # 打开电脑摄像头检测人脸

4|0C++使用


4|1创建测试文件 3d_point_cloud_ex.cpp


#include <dlib/gui_widgets.h> #include <dlib/image_transforms.h> #include <cmath> using namespace dlib; using namespace std; int main() { // Let's make a point cloud that looks like a 3D spiral. std::vector<perspective_window::overlay_dot> points; dlib::rand rnd; for (double i = 0; i < 20; i+=0.001) { // Get a point on a spiral dlib::vector<double> val(sin(i),cos(i),i/4); // Now add some random noise to it dlib::vector<double> temp(rnd.get_random_gaussian(), rnd.get_random_gaussian(), rnd.get_random_gaussian()); val += temp/20; // Pick a color based on how far we are along the spiral rgb_pixel color = colormap_jet(i,0,20); // And add the point to the list of points we will display points.push_back(perspective_window::overlay_dot(val, color)); } // Now finally display the point cloud. perspective_window win; win.set_title("perspective_window 3D point cloud"); win.add_overlay(points); win.wait_until_closed(); }

4|2编写CMakelists.txt


project(test_dlib) cmake_minimum_required(VERSION 2.8) add_subdirectory(../dlib dlib_build) # 找到dlib下的源码文件 add_executable(hc 3d_point_cloud_ex.cpp) # 生成执行文件名字为hc target_link_libraries(hc dlib::dlib) # hc这个执行文件需要链接到 dlib

说明:../dlib 可以使相对路径也可以是绝对路径

4|3编译


mkdir build cd build cmake .. make

4|4执行


.hc

注:中间遇到一些warning没有关系

5|0GPU版本使用


使用GPU则需要添加如下几个参数

git clone https://github.com/davisking/dlib.git cd dlib mkdir build cd build cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 cmake --build .

cmake 成功找到cuda和cudnn结果是这样的

-- Found CUDA: /usr/local/cuda-9.2 (found suitable version "9.2", minimum required is "7.5") -- Looking for cuDNN install... -- Found cuDNN: /usr/local/cuda-9.2/lib64/libcudnn.so -- Building a CUDA test project to see if your compiler is compatible with CUDA... -- Checking if you have the right version of cuDNN installed. -- Enabling CUDA support for dlib. DLIB WILL USE CUDA -- C++11 activated. -- Configuring done -- Generating done -- Build files have been written to: /home/xxx/dlib/build

给python使用。

cd .. python setup.py install --set USE_AVX_INSTRUCTIONS=yes --set DLIB_USE_CUDA=yes 多数博客会写成这样 #python setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA # dlib 已经取消yes参数了。

安装成功

import dlib dlib.DLIB_USE_CUDA # 结果为True则可以使用了

6|0参考



__EOF__

作  者Hichens
出  处https://www.cnblogs.com/hichens/p/12666298.html
关于博主:莫得感情的浅度学习机器人
版权声明:@Hichens
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!

posted @   hichens  阅读(1785)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
点击右上角即可分享
微信分享提示