Using opencv dnn module with ros
I'm writing a Publisher-Subscriber node to run an object detection program using the images from webcam in my robot. I am trying to use the OpenCV DNN module and load the pretrained model that i had before. The problem is, whenever I tried to catkin_make my project, when it reached 98& of completion, the following error showed up on the console:
CMakeFiles/vision_secondary_capture.dir/src/vision_secondary_capture.cpp.o: In function `main':
vision_secondary_capture.cpp:(.text+0xa0): undefined reference to `cv::dnn::experimental_dnn_v2::Net::Net()'
vision_secondary_capture.cpp:(.text+0x8e0): undefined reference to `cv::dnn::experimental_dnn_v2::Net::~Net()'
vision_secondary_capture.cpp:(.text+0xc39): undefined reference to `cv::dnn::experimental_dnn_v2::Net::~Net()'
collect2: error: ld returned 1 exit status
iris_its/CMakeFiles/vision_secondary_capture.dir/build.make:154: recipe for target '/home/iris/maul/devel/lib/iris_its/vision_secondary_capture' failed
make[2]: *** [/home/iris/maul/devel/lib/iris_its/vision_secondary_capture] Error 1
CMakeFiles/Makefile2:588: recipe for target 'iris_its/CMakeFiles/vision_secondary_capture.dir/all' failed
make[1]: *** [iris_its/CMakeFiles/vision_secondary_capture.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed
I successfully installed OpenCV 3.4.3 (since the one included with ROS Kinetic is version 3.3.1 and it doesn't have the files I need). Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.3)
project(iris_its)
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
message_generation
message_runtime
roscpp
rospy
sensor_msgs
std_msgs
)
find_package(Boost REQUIRED COMPONENTS thread)
set(OpenCV_DIR "/usr/local/lib")
find_package(OpenCV 3.4.3 REQUIRED)
find_package(yaml-cpp REQUIRED)
add_message_files(
FILES
vision_ball.msg
vision_obstacle.msg
vision_field.msg
data_robot.msg
serial.msg
)
add_service_files(
FILES
hsv_threshold_init.srv
)
generate_messages(
DEPENDENCIES
sensor_msgs
std_msgs
)
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS cv_bridge image_transport roscpp rospy sensor_msgs std_msgs
DEPENDS Boost OpenCV
)
include_directories(
include
${OpenCV_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${YAML_CPP_INCLUDE_DIR}
)
add_executable(vision_capture src/vision_capture.cpp)
add_executable(vision_field src/vision_field.cpp)
add_executable(vision_ball src/vision_ball.cpp)
add_executable(vision_obstacle src/vision_obstacle.cpp)
add_executable(vision_secondary_capture src/vision_secondary_capture.cpp)
add_executable(vision_secondary_field src/vision_secondary_field.cpp)
add_executable(vision_secondary_ball src/vision_secondary_ball.cpp)
add_executable(dribble src/dribble.cpp)
add_executable(routine src/routine_motion.cpp src/routine_game.cpp src/routine.cpp)
add_executable(udp_receive src/udp-recv.cpp)
add_executable(udp_send src/udp-send.cpp)
add_executable(serial src/serial.cpp src/rs232.c)
target_link_libraries(vision_capture ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
target_link_libraries(vision_field ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
target_link_libraries(vision_ball ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
target_link_libraries(vision_obstacle ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
target_link_libraries(vision_secondary_capture ${catkin_LIBRARIES} ${OpenCV_LIBS} ${Boost_LIBRARIES} ${YAML_CPP_LIBRARIES})
target_link_libraries(vision_secondary_field ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
target_link_libraries(vision_secondary_ball ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
target_link_libraries(dribble ${catkin_LIBRARIES})
target_link_libraries(routine ${catkin_LIBRARIES})
target_link_libraries(udp_receive ${catkin_LIBRARIES})
target_link_libraries(udp_send ${catkin_LIBRARIES})
target_link_libraries(serial ${catkin_LIBRARIES})
this is .cpp file for the node
#include "cv_bridge/cv_bridge.h"
#include "image_transport/image_transport.h"
#include "opencv2/opencv.hpp"
#include "ros/package.h"
#include "ros/ros.h"
#include "opencv2/dnn/dnn.hpp"
using namespace std;
using namespace cv;
using namespace dnn;
int main(int argc, char **argv)
{
Mat frame;
Mat blob;
Mat outs;
Net net;
net = readNetFromTensorflow("src/frozen_inference_graph.pb", "/src/graph.pbtxt");
is there any suggestion what should i do? thanks before