c++机器学习库dlib编译及应用测试

40 篇文章 32 订阅
35 篇文章 6 订阅

1 dlib介绍

Dlib是一个现代的C ++工具箱,其中包含机器学习算法和工具,这些工具和工具可以用C ++创建复杂的软件来解决实际问题。 它在工业和学术界广泛使用,包括机器人技术,嵌入式设备,移动电话和大型高性能计算环境。  Dlib的开源许可使您可以免费在任何应用程序中使用它。
Dlib包含各种机器学习算法。 所有这些都设计为高度模块化,易于执行且通过干净现代的C ++ API易于使用。 它被广泛用于机器人,嵌入式设备,移动电话和大型高性能计算环境中。
http://dlib.net/

https://github.com/davisking/dlib 

2 dlib编译

dlib的官网没有提供编译好的库文件,需要自己编译,不过也比较简单。从官网下载dlib源码

http://dlib.net/files/dlib-19.21.zip

然后通过cmake编译

打开cmake,设计源码所在路径,设置编译生成visual studio项目所在的文件夹,点击configure,选择编译器visual studio 2019 和x64版本,设置如下信息,然后继续configure,没有错误,即可generate生成项目,然后编译项目, 分别编译debug版本和release版本,以及通过instal生成头文件。

这个库生成的是静态库文件,只有头文件和lib文件,没有dll文件。两个lib文件分别是

dlib19.21.0_debug_64bit_msvc1928.lib

dlib19.21.0_release_64bit_msvc1928.lib

3 dlib测试应用

首先在visual studio创建c++ console项目,与其他库的设置方法一致,需要设置dlib的头文件所在目录,lib文件所在目录,以及dlib的名称。

然后测试官网给出的例子

http://dlib.net/3d_point_cloud_ex.cpp.html

// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt 
/* 
This is an example illustrating the use of the perspective_window tool
in the dlib C++ Library.  It is a simple tool for displaying 3D point      
clouds on the screen.
*/

#include <iostream>
#include <dlib/gui_widgets.h> 
#include <dlib/image_transforms.h> 
#include <cmath>  
using namespace dlib;
using namespace std;

int main()
{
	std::cout << "Hello World!\n";
	// 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();
	return EXIT_SUCCESS;
}

运行结果如下,这个例子生成了三维空间的点云,并进行了可视化,这个库提供的三维可视化窗口也不错,可以旋转缩放等。

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

oceanstonetree

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值