7-24(linux dlib c++初识)

环境准备:

官网Download

解压缩:

tar -xjf dlib-19.17.tar.bz2

编译dlib:

进入~/dlib-19.17 下
mkdir build
cd build
cmake …
make release=1

编译例程:

进入~/dlib-19.17$ 下
cd examples #进入dlib下的examples文件夹
mkdir build #新建build文件夹,存放cmake编译后的执行文件
cd build #进入新建好的build文件夹
cmake … #cmake编译examples整个文件夹
cmake --build . --config Release

8-5记录:
下载解压好之后,直接在examples内用g++编译例程:

jiang@jiang-TM1707:~/dlib-19.17/examples$ g++ -o …/out -std=c++11 -O3 -I… …/dlib/all/source.cpp -lpthread -lX11 face_detection_ex.cpp

Note also that if you want to work with jpeg/png/gif files using dlib then you will need to link your program with libjpeg, libpng, and/or libgif. You also need to tell dlib about this by defining the DLIB_JPEG_SUPPORT, DLIB_PNG_SUPPORT, and DLIB_GIF_SUPPORT preprocessor directives. How you “link to libjpeg/libpng/libgif” varies from platform to platform. On UNIX machines you usually just add a -ljpeg, -lpng, or -lgif switch to your compiler (after installing the libraries). On windows it’s less well defined. So dlib comes with a copy of libjpeg and libpng in the dlib/external folder so you can statically compile them into your application if no system wide version is available on your machine. If all this talk about linking is confusing to you then just use CMake. It will set this all up for you.
Note also that if you want to work with jpeg/png/gif files using dlib then you will need to link your program with libjpeg, libpng, and/or libgif. You also need to tell dlib about this by defining the DLIB_JPEG_SUPPORT, DLIB_PNG_SUPPORT, and DLIB_GIF_SUPPORT preprocessor directives. How you “link to libjpeg/libpng/libgif” varies from platform to platform. On UNIX machines you usually just add a -ljpeg, -lpng, or -lgif switch to your compiler (after installing the libraries). On windows it’s less well defined. So dlib comes with a copy of libjpeg and libpng in the dlib/external folder so you can statically compile them into your application if no system wide version is available on your machine. If all this talk about linking is confusing to you then just use CMake. It will set this all up for you.
还请注意,如果要使用dlib处理jpeg/png/gif文件,则需要将程序链接到libjpeg、libpng和/或libgif。您还需要通过定义dlib_jpeg_支持、dlib_png_支持和dlib_gif_支持预处理器指令来告诉dlib关于这一点。“链接到libjpeg/libpng/libgif”的方式因平台而异。在UNIX机器上,通常只需添加-ljpeg、-lpng或-lgif开关到编译器(在安装库之后)。在Windows上,它的定义不太明确。因此,dlib在dlib/external文件夹中附带了libjpeg和libpng的副本,因此,如果您的计算机上没有可用的系统范围版本,您可以将它们静态编译到应用程序中。如果所有关于链接的讨论都让您感到困惑,那么只需使用cmake。这一切都会为你准备好的。

我尝试了链接静态库,即-L/home/jiang/dlib-19.17/dlib/external -lpng -ljpeg,但没有效果;也尝试链接已安装的 -lpng -ljpeg,也没有效果。

最终解决办法,利用opencv来读取图像,然后转成dlib的 array2d

#include <dlib/opencv.h>  
#include <opencv2/opencv.hpp>  
            //array2d<unsigned char> img;
            //load_image(img, argv[i]);
	        cv::Mat cvimg = cv::imread(argv[i],0);
	        cv_image<unsigned char> img(cvimg);

Makefile文件:

CC = g++
BOOSTLIB = -std=c++11 -std=c++11 -O3 -I.. ../dlib/all/source.cpp -lpthread -lX11

LIB = $(shell pkg-config --libs opencv)
INC = $(shell pkg-config --cflags opencv)
SRCFILE = face_detection.cpp
DEBUGFLG=
all:
		$(CC) $(SRCFILE) $(DEBUGFLG) $(INC) $(BOOSTLIB) $(LIB) -o out
clean:
		rm -rf out
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值