结合上篇玩转Jetson nano系列(1),在jetson安装好ncnn,就可以开发各种模型了。
上篇最后提到,可以通过在ncnn根目录下修改CMakefile.txt文件,去掉examples的编译注释,就可以编译出ncnn自带的模型。
一. 修改自带yolov2源码
因为自带yolov2是基于mobilenet的,而且只支持图片检测,为了让模型支持cam的实时检测,因此需要对自带的源码进行修改。
进入自带模型源码文件夹:
并备份得到新的yolov2_cam.cpp
cd ~/ncnn/examples
cp yolov2.cpp yolov2_cam.cpp
打开修改yolov2_cam.cpp
vim yolov2_cam.cpp
因为我用的是树莓派cam,设置cam参数:
这里参考自:
std::string gstreamer_pipeline (int capture_width, int capture_height, int display_width, int display_height, int framerate, int flip_method) {
return "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)" + std::to_string(capture_width) + ", height=(int)" +
std::to_string(capture_height) + ", format=(string)NV12, framerate=(fr