Can't convert to image from /camera/image/compressed
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:
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} )
You might want to add your
CMakeLists.txt
as well.Added the cmakelists
Since you are already depending on
cv_bridge
, I don't believe you need tofind_package(OpenCV ..)
yourself any more.You can probably remove the
find_package(OpenCV ..)
and thetarget_link_libraries(..)
call.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.