• 2020/4/3


    今日学习

    • 搭好dlib c++的环境
    • 三节课
    • 写完作业

    今日杂碎记录

    dlib 的编译

    官网教程,稳得一批

    CMakeLists.txt 的编写

    project(dlib_test) # 工程名字
    find_package(OpenCV REQUIRED) # 使用opencv , 注意括号中的大小写
    cmake_minimum_required(VERSION 2.8.12) # cmake 版本
    
    # cmake needs is the dlib source code folder and it will take care of everything.
    add_subdirectory(../dlib dlib_build) # 需要编译的添加子目录
    
    include_directories( ${OpenCV_INCLUDE_DIRS} ) 
    add_executable(dlib_test main.cpp) # 要编译的文件, 这里的dlib_test 是生成的可执行文件的名字
    target_link_libraries( dlib_test ${OpenCV_LIBS} ) # dlib_test 是生成的可执行文件的名字
    # Finally, you need to tell CMake that this program, assignment_learning_ex,
    # depends on dlib.  You do that with this statement:
    target_link_libraries(dlib_test dlib::dlib) # dlib_test 是生成的可执行文件的名字
    
    

    dlib的CMakeLists.txt编写详细规则
    opencv的CMakeLists.txt编写详细规则
    更多关于CMakeLists.txt 的编写

    C++中的rectangle API

    void rectangle(Mat& img, Point pt1,Point pt2,const Scalar& color, int thickness=1, int lineType=8, int shift=0)
     void rectangle(Mat& img, Rect rec, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )
    

    dlib C++ 检测特征点

    #include <dlib/opencv.h>
    #include <opencv2/opencv.hpp>
    #include <dlib/image_processing/frontal_face_detector.h>
    #include <dlib/image_processing/render_face_detections.h>
    #include <dlib/image_processing.h>
    #include <dlib/gui_widgets.h>
     
    using namespace dlib;
    using namespace std;
     
    int main()
    {
    	try
    	{
    		cv::VideoCapture cap(0);
    		if (!cap.isOpened())
    		{
    			cerr << "Unable to connect to camera" << endl;
    			return 1;
    		}
     
    		//image_window win;
     
    		// Load face detection and pose estimation models.
    		frontal_face_detector detector = get_frontal_face_detector();
    		shape_predictor pose_model;
    		deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;
     
    		// Grab and process frames until the main window is closed by the user.
    		while (cv::waitKey(30) != 27)
    		{
    			// Grab a frame
    			cv::Mat temp;
    			cap >> temp;
     
    			cv_image<bgr_pixel> cimg(temp); //这一行一定不能少, dlib和opencv中的img格式保存不一样
    			// Detect faces 
    			std::vector<rectangle> faces = detector(cimg);
    			// Find the pose of each face.
    			std::vector<full_object_detection> shapes;
    			for (unsigned long i = 0; i < faces.size(); ++i)
    				shapes.push_back(pose_model(cimg, faces[i]));
    	
    			if (!shapes.empty()) {
    				for (int i = 0; i < 68; i++) {
    					circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 3, cv::Scalar(0, 0, 255), -1);
    					//	shapes[0].part(i).x();//68个
    				}
    			}
    			//Display it all on the screen
    			imshow("Dlib特征点", temp);
     
    		}
    	}
    	catch (serialization_error& e)
    	{
    		cout << "You need dlib's default face landmarking model file to run this example." << endl;
    		cout << "You can get it from the following URL: " << endl;
    		cout << "   http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
    		cout << endl << e.what() << endl;
    	}
    	catch (exception& e)
    	{
    		cout << e.what() << endl;
    	}
    }
    

    如果标了数字会是这样的。

    dlib 的demo1
    dlib 的demo2

    明天再使用的方法

    FaceDetection
    python 与 C++ dlib人脸检测结果对比

    刷剧时间长了哇,后悔一秒。

  • 相关阅读:
    处理安卓9patch(.9.png)图片
    block 方法参数中带有block 如何生成 如何使用
    hash_hmac
    日期(NSDate)是NSString类的格式(stringWithFormat)
    UITableView刷新单个cell或者单个Section
    iOS enum 定义与使用
    拼接url地址
    demo效果
    好东西
    关于ios7 navigationController中view的frame以及坐标点
  • 原文地址:https://www.cnblogs.com/hichens/p/12626286.html
Copyright © 2020-2023  润新知