ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Undefined reference to `cv::VideoCapture::~VideoCapture()

asked 2018-12-15 10:57:28 -0500

Ibrahim_aerospace gravatar image

updated 2018-12-17 05:53:58 -0500

Hi all ! I want compile the package bebop_teleop but it gives the error that:

WebcamPublisher.cpp:(.text+0x7d4): undefined reference to `cv::VideoCapture::~VideoCapture()

I already installed ffmpeg, because someone mentioned that its needed to be installed. I searched the problem on different forums but they used other platforms not CATKIN and ROS if someone has faced this problem using ROS, please help me. Thanks alot. my source code is:

#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <ros/ros.h>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/video.hpp"
#include "opencv2/imgproc.hpp"

using namespace std;
using namespace cv;

int main(int argc, char** argv) {
    ros::init(argc, argv, "webcam_publisher");
    ros::NodeHandle nh;
    image_transport::ImageTransport it(nh);
    image_transport::Publisher pub = it.advertise("bebop/image_raw", 1);

    cv::VideoCapture capture(0);
    if( !capture.isOpened() ) {
        ROS_ERROR("FAILED TO OPEN CAPTURE");
        return -1;
    }

    cv::Mat input;
    cv::Mat output;
    cv::Size size(640, 368);
    sensor_msgs::ImagePtr msg;

    ros::Rate r(10);
    while( nh.ok() ) {
        capture >> input;

        if( !input.empty() ) {
            cv::resize(input, output, size);
            msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", output).toImageMsg();
            pub.publish(msg);
        }

        ros::spinOnce();
        r.sleep();
    }

    pub.shutdown();
    ros::shutdown();
}

cmake_minimum_required(VERSION 3.0.0) project(bebop_teleop)

add_definitions(-std=c++11) add_compile_options(-std=gnu++11)

find_package(catkin REQUIRED COMPONENTS     geometry_msgs   roscpp  std_msgs    sensor_msgs     bebop_msgs  cv_bridge   image_transport )

include(FindPkgConfig) pkg_check_modules(SDL2 REQUIRED sdl2) pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)

#generate_messages(
#  DEPENDENCIES
#  geometry_msgs
#  std_msgs
#  sensor_msgs
#  bebop_msgs
#)


catkin_package(     INCLUDE_DIRS include    LIBRARIES bebop_teleop  CATKIN_DEPENDS geometry_msgs roscpp std_msgs sensor_msgs bebop_msgs cv_bridge image_transport   DEPENDS ${SDL2_LIBRARY} ${SDL2_TTF_LIBRARY} )

include_directories(include     ${SDL2_INCLUDE_DIRS}    ${SDL2_TTF_INCLUDE_DIRS}    ${catkin_INCLUDE_DIRS})

link_directories(${SDL2_LIBRARY_DIRS}   ${SDL2_TTF_LIBRARY_DIRS}    ${catkin_LIBRARY_DIRS})


add_executable( bebop_teleop src/Events.cpp src/Input.cpp src/Window.cpp src/ManualControl.cpp src/GUI.cpp src/StateTracker.cpp src/Patroller.cpp src/main.cpp) add_executable( webcam src/WebcamPublisher.cpp) target_link_libraries( bebop_teleop     ${SDL2_LIBRARIES}   ${SDL2_TTF_LIBRARIES}   ${catkin_LIBRARIES} )

target_link_libraries( webcam   ${catkin_LIBRARIES} )
edit retag flag offensive close merge delete

Comments

have you seen this?

aPonza gravatar image aPonza  ( 2018-12-17 01:58:32 -0500 )edit

@aPonza yes I already checked that link, and I included those libraries mentioned by him but doesnt work in my case. But in that post I didnt understand one sentence that Some LD_LIBRARY_PATH may solve it. What does this mean may be this solve my problem but I cant get its meaning?

Ibrahim_aerospace gravatar image Ibrahim_aerospace  ( 2018-12-17 02:52:20 -0500 )edit

can you please explain ? Thanks alot

Ibrahim_aerospace gravatar image Ibrahim_aerospace  ( 2018-12-17 02:52:42 -0500 )edit

Try first to remove using namespace std and using namespace cv: you're not even using anything from std, and you're qualifying all your cv names. Also maybe edit your post to include the CMakeLists.txt which should be the real problem

aPonza gravatar image aPonza  ( 2018-12-17 03:01:43 -0500 )edit

I removed them and still the same error, by the way I didnt include std but it was already there when downloaded this package.

Ibrahim_aerospace gravatar image Ibrahim_aerospace  ( 2018-12-17 05:52:05 -0500 )edit

@aPonza can you please have a look now, I added the contents of CMakeLists.txt file. thanks

Ibrahim_aerospace gravatar image Ibrahim_aerospace  ( 2018-12-17 05:54:54 -0500 )edit

You only mention installing ffmpeg, but you link to SDL2 and SDL2_TTF... Do you have those installed?

aPonza gravatar image aPonza  ( 2018-12-17 06:15:41 -0500 )edit

yes I installed them according to the instructions given here. link text

Ibrahim_aerospace gravatar image Ibrahim_aerospace  ( 2018-12-17 06:25:31 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-06-11 13:20:26 -0500

I encountered this problem. First make sure you have opencv in /usr/include folder and all the libs are installed in the correct place. And in CMakeLists.txt for your program after add_executable line, add find_package(OpenCV) include_directories(${OpenCV_INCLUDE_DIRS}) and in target_link_libraries, add ${OpenCV_LIBS} too along with catkin libraries. And this worked for me and this is specific to ros melodic. I had to install specific opencv version and all. But the above changes worked for me!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-12-15 10:57:28 -0500

Seen: 3,468 times

Last updated: Dec 17 '18