darknet的安装使用直接在官网上获取。https://pjreddie.com/darknet/
但我用的是OpenCV4.1.1,make时会在image_opencv.cpp中有两个错误。
1. IplImage未定义
加上#include "opencv2/imgproc/imgproc_c.h"
2. 一些CV_开头的标识未定义,删除CV_就可以了,如CV_WINDOW_NORMAL改成WINDOW_NORMAL就行了。
整个image_opencv.cpp的代码如下:
#ifdef OPENCV
#include "stdio.h"
#include "stdlib.h"
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "image.h"
using namespace cv;
extern "C" {
IplImage *image_to_ipl(image im)
{
int x,y,c;
IplImage *disp = cvCreateImage(cvSize(im.w,im.h), IPL_DEPTH_8U, im.c);
int step = disp->widthStep;
for(y = ; y < im.h; ++y){
for(x = ; x < im.w; ++x){
for(c= ; c < im.c; ++c){
float val = im.data[c*im.h*im.w + y*im.w + x];
disp->imageData[y*step + x*im.c + c] = (unsigned char)(val*);
}
}
}
return disp;
}
image ipl_to_image(IplImage* src)
{
int h = src->height;
int w = src->width;
int c = src->nChannels;
image im = make_image(w, h, c);
unsigned char *data = (unsigned char *)src->imageData;
int step = src->widthStep;
int i, j, k;
for(i = ; i < h; ++i){
for(k= ; k < c; ++k){
for(j = ; j < w; ++j){
im.data\[k\*w\*h + i\*w + j\] = data\[i\*step + j\*c + k\]/.;
}
}
}
return im;
}
Mat image_to_mat(image im)
{
image copy = copy_image(im);
constrain_image(copy);
if(im.c == ) rgbgr_image(copy);
IplImage \*ipl = image\_to\_ipl(copy);
Mat m = cvarrToMat(ipl, true);
cvReleaseImage(&ipl);
free\_image(copy);
return m;
}
image mat_to_image(Mat m)
{
IplImage ipl = m;
image im = ipl_to_image(&ipl);
rgbgr_image(im);
return im;
}
void *open_video_stream(const char *f, int c, int w, int h, int fps)
{
VideoCapture *cap;
if(f) cap = new VideoCapture(f);
else cap = new VideoCapture(c);
if(!cap->isOpened()) return ;
if(w) cap->set(CAP_PROP_FRAME_WIDTH, w);
if(h) cap->set(CAP_PROP_FRAME_HEIGHT, w);
if(fps) cap->set(CAP_PROP_FPS, w);
return (void *) cap;
}
image get_image_from_stream(void *p)
{
VideoCapture *cap = (VideoCapture *)p;
Mat m;
*cap >> m;
if(m.empty()) return make_empty_image(,,);
return mat_to_image(m);
}
image load_image_cv(char *filename, int channels)
{
int flag = -;
if (channels == ) flag = -;
else if (channels == ) flag = ;
else if (channels == ) flag = ;
else {
fprintf(stderr, "OpenCV can't force load with %d channels\n", channels);
}
Mat m;
m = imread(filename, flag);
if(!m.data){
fprintf(stderr, "Cannot load image \"%s\"\n", filename);
char buff[];
sprintf(buff, "echo %s >> bad.list", filename);
system(buff);
return make_image(,,);
//exit(0);
}
image im = mat_to_image(m);
return im;
}
int show_image_cv(image im, const char* name, int ms)
{
Mat m = image_to_mat(im);
imshow(name, m);
int c = waitKey(ms);
if (c != -) c = c%;
return c;
}
void make_window(char *name, int w, int h, int fullscreen)
{
namedWindow(name, WINDOW_NORMAL);
if (fullscreen) {
setWindowProperty(name, WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
} else {
resizeWindow(name, w, h);
if(strcmp(name, "Demo") == ) moveWindow(name, , );
}
}
}
#endif
手机扫一扫
移动阅读更方便
你可能感兴趣的文章