DLIB庫example中face_detection_ex學習與實現
阿新 • • 發佈:2018-11-03
上原始碼
#include <dlib/image_processing/frontal_face_detector.h> #include <dlib/gui_widgets.h> #include <dlib/image_io.h> #include <iostream> using namespace dlib; using namespace std; // ---------------------------------------------------------------------------------------- int main(int argc, char** argv) { try { if (argc == 1) { cout << "Give some image files as arguments to this program." << endl; return 0; } frontal_face_detector detector = get_frontal_face_detector(); image_window win; // Loop over all the images provided on the command line. for (int i = 1; i < argc; ++i) { cout << "processing image " << argv[i] << endl; array2d<unsigned char> img; load_image(img, argv[i]); pyramid_up(img); // Now tell the face detector to give us a list of bounding boxes // around all the faces it can find in the image. std::vector<rectangle> dets = detector(img); cout << "Number of faces detected: " << dets.size() << endl; // Now we show the image on the screen and the face detections as // red overlay boxes. win.clear_overlay(); win.set_image(img); win.add_overlay(dets, rgb_pixel(255,0,0)); cout << "Hit enter to process the next image..." << endl; cin.get(); } } catch (exception& e) { cout << "\nexception thrown!" << endl; cout << e.what() << endl; } }
frontal_face_detector:
是object_detector一樣的,該類的物件是用於檢測影象中的物件的位置的工具。特別是,它是一個簡單的容器,用於聚合影象掃描器物件的例項(scan_fhog_pyramid,scan_image_pyramid,scan_image_boxes或 scan_image_custom)
typedef object_detector<scan_fhog_pyramid<pyramid_down<6> > > frontal_face_detector;
get_frontal_face_detector():
返回一個能夠識別人臉的並且為 frontal_face_detector型別的容器
array2d
此物件表示二維物件陣列。 灰度圖
pyramid_up(img)
向上取樣,放大一倍
std::vector<rectangle> dets = detector(img)
這個運算子過載是在object_detector裡面的。返回一個影象的vector<rectangle>。
效果
程式要用cmd來執行