cv_bridge ROS image segmentation fault core dumped

asked 2016-07-27 02:24:32 -0600

Jon Verbeke gravatar image

updated 2016-07-27 02:28:53 -0600

Hi,

I'm trying to pull a video feed from rviz into OpenCV to do some real-time image processing on it. For this I publish the rviz video feed onto a ROS topic: /camera_webcam/rgb/image_raw

I'm using:

  • Ubuntu 14.04
  • ROS Indigo
  • OpenCV 3.1
  • Rviz 1.11.14

I wrote a ROS node, named talker, to pull in this video feed an do some processing on it. When using the capture function in combination with a webcam feed or a pre-recorded video everything works fine. But now I need to convert the ROS image fro mthe ROS topic to a Mat in order to be able to process it. To do this I wrote a imageCallback function containing the cv_bridge::toCvCopy() function one requires to do this.

All relevant code is listed below.

CMakelist.txt:

cmake_minimum_required(VERSION 2.8.3)
project(camera_corridor_ROS_OpenCV)

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

# don't use opencv as found by any prior running of find_package
unset(OpenCV_CONFIG_PATH CACHE)
unset(OpenCV_DIR CACHE)

set(TMP_PREFIX_PATH ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH "$ENV{HOME}/opencv-3.1.0")
find_package(OpenCV 3.0 REQUIRED)

# restore CMAKE_PREFIX_PATH and other cached variables
# so nothing other package finds this opencv
set(CMAKE_PREFIX_PATH ${TMP_PREFIX_PATH})

unset(OpenCV_CONFIG_PATH CACHE)
unset(OpenCV_DIR CACHE)

add_message_files(
  FILES
  Corridor_vanish.msg
)
generate_messages(
  DEPENDENCIES
  std_msgs  # Or other packages containing msgs
)
catkin_package(
  CATKIN_DEPENDS message_runtime std_msgs cv_bridge image_transport
)
include_directories(${catkin_INCLUDE_DIRS} include ${OpenCV_INCLUDE_DIRS})
add_library(talker2 src/KalmanDHU.cpp)
add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
target_link_libraries(talker ${OpenCV_LIBRARIES})
target_link_libraries(talker2 ${OpenCV_LIBRARIES})
target_link_libraries(talker talker2)

Package.xml:

<?xml version="1.0"?>
<package>
  <name>camera_corridor_ROS_OpenCV</name>
  <version>0.0.0</version>
  <description>The camera_corridor_ROS_OpenCV package</description>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>image_transport</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>cv_bridge</build_depend>
  <build_depend>uvc_camera</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>rospy</build_depend> 

  <run_depend>image_transport</run_depend>
  <run_depend>roscpp</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>cv_bridge</run_depend>
  <run_depend>uvc_camera</run_depend>
  <run_depend>sensor_msgs</run_depend>
  <run_depend>message_runtime</run_depend>

  <export>
  </export>
</package>

My main code:

//Includes all the headers necessary to use the most common public pieces of the ROS system.
#include <ros/ros.h>
//Use image_transport for publishing and subscribing to images in ROS
#include <image_transport/image_transport.h>
//Use cv_bridge to convert between ROS and OpenCV Image formats
#include <cv_bridge/cv_bridge.h>
//Include some useful constants for image encoding. Refer to: http://www.ros.org/doc/api/sensor_msgs/html/namespacesensor__msgs_1_1image__encodings.html for more info.
#include <sensor_msgs/image_encodings.h>
//Include headers for OpenCV Image processing
#include <opencv2/imgproc/imgproc.hpp>
//Include headers for OpenCV GUI handling
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>


#include "std_msgs/String.h"

#include <sstream>

#include <iostream>
#include "KalmanDHU.h"

#include <camera_corridor_ROS_OpenCV/Corridor_vanish.h>

//Store all constants for image encodings in the enc namespace to be used later.
namespace enc = sensor_msgs::image_encodings;

using namespace std;
using namespace cv;

void imageCallback(const sensor_msgs::ImageConstPtr& original_image);
void ProcessFrame(Mat inputframe);
bool intersection(Point2f o1, Point2f p1, Point2f o2, Point2f p2,Point2f &r);

Point2f pointVanish,pointLeft,pointRight,pointMiddle;
bool corridorFound = false;
vector<Point2f> intersectvector ...
(more)
edit retag flag offensive close merge delete

Comments

Hi,

Maybe I'm wrong but it looks like you use source_img unitialized!

Also you should take a look at the image transport package as it can handle videostream http://wiki.ros.org/image_transport .

Nico

Nico__ gravatar imageNico__ ( 2016-07-28 00:55:53 -0600 )edit