39 #include <image_publisher/ImagePublisherConfig.h> 41 #include <sensor_msgs/CameraInfo.h> 43 #include <opencv2/highgui/highgui.hpp> 44 #include <dynamic_reconfigure/server.h> 45 #include <boost/assign.hpp> 51 dynamic_reconfigure::Server<image_publisher::ImagePublisherConfig>
srv;
72 frame_id_ = new_config.frame_id;
77 if ( !new_config.camera_info_url.empty() ) {
82 }
catch(cv::Exception &e) {
83 NODELET_ERROR(
"camera calibration failed to load: %s %s %s %i", e.err.c_str(), e.func.c_str(), e.file.c_str(), e.line);
95 if ( cap_.isOpened() ) {
96 if ( ! cap_.read(image_) ) {
97 cap_.set(CV_CAP_PROP_POS_FRAMES, 0);
101 cv::flip(image_, image_, flip_value_);
104 out_img->header.frame_id = frame_id_;
106 camera_info_.header.frame_id = out_img->header.frame_id;
107 camera_info_.header.stamp = out_img->header.stamp;
109 pub_.
publish(*out_img, camera_info_);
111 catch (cv::Exception &e)
113 NODELET_ERROR(
"Image processing error: %s %s %s %i", e.err.c_str(), e.func.c_str(), e.file.c_str(), e.line);
130 subscriber_count_ = 0;
131 nh_ = getPrivateNodeHandle();
135 nh_.
param(
"filename", filename_, std::string(
""));
136 NODELET_INFO(
"File name for publishing image is : %s", filename_.c_str());
138 image_ = cv::imread(filename_, CV_LOAD_IMAGE_COLOR);
139 if ( image_.empty() ) {
141 int num = boost::lexical_cast<
int>(filename_);
143 }
catch(boost::bad_lexical_cast &) {
144 cap_.open(filename_);
146 CV_Assert(cap_.isOpened());
148 cap_.set(CV_CAP_PROP_POS_FRAMES, 0);
150 CV_Assert(!image_.empty());
152 catch (cv::Exception &e)
154 NODELET_ERROR(
"Failed to load image (%s): %s %s %s %i", filename_.c_str(), e.err.c_str(), e.func.c_str(), e.file.c_str(), e.line);
157 bool flip_horizontal;
158 nh_.
param(
"flip_horizontal", flip_horizontal,
false);
159 NODELET_INFO(
"Flip horizontal image is : %s", ((flip_horizontal)?
"true":
"false"));
162 nh_.
param(
"flip_vertical", flip_vertical,
false);
163 NODELET_INFO(
"Flip flip_vertical image is : %s", ((flip_vertical)?
"true":
"false"));
168 if (flip_horizontal && flip_vertical)
170 else if (flip_horizontal)
172 else if (flip_vertical)
177 camera_info_.width = image_.cols;
178 camera_info_.height = image_.rows;
179 camera_info_.distortion_model =
"plumb_bob";
180 camera_info_.D = list_of(0)(0)(0)(0)(0).convert_to_container<std::vector<double> >();
181 camera_info_.K = list_of(1)(0)(camera_info_.width/2)(0)(1)(camera_info_.height/2)(0)(0)(1);
182 camera_info_.R = list_of(1)(0)(0)(0)(1)(0)(0)(0)(1);
183 camera_info_.P = list_of(1)(0)(camera_info_.width/2)(0)(0)(1)(camera_info_.height/2)(0)(0)(0)(1)(0);
187 dynamic_reconfigure::Server<image_publisher::ImagePublisherConfig>::CallbackType
f =
188 boost::bind(&ImagePublisherNodelet::reconfigureCallback,
this, _1, _2);
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
#define NODELET_ERROR(...)
sensor_msgs::CameraInfo getCameraInfo(void)
PLUGINLIB_EXPORT_CLASS(image_publisher::ImagePublisherNodelet, nodelet::Nodelet)
bool loadCameraInfo(const std::string &url)
void disconnectCb(const image_transport::SingleSubscriberPublisher &)
void reconfigureCallback(image_publisher::ImagePublisherConfig &new_config, uint32_t level)
bool validateURL(const std::string &url)
CameraPublisher advertiseCamera(const std::string &base_topic, uint32_t queue_size, bool latch=false)
void do_work(const ros::TimerEvent &event)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
dynamic_reconfigure::Server< image_publisher::ImagePublisherConfig > srv
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
image_transport::CameraPublisher pub_
#define NODELET_INFO(...)
sensor_msgs::CameraInfo camera_info_
boost::shared_ptr< image_transport::ImageTransport > it_
sensor_msgs::ImagePtr toImageMsg() const
void connectCb(const image_transport::SingleSubscriberPublisher &ssp)