【发布时间】:2018-05-18 03:04:55
【问题描述】:
我正在尝试使用 Dlib 中的 mmod_dnn 模型在视频中跟踪自我训练的猫检测器。我已经使用 dnn_mmod_train_find_cars_example 形式的 blog post 训练了我自己的网络。使用dnn_mmod_face_detector 示例可以很好地检测图像中的猫,但我希望在视频中跟踪猫。我尝试使用webcam_face_pose 示例作为起点,但我似乎无法弄清楚如何应用我自己的网络而不是人脸检测器。任何帮助都非常受欢迎。
代码:
#include <dlib/opencv.h>
#include <opencv2/highgui/highgui.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>
#include <iostream>
#include <dlib/dnn.h>
#include <dlib/data_io.h>
using namespace dlib;
using namespace std;
// network ----------------------
template <long num_filters, typename SUBNET> using con5d = con<num_filters,
5, 5, 2, 2, SUBNET>;
template <long num_filters, typename SUBNET> using con5 = con<num_filters,
5, 5, 1, 1, SUBNET>;
template <typename SUBNET> using downsampler = relu<bn_con<con5d<32,
relu<bn_con<con5d<32, relu<bn_con<con5d<16, SUBNET>>>>>>>>>;
template <typename SUBNET> using rcon5 = relu<bn_con<con5<55, SUBNET>>>;
using net_type = loss_mmod<con<1, 9, 9, 1, 1, rcon5<rcon5<rcon5<downsampler<input_rgb_image_pyramid<pyramid_down<6>>>>>>>>;
----------------------------------
int main()
{
try
{
cv::VideoCapture cap("cat.avi");
if (!cap.isOpened())
{
cerr << "Unable to connect to camera" << endl;
return 1;
}
image_window win;
net_type net;
deserialize("cat_detector.dat") >> net;
// Grab and process frames until the main window is closed by the user.
while(!win.is_closed())
{
// Grab a frame
cv::Mat temp;
if (!cap.read(temp))
{
break;
}
cv_image<bgr_pixel> cimg(temp);
// This is where I get an error (error message below):
std::vector<rectangle> dets = net(cimg);
-------------------
// Display it all on the screen
win.clear_overlay();
win.set_image(temp);
win.add_overlay(dets, rgb_pixel(255, 0, 0));
}
}
catch(serialization_error& e)
{
cout << endl << e.what() << endl;
}
catch(exception& e)
{
cout << e.what() << endl;
}
}
错误:error C2440: 'initializing': cannot convert from 'std::vector<std::vector<dlib::mmod_rect,std::allocator<_Ty>>,std::allocator<std::vector<_Ty,std::allocator<_Ty>>>>' to 'std::vector<dlib::rectangle,std::allocator<_Ty>>'
我似乎有错误的向量类型,即使webcam_face_pose 示例使用了此向量,但我没有在示例中使用人脸模型。我也尝试过std::vector<full_object_detection>,如示例中所示,但我认为我不明白如何正确应用我自己的网络。有什么建议吗?提前感谢您的帮助。
【问题讨论】: