#include <ros/ros.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <iomanip>
#include <opencv2/objdetect.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#include "std_msgs/Int32.h"
#include <vector>
#include <std_msgs/String.h>
#include <stdio.h>
#include <sensor_msgs/Image.h>
#include<cv_bridge/cv_bridge.h>
#include<sensor_msgs/image_encodings.h>
#include<image_transport/image_transport.h>
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
ros::init(argc, argv, "test_carema");
ros::NodeHandle nh;
ros::Rate loop_rate(1.0);
ROS_INFO_STREAM("Hello, ROS!");
boost::shared_ptr<sensor_msgs::Image const> image_sub;
image_sub = ros::topic::waitForMessage<sensor_msgs::Image>("/usb_cam/image_raw",ros::Duration(3));
//image_sub = ros::topic::waitForMessage<sensor_msgs::Image>("/usb_cam/image_raw",(ros::NodeHandle *)&nh, ros::Duration(3));
if(image_sub != NULL)
{
sensor_msgs::Image image_raw = *image_sub;
//cout<<"battery:"<< bat <<endl;
//cout<<"battery:"<< image_sub <<endl;
cv_bridge::CvImagePtr cv_ptr = cv_bridge::toCvCopy(image_raw, sensor_msgs::image_encodings::BGR8);
Mat img = cv_ptr -> image;
std::string image_name = "image.jpg";
std::string path = "/home/muyuan/" + image_name;
cv::imwrite(path.c_str(), img);
//cv::imshow("image", img);
ROS_INFO("image ok!");
//cv::waitKey(1);
}
else
{
cout<<"no topic image_sub"<<endl;
}
ROS_INFO("ok!");
ros::MultiThreadedSpinner spinner(0);
spinner.spin();
return 0;
}