赞
踩
YOLOv3论文:https://pjreddie.com/media/files/papers/YOLOv3.pdf
官网和代码:https://pjreddie.com/darknet/
yolo属于one-stage(检测一步到位),兼顾准确率和速度,特别是最近的v3版本提高了小目标的检测率,是移动端目标检测的热门算法。关于YOLO原理的介绍网上有很多资料请自行百度,本文主要介绍如何在自己的cpp中调用yolov3进行目标检测。
yolo采用自定义的image格式进行图像读取和处理,而一般我们工程中使用较多的是OpenCV或者指向图像数据的指针,因此此处先对图像转换和缩放操作进行修改,代码如下:
- #ifndef IMPROCESS_H
- #define IMPROCESS_H
-
- #include<opencv2/opencv.hpp>
-
- void imgConvert(const cv::Mat& img, float* dst);
-
- void imgResize(float* src, float* dst,int srcWidth,int srcHeight,int dstWidth,int dstHeight);
-
- void resizeInner(float *src, float* dst,int srcWidth,int srcHeight,int dstWidth,int dstHeight);
-
- #endif // IMPROCESS_H
- #include<improcess.h>
-
- void imgConvert(const cv::Mat& img, float* dst){
- uchar *data = img.data;
- int h = img.rows;
- int w = img.cols;
- int c = img.channels();
-
- for(int k= 0; k < c; ++k){
- for(int i = 0; i < h; ++i){
- for(int j = 0; j < w; ++j){
- dst[k*w*h+i*w+j] = data[(i*w + j)*c + k]/255.;
- }
- }
- }
- }
-
- void imgResize(float *src, float* dst,int srcWidth,int srcHeight,int dstWidth,int dstHeight){
- int new_w = srcWidth;
- int new_h = srcHeight;
- if (((float)dstWidth/srcWidth) < ((float)dstHeight/srcHeight)) {
- new_w = dstWidth;
- new_h = (srcHeight * dstWidth)/srcWidth;
- } else {
- new_h = dstHeight;
- new_w = (srcWidth * dstHeight)/srcHeight;
- }
-
- float* ImgReInner;
- size_t sizeInner=new_w*new_h*3*sizeof(float);
- ImgReInner=

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。