How to subscribe to a camera and save image?
Hi, So I am working with a car simulator and the car has simulated cameras attached to it. Now I am able to get a live video feed from the camera using rviz but I want to save the images that I am getting from the camera to be able to train my model using machine learning. I am not able to figure out how to save those images in a folder. I have tried many things that I found on the forums but nothing has really worked. I would really appreciate the help.
./testimage.cpp: line 6: syntax error near unexpected token `('
./testimage.cpp: line 6: `void imageCallback(const sensor_msgs::ImageConstPtr& msg)'
this was the error I got.
And this is what my code looks like:
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
try
{
cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
cv::waitKey(30);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "image_listener");
ros::NodeHandle nh;
cv::namedWindow("view");
cv::startWindowThread();
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub = it.subscribe("/truevision/camera/front_right", 1, imageCallback);
ros::spin();
cv::destroyWindow("view");
}
What specifically have you tried and what was the result?
./testimage.cpp ./testimage.cpp: line 6: syntax error near unexpected token
(' ./testimage.cpp: line 6:
void imageCallback(const sensor_msgs::ImageConstPtr& msg)'I tried making an image subscriber following the tutorials on the ROS website. And then when I ran the code this is the error i got
Don't know what this error is because the code is the same as in the tutorial. Could this be due to the dependencies or something? because I am using a workspace that I created using the tutorial on workspaces. I am not too sure. I am pretty new to ROS.
http://wiki.ros.org/image_transport/T... this is the tutorial I followed.
Please update your question with this information (including code examples and errors/terminal output) using the preformatted text or
101010
button for code/terminal output. Comments aren't the best place to give new information.Just added the information.
@sdcguy: could it be that you're trying to execute the
cpp
file directly (ie: as./testimage.cpp
in a terminal)? This is C++ and that needs to compiled before you can run the executable.If the only thing you're trying to do is to save
sensor_msgs/Image
to disk (so don't want to process them in your node), then take a look atimage_saver
in the image_view package.