YOLOv3在Darknet框架下编译出错

yolov3在darknet下编译时出现

gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv`  -Wall -Wno-unknown-pragmas -Wfatal-```
errors -fPIC -Ofast -DOPENCV -c ./src/gemm.c -o obj/gemm.o
In file included from /usr/local/include/opencv2/core/types_c.h:59:0,
                 from /usr/local/include/opencv2/core/core_c.h:48,
                 from /usr/local/include/opencv2/highgui/highgui_c.h:45,
                 from include/darknet.h:25,
                 from ./src/utils.h:5,
                 from ./src/gemm.c:2:
/usr/local/include/opencv2/core/cvdef.h:485:1: error: unknown type name ‘namespace’
 namespace cv {
 ^~~~~~~~~
compilation terminated due to -Wfatal-errors.
Makefile:85: recipe for target 'obj/gemm.o' failed
make: *** [obj/gemm.o] Error 1

opencv版本3.4,(之前在3.2版本编译并没有出错),解决方法:
步骤有两步,需要修改两个c文件。
第一步,找到:

/usr/local/include/opencv2/core/cvdef.h

修改485行左右的代码:

#else
#include 
namespace cv {
typedef ::int8_t int8_t;
typedef ::uint8_t uint8_t;
typedef ::int16_t int16_t;
typedef ::uint16_t uint16_t;
typedef ::int32_t int32_t;
typedef ::uint32_t uint32_t;
typedef ::int64_t int64_t;
typedef ::uint64_t uint64_t;
}
#endif

把这段代码注释掉,改为:

#else
#include 
//namespace cv {
//typedef ::int8_t int8_t;
//typedef ::uint8_t uint8_t;
//typedef ::int16_t int16_t;
//typedef ::uint16_t uint16_t;
//typedef ::int32_t int32_t;
//typedef ::uint32_t uint32_t;
//typedef ::int64_t int64_t;
//typedef ::uint64_t uint64_t;
//}
#endif

在ubuntu下找到这个文件后发现这个文件不可操作是因为权限不够,可以在该文件路径下打开命令行输入

sudo chmod 777 <文件名>

输入密码获取操作权限。

第二步,找到:

/usr/local/include/opencv2/highgui/highgui_c.h

修改139行左右的代码:

CVAPI(cv::Rect)cvGetWindowImageRect(const char* name);

修改类型为:

CVAPI(CvRect)cvGetWindowImageRect(const char* name);

这两步做完以后,再在darknet文件夹下执行make命令,应该就能编译通过了。编译通过以后别忘了把修改过的代码改回来,因为不知道以后什么时候万一还会用到,到时候忘了自己改过这里的话会很麻烦。
然后呢还没完,执行检测的时候又报错了,也是和OpenCV 3.4.1的bug有关,以下是输入的命令:

./darknet detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights data/dog.jpg

错误提示是:
penCV(3.4.1-dev) Error: Assertion failed ((flags & FIXED_TYPE) != 0) in type, file /opt/opencv/modules/core/src/matrix_wrap.cpp, line 807 terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(3.4.1-dev) /opt/opencv/modules/core/src/matrix_wrap.cpp:807: error: (-215) Assertion failed: (flags & FIXED_TYPE) != 0 in function type
经过调试,大概知道是:

darknet/examples/detector.c

这个文件的610行左右这句的锅

save_image(im, "predictions"); 

这句话的意思是要把图片im存下来,我感觉这句话好像没有也不影响什么,然后我把这句话注释掉,然后重新make一次,再执行检测代码,就能够用OpenCV的GUI界面去显示检测结果以及包围盒了。

转自 知乎https://zhuanlan.zhihu.com/p/36933700,据说是一个国外大神写的。

你可能感兴趣的:(目标检测)