安装dlib C++

摘要:
环境Ubuntu18.04dlib19下载安装下载从github下载dlibgitclonehttps://github.com/davisking/dlib.git安装在dlib目录下,依次执行。mkdirbuild;cdbuild;cmake..;cmake--build.Python使用pythonsetup.pyinstall安装成功python_examples目录下有很多例子,可以试试
环境
  • Ubuntu18.04
  • dlib19
下载安装

下载

从github下载 dlib

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

安装

在dlib目录下, 依次执行。

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

安装dlib C++第1张

Python使用
python setup.py install

安装成功
安装dlib C++第2张

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

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

创建测试文件 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();
}

编写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 可以使相对路径也可以是绝对路径

编译

mkdir build 
cd build 
cmake ..
make

执行

.hc 

安装dlib C++第3张

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

GPU版本使用

使用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则可以使用了

安装dlib C++第4张

参考

免责声明:文章转载自《安装dlib C++》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ASP Blob类型转存为Long Raw类型小区光纤PON接入组网方式与案例下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

(python learn) 5 元组

首先我们要知道,字符串,元组,还有列表等数据类型在python中都属于序列数据类型。对这种数据类型,有一些统一的函数可用,比如: len() 可以返回长度 +可以连接两个序列 *可以重复两个序列中的元素 in可以判断某个元素是否在序列中 max()返回最大元素 min()返回最小元素 cmp()比较两个序列是否相等 下面,我们研究一下元组。 元组是一组被逗...

Python数据可视化--matplotlib

抽象化|具体化: 如盒形图 | 现实中的图 功能性|装饰性:没有装饰和渲染 | 包含艺术性美学上的装饰 深度表达|浅度表达:深入层次的研究探索数据 | 易于理解的,直观的表示 多维度|单一维度:数据的多个层次 | 数据的单一维度 创造性|熟悉性:全新的方式进行可视化 | 被大众接受并且熟悉的方式 新颖性|冗余性: 每个元素只表述一次 | 每个元素表示多次...

Python基础知识

作者:地球的外星人君链接:https://www.zhihu.com/question/20336475/answer/197317130来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 1 算法 1.1 字符串 1.1.1 正则表达式 re 【标准库】 提供基于正则的匹配和替换。 1.1.2 字符集 chardet Home...

python 基本数据类型分析

在python中,一切都是对象!对象由类创建而来,对象所拥有的功能都来自于类。在本节中,我们了解一下python基本数据类型对象具有哪些功能,我们平常是怎么使用的。 对于python,一切事物都是对象,对象基于类创建 一、整数:int 类源码分析 整数如:1,2,3... 2147483647 class int(object): """...

使用python操作mysql数据库

一、pymysql的使用 1.首先在python中安装pymysql模块(CMD窗口命令下)。 pip install pymsql 安装完成后导入import pymysql 2.pyysql 连接数据库的必要参数: 主机、端口、用户名。密码、数据库 注意:pymysql不能提供创建数据库的服务,数据库要提前创建 3.连接步骤: ​ -1. 建立数据库连...

电子公文传输系统团队项目——团队展示

团队成员 20181202 李祎铭 20181209 沙桐 20181215 薛胜瀚 20181216 杨越麒 20181221 曾宇涛(队长) 20181223 何家豪 20181232 冶廷瑞 队名 七侠传 团队项目介绍 电子公文传输系统 队员风采 曾宇涛 代号:长虹剑剑主 风格:沉着冷静 擅长技术:python,php,html 编程兴趣:前端...