Ask Your Question
0

rosrun can't open my video (ROS OpenCV)

asked 2019-09-19 11:18:54 -0500

Jovan gravatar image

updated 2019-10-10 11:37:15 -0500

mjcarroll gravatar image

Hi guys,

I'm trying to stream some video file (.mp4). I wrote a node:

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>

#include <iostream>

int main(int argc, char **argv)
{
    cv::VideoCapture cap("chaplin.mp4"); 


    cv::namedWindow("A_good_name", CV_WINDOW_AUTOSIZE);


    if(!cap.isOpened() )
    {
        std::cout << "\nCannot open the video file.\n";
        return EXIT_FAILURE;
    }

    double fps = cap.get(CV_CAP_PROP_FPS); //get the fps

    int waitKeyValue = 10;

    while(true)
    {
        cv::Mat frame;


        if(!cap.read(frame) )
        {
            std::cout <<"\n Cannot read the video file.\n";
            return EXIT_FAILURE;
        }

        cv::imshow("A_good_name", frame);

        int key = cv::waitKey(waitKeyValue);

        if(key != -1)
            std::cout << key << std::endl;

        if(key == 32) //space button for pause
        {
            if(waitKeyValue)
                waitKeyValue = 0;
            else
                waitKeyValue = 10;
        }

        if(key == 27) //escape button for exit
            break;
    }

    cap.release();
    return EXIT_SUCCESS;
}

my CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.15.2)
project(task)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  message_generation
  cv_bridge 
  image_transport
  sensor_msgs
)

generate_messages(
  DEPENDENCIES
  std_msgs
)

###################################

find_package(Boost REQUIRED COMPONENTS system)
find_package(SDL REQUIRED)
set(LIBS ${SDL_LIBRARY})

catkin_package(
  INCLUDE_DIRS
  LIBRARIES task
  CATKIN_DEPENDS roscpp 
                 rospy 
                 std_msgs
                 cv_bridge
                 image_transport

  DEPENDS system_lib ${LIBS}
)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
  ${GSTREAMER_INCLUDE_DIRS}
  ${SDL_INCLUDE_DIR}
  ${OpenCV_INCLUDE_DIRS}
)

##################################### build

add_executable(playVideo_node nodes/CVexample/PlayVideo_node.cpp )
target_link_libraries(playVideo_node ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} )
add_dependencies(playVideo_node task_gencpp)

#####################################

install(TARGETS 
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".svn" EXCLUDE
)

I moved video (chaplin.mp4) in my code directory, but when I enter

$ rosrun task playVideo_node

I get:

init done
opengl support available

Cannot open the video file.

Then I tried to move video in execute file directory, but problem is same. Does anyone has suggestion what should I do?

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-09-19 12:54:14 -0500

tfoote gravatar image

rosrun executes with the cwd in your current directory so relatively links should be relative to your current path. Not the source or executable directory.

For others reference roslaunch uses ROS_HOME Related roslaunch question Reference roslaunch XML node attributes

edit flag offensive delete link more

Comments

I understood, thanks.

Jovan gravatar imageJovan ( 2019-09-20 04:21:31 -0500 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2019-09-19 11:18:54 -0500

Seen: 26 times

Last updated: Sep 19