習(xí)】DLIB關(guān)鍵點檢測初探)
主要還是項目要求吧需要進行人臉68個關(guān)鍵點檢測然后網(wǎng)上尋找一番發(fā)現(xiàn)DLIB庫使用還是挺高的然后就在上篇博客中簡單記錄了一下DLIB 19.17的配置過程但是還是要嘗試下它的程序的。LZ修改過的版本由于保密原因就不進行展示(≧▽≦)/啦啦啦給出官方給的源碼吧。#includedlib/image_processing/frontal_face_detector.h#includedlib/image_processing/render_face_detections.h#includedlib/image_processing.h#includedlib/gui_widgets.h#includedlib/image_io.h#includeiostreamusing namespace dlib;using namespace std;// ----------------------------------------------------------------------------------------intmain(intargc,char**argv){try{// This example takes in a shape model file and then a list of images to// process. We will take these filenames in as command line arguments.// Dlib comes with example images in the examples/faces folder so give// those as arguments to this program.//這里要去對應(yīng)的網(wǎng)址下載關(guān)鍵點檢測的數(shù)據(jù)網(wǎng)速還是很渣渣if(argc1){coutCall this program like this:endl;cout./face_landmark_detection_ex shape_predictor_68_face_landmarks.dat faces/*.jpgendl;cout\nYou can get the shape_predictor_68_face_landmarks.dat file from:\n;couthttp://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2endl;return0;}// We need a face detector. We will use this to get bounding boxes for// each face in an image.// 初始化檢測器frontal_face_detector detectorget_frontal_face_detector();// And we also need a shape_predictor. This is the tool that will predict face// landmark positions given an image and face bounding box. Here we are just// loading the model from the shape_predictor_68_face_landmarks.dat file you gave// as a command line argument.shape_predictor sp;deserialize(argv[1])sp;image_window win,win_faces;// Loop over all the images provided on the command line.for(inti2;iargc;i){coutprocessing image argv[i]endl;array2drgb_pixelimg;load_image(img,argv[i]);// Make the image larger so we can detect small faces.pyramid_up(img);// Now tell the face detector to give us a list of bounding boxes// around all the faces in the image.std::vectorrectangledetsdetector(img);coutNumber of faces detected: dets.size()endl;// Now we will go ask the shape_predictor to tell us the pose of// each face we detected.std::vectorfull_object_detectionshapes;for(unsignedlongj0;jdets.size();j){full_object_detection shapesp(img,dets[j]);coutnumber of parts: shape.num_parts()endl;coutpixel position of first part: shape.part(0)endl;coutpixel position of second part: shape.part(1)endl;// You get the idea, you can get all the face part locations if// you want them. Here we just store them in shapes so we can// put them on the screen.shapes.push_back(shape);}// Now lets view our face poses on the screen.win.clear_overlay();win.set_image(img);win.add_overlay(render_face_detections(shapes));// We can also extract copies of each face that are cropped, rotated upright,// and scaled to a standard size as shown here:dlib::arrayarray2drgb_pixelface_chips;extract_image_chips(img,get_face_chip_details(shapes),face_chips);win_faces.set_image(tile_images(face_chips));coutHit enter to process the next image...endl;cin.get();}}catch(exceptione){cout\nexception thrown!endl;coute.what()endl;}}其實上述代碼LZ覺得官方還是很良心的仔細(xì)看看基本上每一步都講解的非常清楚下面是對應(yīng)的CMakeLists.txt。cmake_minimum_required(VERSION 3.14) project(gaze_correction_v1) set(CMAKE_CXX_STANDARD 11) #opencv find_package(OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) #DLIB19.17 add_subdirectory(/home/felaim/Documents/software/dlib-19.17/dlib dlib_build) #include_directories(/usr/local/include/dlib) add_executable(gaze_correction_v1 main.cpp) target_link_libraries(gaze_correction_v1 ${OpenCV_LIBS} dlib::dlib )LZ把include_directories部分給注釋掉了因為不注釋匯報一個錯說DLIB路徑不能include類似錯誤啦(≧▽≦)/啦啦啦后面進行測試通常情況下C版本的基本上都會比python版本的速度要快一些但是LZ運行了上述代碼居然奇慢無比處理一張640*480的圖片要2000多ms然后LZ就瘋狂百度發(fā)現(xiàn)其他小伙伴測試人臉檢測速度也不快大概50ms~100ms左右但是LZ電腦好歹也是i7給我的感覺仿佛是個i3。。。后來總算找到了原因LZ編譯成debug模式DLIB庫在Debug模式下奇慢非常慢最后修改成release模式人臉檢測大概需要38ms關(guān)鍵點檢測需要3ms雖然速度還可以但是遠(yuǎn)遠(yuǎn)達(dá)不到項目要求/(ㄒoㄒ)/~~