Error linking to OpenCV DNN Library
I'm writing a Publisher-Subscriber node to run a face detection program using the images from my webcam. I am trying to use the OpenCV DNN module. The problem is, whenever I try to catkin_make my project, the following is output on the console:
pedrosc@PEDROSC:~/robotics$ catkin_make
Base path: /home/pedrosc/robotics
Source space: /home/pedrosc/robotics/src
Build space: /home/pedrosc/robotics/build
Devel space: /home/pedrosc/robotics/devel
Install space: /home/pedrosc/robotics/install
####
#### Running command: "make cmake_check_build_system" in "/home/pedrosc/robotics/build"
####
####
#### Running command: "make -j8 -l8" in "/home/pedrosc/robotics/build"
####
[ 50%] Linking CXX executable /home/pedrosc/robotics/src/artrack/src/artrack_imgproc
CMakeFiles/artrack_imgproc.dir/src/artrack_imgproc.cpp.o: In function `ImageProcessor::ImageProcessor()':
artrack_imgproc.cpp:(.text._ZN14ImageProcessorC2Ev[_ZN14ImageProcessorC5Ev]+0xdd): undefined reference to `cv::dnn::experimental_dnn_v2::Net::Net()'
artrack_imgproc.cpp:(.text._ZN14ImageProcessorC2Ev[_ZN14ImageProcessorC5Ev]+0x622): undefined reference to `cv::dnn::experimental_dnn_v2::Net::~Net()'
CMakeFiles/artrack_imgproc.dir/src/artrack_imgproc.cpp.o: In function `ImageProcessor::~ImageProcessor()':
artrack_imgproc.cpp:(.text._ZN14ImageProcessorD2Ev[_ZN14ImageProcessorD5Ev]+0x53): undefined reference to `cv::dnn::experimental_dnn_v2::Net::~Net()'
artrack_imgproc.cpp:(.text._ZN14ImageProcessorD2Ev[_ZN14ImageProcessorD5Ev]+0xd4): undefined reference to `cv::dnn::experimental_dnn_v2::Net::~Net()'
collect2: error: ld returned 1 exit status
artrack/CMakeFiles/artrack_imgproc.dir/build.make:229: recipe for target '/home/pedrosc/robotics/src/artrack/src/artrack_imgproc' failed
make[2]: *** [/home/pedrosc/robotics/src/artrack/src/artrack_imgproc] Error 1
CMakeFiles/Makefile2:477: recipe for target 'artrack/CMakeFiles/artrack_imgproc.dir/all' failed
make[1]: *** [artrack/CMakeFiles/artrack_imgproc.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed
I have successfully installed OpenCV 3.4.5 (since the one included with ROS Kinetic is version 3.0.0 and it doesn't have the files I need). Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.3)
project(artrack)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
image_transport
geometry_msgs
ardrone_autonomy
)
find_package(OpenCV 3.4.5 REQUIRED)
find_package(uvc_camera REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
include_directories(
${catkin_INCLUDE_DIRS}
${uvc_camera_INCLUDE_DIRS}
${cv_bridge_INCLUDE_DIRS}
${sensor_msgs_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_executable(artrack_imgproc src/artrack_imgproc.cpp)
target_link_libraries(artrack_imgproc
${catkin_LIBRARIES}
${uvc_camera_LIBRARIES}
${cv_bridge_LIBRARIES}
${sensors_msgs_LIBRARIES}
${OpenCV_LIBRARIES}
)
set_target_properties(artrack_imgproc PROPERTIES RUNTIME_OUTPUT_DIRECTORY ~/robotics/src/artrack/src)
catkin_package(CATKIN_DEPENDS
message_runtime
sensor_msgs
image_transport
cv_bridge
geometry_msgs
)
And the .cpp file for the node:
//////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ImageProcessor
//
// Node source code for the processing of the image. It uses neural networks to detect faces,
// then tracks the detected face using a tracking algorithm. It publishes the coordinates of
// the centroid of the face. This node also handles the GUI elements of the main window of
// the project.
//
//////////////////////////////////////////////////////////////////////////////////////////////////////
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/core.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/utils/trace.hpp>
#include <iostream>
using namespace cv;
using namespace cv::dnn;
using namespace std;
static const std::string OPENCV_WINDOW = "OpenCV Image Window";
//Image Processor Class
class ImageProcessor
{
//Object declarations for the ROS elements
ros::NodeHandle nh_;
image_transport::ImageTransport it_;
image_transport::Subscriber image_sub_;
image_transport::Publisher image_pub_;
//Object initialization for ...