crazyMint

opencv cv::Mat 彩色图像转为dlib::array2d

#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/opencv/cv_image.h>
#include <iostream>
#include <opencv2/opencv.hpp>

void face_detect(const cv::Mat& img)
{
    //定义人脸检测器
    dlib::frontal_face_detector detector = dlib::get_frontal_face_detector();
    //定义窗口
    dlib::image_window win;

    dlib::array2d<dlib::rgb_pixel> src;
    //opencv mat转换为dlib array2d
    dlib::assign_image(src, dlib::cv_image<dlib::bgr_pixel>(img));
    //上采样
    dlib::pyramid_up(src);
    //获取检测结果
    std::vector<dlib::rectangle> dets = detector(src);

    std::cout << "Number of faces detected: " << dets.size() << std::endl;
    // Now we show the image on the screen and the face detections as
    // red overlay boxes.
    win.clear_overlay();
    win.set_image(src);
    win.add_overlay(dets, dlib::rgb_pixel(255,0,0));

    std::cout << "Hit enter to process the next image..." << std::endl;
    std::cin.get();
}

int main()
{
    cv::Mat src = cv::imread("faces/2007_007763.jpg");
    face_detect(src);
    return 0;
}

分类:

技术点:

相关文章:

  • 2021-07-09
  • 2021-12-06
  • 2021-12-04
  • 2021-08-25
猜你喜欢
  • 2021-12-21
  • 2022-12-23
  • 2021-12-30
  • 2022-01-01
  • 2021-10-11
  • 2021-05-27
相关资源
相似解决方案