dlib, cmake, c++, and linux
Download
git clone https://github.com/davisking/dlib.git2
Install and Use
under the folder of dlib, do the following:
mkdir build; cd build; cmake .. ; cmake --build .
For Python3
python setup.py install
python3 opencv_webcam_face_detection.py
For C++
Create a file at a new folder: `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();
}
Create CMakelists.txt
project(test_dlib)
cmake_minimum_required(VERSION 2.8)
add_subdirectory(../dlib dlib_build) # '../dlib' is the source code folder; built files will be put into 'dlib_build'
add_executable(a 3d_point_cloud_ex.cpp) # generate an excuteable file named 'a'
target_link_libraries(a dlib::dlib) # link dlib to a; a needs this lib to work
tips:../dlib can be an absolute path
Compile
mkdir build
cd build
cmake ..
make
Run
./a
For 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 .
-- 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
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参数了。