1
votes

I tried to use dnn module of Opencv 3.1.0 to do some object detection, which I follow tutorial here: Opencv dnn module tutorial

From my understanding, extra module, which contain dnn module, should be built with Opencv source. So I follow this tutorial: Build Opencv with Extra Modules.

However, when I try to compile this simple code in Microsoft Visual Studio 2013,

#include <opencv2\dnn.hpp>
#include <opencv2\core.hpp>
using namespace cv;
using namespace cv::dnn;

void main() {

}

1>------ Rebuild All started: Project: WithDnnModule, Configuration: Debug Win32 ------ 1> DnnTest.cpp 1>DnnTest.obj : error LNK2019: unresolved external symbol "private: void __thiscall cv::String::deallocate(void)" (?deallocate@String@cv@@AAEXXZ) referenced in function "public: __thiscall cv::String::~String(void)" (??1String@cv@@QAE@XZ) 1>C:\Rescourse\Project\opencvdnn\WithDnnModule\Debug\WithDnnModule.exe : fatal error LNK1120: 1 unresolved externals ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

If I don't include opencv2\dnn.hpp, I can build the code successfully.

Please help me out.

3
you need to link the opencv .lib - Miki
You mean something like opencv_core310d.lib and opencv_dnn310d.lib? I'm sure I did it. - Huang Zou

3 Answers

1
votes

I had a very similar problem. It turned out that I was trying to link against the x64 opencv lib/dll but my project was set to x86.

0
votes

Try installing OpenCV 3.10 using this tutorial in a custom directory on your machine. It doesn't matter if you have any other instance of OpenCV installed.

I suppose you will install it in /home/ubuntu/opencv310:

For installation you should run the following command by putting contrib directory somwhere like /home/ubuntu/opencv_contrib:

ccmake -DCMAKE_INSTALL_PREFIX=/home/ubuntu/opencv310 -DWITH_CUDA=ON  -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_EXTRA_MODULES_PATH=/home/ubuntu/opencv_contrib/modules ..

and you are going to run this example:

g++ -I/home/ubuntu/opencv310/include -L/home/ubuntu/opencv310/lib  caffe.cpp  -lopencv_bgsegm -lopencv_bioinspired -lopencv_calib3d -lopencv_ccalib -lopencv_core -lopencv_datasets -lopencv_face -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc  -lopencv_line_descriptor -lopencv_ml -lopencv_objdetect -lopencv_optflow -lopencv_photo -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_videoio -lopencv_video -lopencv_videostab -lopencv_xfeatures2d -lopencv_ximgproc -lopencv_xobjdetect -lopencv_xphoto -lopencv_dnn -o caffe

Now you can run it using ./caffe .

0
votes

You didn't include the correct library. This include will give you all of OpenCV libraries:

include "opencv2/opencv.hpp"