Go to the documentation of this file.00001 #include "image_publisher_alg_node.h"
00002
00003 ImagePublisherAlgNode::ImagePublisherAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<ImagePublisherAlgorithm>(), imgtransport_(public_node_handle_)
00005 {
00006
00007
00008 image_pub_ = imgtransport_.advertise("image", 1);
00009
00010 this->filename_ = "~/default.jpg";
00011 cv_image.header.stamp = ros::Time::now();
00012 cv_image.header.frame_id = "camera";
00013 cv_image.encoding = "bgr8";
00014
00015 ROS_INFO("Image reading");
00016 cv_image.image = cv::imread(this->filename_);
00017 ROS_INFO("Image read");
00018
00019 if(cv_image.image.data==NULL){
00020 ROS_ERROR("Image %s could not be read", this->filename_.c_str());
00021 image_loaded = false;
00022 }else{
00023 ROS_INFO("Image %s read", this->filename_.c_str());
00024 image_loaded = true;
00025 }
00026
00027 ROS_INFO("Image read");
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 }
00041
00042 ImagePublisherAlgNode::~ImagePublisherAlgNode(void)
00043 {
00044
00045 }
00046
00047 void ImagePublisherAlgNode::mainNodeThread(void)
00048 {
00049 this->alg_.lock();
00050 if(image_loaded){
00051
00052 image_pub_.publish(cv_image.toImageMsg());
00053 }else{
00054
00055 }
00056 this->alg_.unlock();
00057
00058
00059
00060
00061
00062
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 void ImagePublisherAlgNode::node_config_update(Config &config, uint32_t level)
00074 {
00075 this->alg_.lock();
00076
00077 ROS_INFO("Image reading config");
00078 this->filename_ = config.filename;
00079
00080 cv_image.header.stamp = ros::Time::now();
00081 cv_image.header.frame_id = "camera";
00082 cv_image.encoding = "bgr8";
00083 ROS_INFO("Image reading");
00084 cv_image.image = cv::imread(filename_, -1);
00085
00086 if(cv_image.image.data==NULL){
00087 ROS_ERROR("Image %s could not be read", this->filename_.c_str());
00088 image_loaded = false;
00089 }else{
00090 ROS_INFO("Image %s read", this->filename_.c_str());
00091 image_loaded = true;
00092 }
00093
00094 this->alg_.unlock();
00095 }
00096
00097 void ImagePublisherAlgNode::addNodeDiagnostics(void)
00098 {
00099 }
00100
00101
00102 int main(int argc,char *argv[])
00103 {
00104 return algorithm_base::main<ImagePublisherAlgNode>(argc, argv, "image_publisher_alg_node");
00105 }