DLIB将自训练的检测器应用于视频(MMOD_DNN)
Dlib apply self trained detector to video (mmod_dnn)
im试图在视频中使用DLIB中的MMOD_DNN模型在视频中跟踪一个自训练的猫检测器。我已经使用dnn_mmod_train_find_cars_example训练了自己的网络。它可以使用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示例使用此矢量,除了我不使用示例中的face模型。我还尝试了示例中的std::vector<full_object_detection>
,但是我认为我不明白如何正确应用自己的网络。有建议吗?事先感谢您的任何帮助。
如果您仍然遇到麻烦,我一直在处理类似的问题并找到了一些解决方案。
这里的主要问题是对于MMOD_DNN型号,net(cimg)
不会返回矩形的向量。它返回类似的内容:vector<mmod_rect>
或vector<vector<mmod_rect>>
,具体取决于您给它单张图像还是多个图像。您链接的面部检测示例代码使用auto dets = net(img)
。然后,您必须将它们转换为DLIB矩形才能尝试解决姿势。
您可能遇到的其他问题是MMOD_DNN网络采用matrix<rgb_pixel>
或vector<matrix<rgb_pixel>>
类型,因此您必须转换为这些类型。Dlib有一些功能可以帮助那里:
cv_image<bgr_pixel> cimg(temp);
matrix<rgb_pixel> matrix;
assign_image(matrix, cimg)
- 如何在c++中录制具有精确帧时间戳的视频
- 如何在QT中的自定义视频小工具t上绘制矩形
- 如何使用OpenCV-C++编写*.mp4视频?
- 开放 CV 中的动态内存分配,用于视频处理
- 错误:(-210:不支持的格式或格式组合)功能'create'中的硬件视频解码器不支持视频源
- OpenCV QT,显示视频的帧(不使用while循环)
- FFmpeg——使用硬件加速进行视频解码
- 在 openCV 中手动停止视频
- 强制Qt相机视频格式
- 在macOS Mojave上尝试OpenCV视频捕获时"Abort Trap: 6"
- 应用程序在打开的简历中捕获视频后没有响应
- 使用 IMFSinkWriter 编码的视频的播放速度会根据宽度而变化
- 如何在 c++ 中通过 http 发送大型视频文件?
- 在 QLabel 中显示视频
- OpenGL 调试上下文警告 -"将使用视频内存作为缓冲区异议的来源
- 这个工厂类在这个C++视频中的意义何在?
- 如何使用Qt在新窗口中显示视频帧
- Qt GUI使用Qfiledialogbox和qlabel显示视频,这是我的代码
- 如何OPENCV+CUDA+视频捕获?
- 面临分段故障 使用 ffmpeg 读取视频时,因为"pFormatCtx-> streams [i]-> codecpar"的地址0x00