Ask Your Question
1

Using opencv dnn module with ros

asked 2019-03-10 20:56:11 -0600

falithurrahman gravatar image

updated 2019-04-08 16:26:49 -0600

jayess gravatar image

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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2019-03-11 00:15:21 -0600

There is a boo boo in your CMakeLists.txt, the line

target_link_libraries(vision_secondary_capture ${catkin_LIBRARIES} ${OpenCV_LIBS} ${Boost_LIBRARIES} ${YAML_CPP_LIBRARIES})

should be

target_link_libraries(vision_secondary_capture ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${Boost_LIBRARIES} ${YAML_CPP_LIBRARIES})
edit flag offensive delete link more

Comments

i changed the target_link_libraries as you suggested, but then i still encountered the same error.

falithurrahman gravatar imagefalithurrahman ( 2019-03-11 01:11:37 -0600 )edit
1

try deleting the folder "devel" and "build" inside of your catkin workspace. Some CMake cache might be trolling you

Martin Peris gravatar imageMartin Peris ( 2019-03-11 01:13:54 -0600 )edit

it's still the same error after i deleted both folder

falithurrahman gravatar imagefalithurrahman ( 2019-03-11 01:33:27 -0600 )edit

That is odd... try commenting out all the lines related to "vision_secondary_capture" and see if the package compiles

Martin Peris gravatar imageMartin Peris ( 2019-03-11 03:15:30 -0600 )edit

everything works out fine if i comment line 17 and 19. When i do catkin_make, it build 100%

#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");

but when i don't comment them, the code wont build 100%

falithurrahman gravatar imagefalithurrahman ( 2019-03-11 18:43:01 -0600 )edit

If you installed cv_bridge and image_transport using debian packages then they are compiled against the version of the OpenCV library that comes with ROS. Try downloading the source code of those packages and compiling everything together.

Martin Peris gravatar imageMartin Peris ( 2019-03-18 20:46:41 -0600 )edit
0

answered 2019-04-09 15:04:21 -0600

budhie gravatar image

I finally solved this issue, here the solution:

$ cd ~/catkin_ws
$ git clone https://github.com/ros-perception/vision_opencv src/vision_opencv
$ git clone https://github.com/ros-perception/image_transport_plugins.git src/image_transport_plugins
$ catkin_make

Mantap!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-03-10 20:56:11 -0600

Seen: 332 times

Last updated: Apr 09