endless lope in cv:imread?

asked 2020-04-27 13:53:34 -0500

Hello. I made a C++ program. When running the program,endless lope occured in cv:imread(entire code is below). Endless lope in cv:imread is not occured in Opencv biginner sample code . What happend in my program? How to fix my program to run my program propery?

   ~/ros/catkin_ws$ roscore
   ~/ros/catkin_ws$ source devel/setup.bash
   ~/ros/catkin_ws$ rosrun test_opencv test_opencv
   program start
   file_dir
   home/user/ros/catkin_ws/src/test_opencv/img/image3.jpg

    ~/ros/catkin_ws/src/test_opencv$ tree
    .
    ├── CMakeLists.txt
    ├── CMakeLists.txt~
    ├── img
    │   ├── capture.jpg
    │   ├── image1.jpg
    │   ├── image2.jpg
    │   └── image3.jpg
    ├── include
    │   └── test_opencv
    ├── package.xml
    ├── package.xml~
    └── src
        ├── test_opencv.cpp
        └── test_opencv.cpp~

test_opencv.cpp:

#include <ros/ros.h>
#include <ros/package.h>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char** argv)
{
  std::cout << "program start"<<std::endl;
  std::string file_dir = ros::package::getPath("test_opencv") + "/img/";
  std::cout << "file_dir"<<std::endl;
  std::string input_file_path = file_dir + "image3.jpg";
  std::cout<< input_file_path<< std::endl;
  cv::Mat source_image = cv::imread(input_file_path, cv::IMREAD_GRAYSCALE);
  std::cout << "source_image"<<std::endl;

  cv::imshow("image", source_image);
  std::cout << "program start"<<std::endl;
  cv::waitKey(5000);


   std::string output_file_path = file_dir + "capture.jpg";
   cv::imwrite(output_file_path,source_image);
   return 0;
}

CMakeLists.txt

    cmake_minimum_required(VERSION 2.8.3)
    project(test_opencv)
    #find_package(catkin REQUIRED COMPONENTS
    #  roscpp
    #)

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

    #find_package(OpenCV REQUIRED)
    #find_package(OpenCV 2.4.13.6 REQUIRED PATHS "/home/ais/opencv234/opencv-2.4.13.6")
    find_package(OpenCV 3.4.10 REQUIRED)


    #find_package(OpenCV REQUIRED)

    #if(OpenCV_FOUND)
    #    message("opencv found")

    #endif()



    #find_package(PkgConfig)
    #pkg_check_modules(OPENCV REQUIRED opencv)

    catkin_package(
      INCLUDE_DIRS #include
      LIBRARIES roslib
      LIBRARIES test_opencv
      CATKIN_DEPENDS roscpp
      DEPENDS system_lib
    )



    include_directories(${catkin_INCLUDE_DIRS})
    include_directories(${OpenCV_INCLUDE_DIRS})

    #include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
    message(${OpenCV_INCLUDE_DIRS})


    add_executable(test_opencv src/test_opencv.cpp)



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