PacktPublishing/Learn-OpenCV-4-By-Building-Projects-Second-Edition

compile errors with DNN module (Chapter 12)

ArifSohaib opened this issue · 3 comments

There seems to be a problem either with my compilation or the CMake file but I am getting an error with NMSBoxes and DNN_BACKEND_OPENCV being undefined. I tried with both edited and original code and also recompiled OpenCV 4 with Build_opencv_dnn, BUILD_opencv_dnn_objdetect and OPENCV_DNN_OPENCV flags as well as trying both with and without CUDA flags but the error presists and the chapter 12 code either modified or with this repo doesn't work.

Can you paste the error that appears in the command line?

The original error was undefined reference to DNN_BACKEND_OPENCV and undefined reference to NMSBoxes

I recompiled again and this is the full error:

[ 25%] Building CXX object CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o
[ 50%] Linking CXX executable DeepLearning_ch12_face
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `main':
resnet_ssd_face.cpp:(.text+0x92): undefined reference to `cv::CommandLineParser::CommandLineParser(int, char const* const*, cv::String const&)'
resnet_ssd_face.cpp:(.text+0x118): undefined reference to `cv::CommandLineParser::printMessage() const'
resnet_ssd_face.cpp:(.text+0x21c): undefined reference to `cv::dnn::experimental_dnn_v2::readNetFromCaffe(cv::String const&, cv::String const&)'
resnet_ssd_face.cpp:(.text+0x22b): undefined reference to `cv::dnn::experimental_dnn_v2::Net::empty() const'
resnet_ssd_face.cpp:(.text+0x386): undefined reference to `cv::dnn::experimental_dnn_v2::Net::setPreferableTarget(int)'
resnet_ssd_face.cpp:(.text+0x395): undefined reference to `cv::VideoCapture::VideoCapture()'
resnet_ssd_face.cpp:(.text+0x460): undefined reference to `cv::VideoCapture::VideoCapture(int)'
resnet_ssd_face.cpp:(.text+0x488): undefined reference to `cv::VideoCapture::~VideoCapture()'
resnet_ssd_face.cpp:(.text+0x497): undefined reference to `cv::VideoCapture::isOpened() const'
resnet_ssd_face.cpp:(.text+0x52a): undefined reference to `cv::VideoCapture::open(cv::String const&)'
resnet_ssd_face.cpp:(.text+0x557): undefined reference to `cv::VideoCapture::isOpened() const'
resnet_ssd_face.cpp:(.text+0x605): undefined reference to `cv::VideoCapture::operator>>(cv::Mat&)'
resnet_ssd_face.cpp:(.text+0x638): undefined reference to `cv::waitKey(int)'
resnet_ssd_face.cpp:(.text+0x6ad): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
resnet_ssd_face.cpp:(.text+0x72b): undefined reference to `cv::dnn::experimental_dnn_v2::blobFromImage(cv::Mat const&, double, cv::Size_<int> const&, cv::Scalar_<double> const&, bool, bool)'
resnet_ssd_face.cpp:(.text+0x75f): undefined reference to `cv::dnn::experimental_dnn_v2::Net::setInput(cv::Mat const&, cv::String const&)'
resnet_ssd_face.cpp:(.text+0x7a2): undefined reference to `cv::dnn::experimental_dnn_v2::Net::forward(cv::String const&)'
resnet_ssd_face.cpp:(.text+0x7c5): undefined reference to `cv::getTickFrequency()'
resnet_ssd_face.cpp:(.text+0x7fa): undefined reference to `cv::dnn::experimental_dnn_v2::Net::getPerfProfile(std::vector<double, std::allocator<double> >&)'
resnet_ssd_face.cpp:(.text+0x9e2): undefined reference to `cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
resnet_ssd_face.cpp:(.text+0xc4f): undefined reference to `cv::rectangle(cv::Mat&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)'
resnet_ssd_face.cpp:(.text+0xd7c): undefined reference to `cv::getTextSize(cv::String const&, int, double, int, int*)'
resnet_ssd_face.cpp:(.text+0xe58): undefined reference to `cv::rectangle(cv::Mat&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)'
resnet_ssd_face.cpp:(.text+0xefc): undefined reference to `cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
resnet_ssd_face.cpp:(.text+0xf7f): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
resnet_ssd_face.cpp:(.text+0xfa7): undefined reference to `cv::waitKey(int)'
resnet_ssd_face.cpp:(.text+0x108f): undefined reference to `cv::VideoCapture::~VideoCapture()'
resnet_ssd_face.cpp:(.text+0x109e): undefined reference to `cv::dnn::experimental_dnn_v2::Net::~Net()'
resnet_ssd_face.cpp:(.text+0x10cb): undefined reference to `cv::CommandLineParser::~CommandLineParser()'
resnet_ssd_face.cpp:(.text+0x11c6): undefined reference to `cv::VideoCapture::~VideoCapture()'
resnet_ssd_face.cpp:(.text+0x13fc): undefined reference to `cv::VideoCapture::~VideoCapture()'
resnet_ssd_face.cpp:(.text+0x1410): undefined reference to `cv::dnn::experimental_dnn_v2::Net::~Net()'
resnet_ssd_face.cpp:(.text+0x144c): undefined reference to `cv::CommandLineParser::~CommandLineParser()'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `cv::String::String(char const*)':
resnet_ssd_face.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `cv::String::~String()':
resnet_ssd_face.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `cv::operator+(char const*, cv::String const&)':
resnet_ssd_face.cpp:(.text._ZN2cvplEPKcRKNS_6StringE[_ZN2cvplEPKcRKNS_6StringE]+0x5a): undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `cv::Mat::Mat(int, int, int, void*, unsigned long)':
resnet_ssd_face.cpp:(.text._ZN2cv3MatC2EiiiPvm[_ZN2cv3MatC5EiiiPvm]+0x130): undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
resnet_ssd_face.cpp:(.text._ZN2cv3MatC2EiiiPvm[_ZN2cv3MatC5EiiiPvm]+0x237): undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `cv::Mat::~Mat()':
resnet_ssd_face.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `cv::Mat::release()':
resnet_ssd_face.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `cv::String::String(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
resnet_ssd_face.cpp:(.text._ZN2cv6StringC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN2cv6StringC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x70): undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `cv::String cv::CommandLineParser::get<cv::String>(cv::String const&, bool) const':
resnet_ssd_face.cpp:(.text._ZNK2cv17CommandLineParser3getINS_6StringEEET_RKS2_b[_ZNK2cv17CommandLineParser3getINS_6StringEEET_RKS2_b]+0x51): undefined reference to `cv::CommandLineParser::getByName(cv::String const&, bool, int, void*) const'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `bool cv::CommandLineParser::get<bool>(cv::String const&, bool) const':
resnet_ssd_face.cpp:(.text._ZNK2cv17CommandLineParser3getIbEET_RKNS_6StringEb[_ZNK2cv17CommandLineParser3getIbEET_RKNS_6StringEb]+0x44): undefined reference to `cv::CommandLineParser::getByName(cv::String const&, bool, int, void*) const'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `int cv::CommandLineParser::get<int>(cv::String const&, bool) const':
resnet_ssd_face.cpp:(.text._ZNK2cv17CommandLineParser3getIiEET_RKNS_6StringEb[_ZNK2cv17CommandLineParser3getIiEET_RKNS_6StringEb]+0x47): undefined reference to `cv::CommandLineParser::getByName(cv::String const&, bool, int, void*) const'
CMakeFiles/DeepLearning_ch12_face.dir/resnet_ssd_face.cpp.o: In function `float cv::CommandLineParser::get<float>(cv::String const&, bool) const':
resnet_ssd_face.cpp:(.text._ZNK2cv17CommandLineParser3getIfEET_RKNS_6StringEb[_ZNK2cv17CommandLineParser3getIfEET_RKNS_6StringEb]+0x49): undefined reference to `cv::CommandLineParser::getByName(cv::String const&, bool, int, void*) const'
collect2: error: ld returned 1 exit status
CMakeFiles/DeepLearning_ch12_face.dir/build.make:94: recipe for target 'DeepLearning_ch12_face' failed
make[2]: *** [DeepLearning_ch12_face] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/DeepLearning_ch12_face.dir/all' failed
make[1]: *** [CMakeFiles/DeepLearning_ch12_face.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

This error is that you are not linking to the opencv libraries. Check you install correctly opencv library and the libraries are installed correctly