前言
在darknet框架代碼中,有可能在c代碼文件中調用了 opencv的API,如下所示:data.c中調用了opencv代碼。這時就會導致一些編譯錯誤產生。
/**************data.c*************/
... ...
#ifdef OPENCV
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"
image image_data_augmentation(IplImage* ipl, int w, int h, int pleft, int ptop, int swidth, int sheight, int flip, float jitter, float dhue, float dsat, float dexp);
#endif
... ...
問題分析及解決
1)如果darknet的Makefile中指定的opencv版本爲 4.00以上(pkg-config --libs opencv4),那麼會出現下面這個錯誤。
error: #error "OpenCV 4.x+ requires enabled C++11 support"
網上有的說 g++編譯項目時,添加參數"-std=c++11"。但是這裏的是c文件調用opencv頭文件,沒法觸發g++編譯,而gcc編譯也不能添加該參數。 所以比較可行的辦法就是,安裝opencv3.x,並用pkg-config --libs opencv指定。當然,opencv3.x和4.x是可以共存的,具體參考:https://blog.csdn.net/avideointerfaces/article/details/90216832
2)unknown type name ‘namespace’。具體如下所示:
解決辦法就是將cvdef.h中一段代碼註釋掉。如下紅框所示。
3) 解決完上面這個編譯錯誤後,還會遇到另外一個錯誤:error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token 如下所示。
解決辦法就是 將CV::Rect改成 CvRect.