Ask Your Question
0

Can't convert to image from /camera/image/compressed

asked 2019-01-16 06:14:44 -0500

ROStutorialLearner gravatar image

updated 2019-01-16 07:09:57 -0500

Hi, I've followed the tutorial at: http://wiki.ros.org/image_transport/T... and when trying to apply this knowledge to my own project I run into some issues.

OpenCV Error: The function/feature is not implemented (Unknown/unsupported array type) in getMat_, file /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/core/src/matrix.cpp, line 1289
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/core/src/matrix.cpp:1289: error: (-213) Unknown/unsupported array type in function getMat_


Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

However, when I use rqt_image_view I'm able to get an image:

image description

Code:

 void imageCallback(const sensor_msgs::ImageConstPtr& msg)
 {
    try
    {
        cv::Mat image = cv::imdecode(cv::Mat(msg->data),1);//convert compressed image data to cv::Mat
       cv::imshow("view", image);
       cv::waitKey(10);
     }
     catch (cv_bridge::Exception& e)
     {
        ROS_ERROR("Could not convert to image!");
    }
 }


 int main(int argc, char **argv)

 {
    ros::init(argc, argv, "image_listener");
    ros::NodeHandle nh;
    cv::namedWindow("view");
    cv::startWindowThread();
    ros::Subscriber sub = nh.subscribe("/camera/image/compressed", 1, imageCallback);
    ros::spin();
    cv::destroyWindow("view");
    return 0;
 }

CMAKELISTS.TXT

cmake_minimum_required(VERSION 2.8.3)
project(our_robot)

## OpenCV required
find_package( OpenCV REQUIRED )

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

catkin_package(
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

add_executable(our_robot src/lf.cpp)
target_link_libraries(our_robot ${catkin_LIBRARIES})
target_link_libraries(our_robot ${OpenCV_LIBS} )
edit retag flag offensive close merge delete

Comments

You might want to add your CMakeLists.txt as well.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-16 06:19:48 -0500 )edit

Added the cmakelists

ROStutorialLearner gravatar image ROStutorialLearner  ( 2019-01-16 06:43:34 -0500 )edit

Since you are already depending on cv_bridge, I don't believe you need to find_package(OpenCV ..) yourself any more.

You can probably remove the find_package(OpenCV ..) and the target_link_libraries(..) call.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-16 07:04:38 -0500 )edit

Changing it to OpenCV 3 REQUIRED will make the program no longer compile because it can't find any OpenCV anymore, putting OpenCV 2 REQUIRED will compile, while it no longer produces an error, it now just shows a blank window. https://i.imgur.com/bzvU5hP.png Just like it did originally.

ROStutorialLearner gravatar image ROStutorialLearner  ( 2019-01-16 07:09:16 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-01-17 06:01:25 -0500

When I've worked with compressed image topics, I've never had to deal with the compressed data directly I've left that to the image_transport package. You can use the following code to setup a subscriber, this will work with the compressed topic if it is available, or with an uncompressed one if that's all that's available.

image_transport::ImageTransport it(n);
itSub = it.subscribe("topic_name", 1, imageCallbackFn, image_transport::TransportHints("compressed"));

Then your imageCallbackFn will be the same as a regular image callback because the decompression is being handled for you:

// Image callback
void imageCallbackFn(const sensor_msgs::ImageConstPtr& msg)
{
  cv_bridge::CvImagePtr cvImg = cv_bridge::toCvCopy(msg, "bgr8");
  cv::Mat myOpenCVImg = cvImg->image;
}

Hope this helps you get this working.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-01-16 06:14:44 -0500

Seen: 1,446 times

Last updated: Jan 17 '19