1. 程式人生 > >【OpenCV】Dlib人臉關鍵點檢測順序

【OpenCV】Dlib人臉關鍵點檢測順序

dlib19.2 只可以使用VS2015update3進行cmake,不然會提示你c++11特性不能夠支援,導致編譯不通過。

- 人臉關鍵點檢測關鍵程式碼

Mat ProcessFace::DrawDetectedFace(){

    Mat imgDrawFace = srcImage;//這個變數是指向待檢測人臉的圖片


    for (int i = 0; i < (detectedFaceData ? *detectedFaceData : 0); i++)
    {

        short * p = ((short*)(detectedFaceData + 1
)) + 6 * i; Rect opencvRect(p[0], p[1], p[2], p[3]); int x = p[0]; int y = p[1]; int w = p[2]; int h = p[3]; int neighbors = p[4]; printf("face_rect=[%d, %d, %d, %d], neighbors=%d\n", x, y, w, h, neighbors); Point left(x, y); Point right(x + w, y + h); cv::rectangle(imgDrawFace, left, right, Scalar(230
, 255, 0), 4); dlib::rectangle dlibRect((long)opencvRect.tl().x, (long)opencvRect.tl().y, (long)opencvRect.br().x - 1, (long)opencvRect.br().y - 1); dlib::full_object_detection shape = sp(dlib::cv_image<uchar>(srcGrayImage), dlibRect); for (int i = 0; i<shape.num_parts(); i++) { shape.part(0
).x(); //point pt = shape.part(i); int x = shape.part(i).x(); int y = shape.part(i).y(); char str[3]; itoa(i, str, 10); line(imgDrawFace, Point(shape.part(i).x(), shape.part(i).y()), Point(shape.part(i).x(), shape.part(i).y()), Scalar(0, i*3, 255), 2); putText(imgDrawFace, str, Point(shape.part(i).x(), shape.part(i).y()), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 255, 0), 2); } //std::vector<dlib::full_object_detection> shapes; //shapes.push_back(shape);//把點儲存在了shape中 //dlib::array<dlib::array2d<dlib::rgb_pixel>> face_chips; //extract_image_chips(dlib::cv_image<uchar>(srcGrayImage), get_face_chip_details(shapes), face_chips); //imgDrawFace = dlib::toMat(face_chips[0]); //cvtColor(imgDrawFace, imgDrawFace, CV_BGR2GRAY); } return imgDrawFace; }

- 人臉68個關鍵點分佈情況

這裡寫圖片描述