Ask Your Question

Jovan's profile - activity

2020-03-12 17:41:15 -0600 received badge  Famous Question (source)
2020-03-12 17:41:15 -0600 received badge  Notable Question (source)
2020-03-10 19:03:29 -0600 received badge  Taxonomist
2019-10-10 11:36:06 -0600 received badge  Popular Question (source)
2019-09-20 05:10:45 -0600 commented answer rosrun can't open my video (ROS OpenCV)

I understood, thanks.

2019-09-20 03:45:21 -0600 marked best answer rosrun can't open my video (ROS OpenCV)

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.

2019-09-20 03:45:21 -0600 received badge  Scholar (source)
2019-09-20 03:45:21 -0600 received badge  Supporter (source)
2019-09-19 12:01:29 -0600 asked a question rosrun can't open my video (ROS OpenCV)

rosrun can't open my video (ROS OpenCV) Hi guys, I'm trying to stream some video file (.mp4). I wrote a node: #incl