publish an array of images
Hi,
I am trying to publish an array of images. Looking at ros wiki I couldn't find something relevant... I am attaching below my code... The publishing of the array should be at the "try" clause. Any help or hints would be appreciated.
Thanks.
#include "boost/filesystem.hpp"
#include "sensor_msgs/Image.h"
#include "image_transport/image_transport.h"
#include "cv_bridge/CvBridge.h"
#include "std_msgs/String.h"
#include <iostream>
#include <string>
#include <vector>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <ros/ros.h>
#include <signal.h>
using namespace boost::filesystem;
using namespace std;
void ctrlc(int s)
{
cout << "ctrl-c pressed" << endl;
ros::shutdown();
signal(SIGINT, SIG_DFL);
}
int main(int argc, char *argv[])
{
ros::init(argc, argv, "Static_Image_Publisher");
ros::NodeHandle n;
image_transport::ImageTransport it_(n);
sensor_msgs::CvBridge bridge_;
image_transport::Publisher image_pub_;
image_pub_ = it_.advertise("/camera_sim/image_raw", 1);
int cvDelay = (argc == 2 ? atoi(argv[1]) : 500);
string p(argc == 3 ? argv[2] : ".");
vector<string> filenames;
IplImage *img = NULL;
vector<IplImage*> imgs;
if (is_directory(p))
for (directory_iterator itr(p); itr!=directory_iterator(); ++itr)
if (is_regular_file(itr->status())) {
string str(itr->path().file_string());
filenames.push_back(str);
}
sort(filenames.begin(), filenames.end());
signal(SIGINT, ctrlc);
for(;;) {
imgs.clear();
for (vector<string>::iterator itr = filenames.begin(); itr != filenames.end(); ++itr) {
img = cvLoadImage(itr->c_str());
imgs.push_back(img);
}
try {
cout << ".\n";
// publishes one image at a time, how would I publish the array of images
//image_pub_.publish(bridge_.cvToImgMsg(imgs[0], "bgr8"));
} catch (sensor_msgs::CvBridgeException error) {
ROS_ERROR("error");
}
}
ros::spin();
return 0;
}