optris_binary_image_node.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012-2016
5  * Technische Hochschule Nürnberg Georg Simon Ohm
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Nuremberg Institute of Technology
19  * Georg Simon Ohm nor the authors names may be used to endorse
20  * or promote products derived from this software without specific
21  * prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * Author: Christian Pfitzner
37  *********************************************************************/
38 
39 #include "ros/ros.h"
41 #include <dynamic_reconfigure/server.h>
42 
43 #include <optris_drivers/ThresholdConfig.h>
44 
45 #include "libirimager/ImageBuilder.h"
46 
48 
49 double _threshold = 40.0;
50 bool _invert = false;
51 
52 
57 void onThermalDataReceive(const sensor_msgs::ImageConstPtr& image)
58 {
59  static unsigned int frame = 0;
60 
61  unsigned short* data = (unsigned short*)&image->data[0];
62 
63  sensor_msgs::Image img;
64  img.header.frame_id = "thermal_image_view";
65  img.height = image->height;
66  img.width = image->width;
67  img.encoding = "mono8";
68  img.step = image->width;
69  img.data.resize(img.height*img.step);
70  img.header.seq = ++frame;
71  img.header.stamp = ros::Time::now();
72 
73  // generate binary image from thermal data
74  for(unsigned int i=0; i<image->width*image->height; i++)
75  {
76  const double temp = (float(data[i]) -1000.0f)/10.0f;
77 
78  if(!_invert) {
79  if(temp > _threshold) img.data[i] = 0xff;
80  else img.data[i] = 0x00;
81  }
82  else {
83  if(temp > _threshold) img.data[i] = 0x00;
84  else img.data[i] = 0xff;
85  }
86 
87  }
88 
89  _pubThermal->publish(img);
90 }
91 
92 
98 void callback(optris_drivers::ThresholdConfig &config, uint32_t level)
99 {
100  _threshold = config.threshold;
101  _invert = config.invert;
102 }
103 
104 
114 int main (int argc, char* argv[])
115 {
116  ros::init (argc, argv, "optris_binary_image_node");
117 
118  // set up for dynamic reconfigure server
119  dynamic_reconfigure::Server<optris_drivers::ThresholdConfig> server;
120  dynamic_reconfigure::Server<optris_drivers::ThresholdConfig>::CallbackType f;
121 
122  f = boost::bind(&callback, _1, _2);
123  server.setCallback(f);
124 
125  // private node handle to support command line parameters for rosrun
126  ros::NodeHandle n_("~");
127 
128  // parameters for initialization
129  _threshold = 40.0;
130  n_.getParam("threshold", _threshold);
131  _invert = false;
132  n_.getParam("invert", _invert);
133 
134 
135  // init subscribers and publishers
136  ros::NodeHandle n;
138  image_transport::Subscriber subThermal = it.subscribe("thermal_image", 1, onThermalDataReceive);
139  image_transport::Publisher pubt = it.advertise("thermal_binary", 1);
140  _pubThermal = &pubt;
141 
142  // specify loop rate: a meaningful value according to your publisher configuration
143  ros::Rate loop_rate(30);
144  while (ros::ok())
145  {
146  ros::spinOnce();
147  loop_rate.sleep();
148  }
149 }
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
double _threshold
f
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
void onThermalDataReceive(const sensor_msgs::ImageConstPtr &image)
void callback(optris_drivers::ThresholdConfig &config, uint32_t level)
image_transport::Publisher * _pubThermal
void publish(const sensor_msgs::Image &message) const
ROSCPP_DECL bool ok()
bool sleep()
bool getParam(const std::string &key, std::string &s) const
static Time now()
int main(int argc, char *argv[])
ROSCPP_DECL void spinOnce()


optris_drivers
Author(s): Stefan May (Nuremberg Institute of Technology Georg Simon Ohm - www.th-nuernberg.de), 64-Bit platform supported by Fraunhofer IPA (www.ipa.fraunhofer.de), Support for ROS hydro migration by Christopher-Eyk Hrabia (DAI-Labor, Technische Universität Berlin)
autogenerated on Mon Jun 10 2019 14:09:58