• 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人脸检测结果对比

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

  • 相关阅读:
    jstl核心标签库
    乱码的解决
    eclipse 中 Servlet 模板代码(其实是代码提示模板)
    因为最近一直在和数据库打交道,所以做了几个小封装
    意外发现的大批量导入数据SqlBulkCopy类
    Http相关
    Tomcat相关
    对于反射中的invoke()方法的理解
    SqlCommandBuilder类是如何构建T-Sql语句
    模拟在内存中的数据库DataSet相关的类
  • 原文地址:https://www.cnblogs.com/hichens/p/12626286.html
Copyright © 2020-2023  润新知