tactile_filter.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * \file
00003  *
00004  * $Id:$
00005  *
00006  * Copyright (C) Brno University of Technology
00007  *
00008  * This file is part of software developed by dcgm-robotics@FIT group.
00009  *
00010  * Author: Zdenek Materna (imaterna@fit.vutbr.cz)
00011  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00012  * Date: dd/mm/2012
00013  *
00014  * This file is free software: you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as published by
00016  * the Free Software Foundation, either version 3 of the License, or
00017  * (at your option) any later version.
00018  *
00019  * This file is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 #include <srs_assisted_grasping/tactile_filter.h>
00029 
00030 using namespace srs_assisted_grasping;
00031 
00032 void TactileFilter::TactileDataCallback(const schunk_sdh::TactileSensor::ConstPtr & msg) {
00033 
00034         boost::mutex::scoped_lock(tact_data_mutex_);
00035 
00036         if (!data_received_) {
00037 
00038                 tact_data_.resize(msg->tactile_matrix.size());
00039                 tact_data_filtered_.resize(msg->tactile_matrix.size());
00040 
00041                 data_received_ = true;
00042 
00043                 ROS_INFO("First tactile data received (%u pads)",(unsigned int)tact_data_.size());
00044 
00045         }
00046 
00047         schunk_sdh::TactileSensor data = *msg;
00048 
00049         // convert it to opencv representation
00050         for (unsigned int i=0; i < data.tactile_matrix.size(); i++) {
00051 
00052                 cv::Mat tmp;
00053 
00054                 int x = data.tactile_matrix[i].cells_x;
00055                 int y = data.tactile_matrix[i].cells_y;
00056 
00057                 tmp = cv::Mat::zeros(x, y, CV_16S);
00058 
00059                 for(int a = 0; a < x*y; a++) {
00060 
00061                         tmp.at<int16_t>(a / y, a % x) = (int16_t)data.tactile_matrix[i].tactile_array[a];
00062 
00063                 }
00064 
00065                 tact_data_[i] = tmp;
00066 
00067         }
00068 
00069 
00070         // filter it
00071         for (unsigned int i=0; i < tact_data_.size(); i++) {
00072 
00073                 tact_data_filtered_[i] = tact_data_[i].clone();
00074 
00075                 cv::Scalar mean(0.0),stddev(0.0),mean_f(0.0),stddev_f(0.0);
00076                 double min,min_f,max,max_f;
00077 
00078                 min = min_f = max = max_f = 0;
00079 
00080                 cv::meanStdDev(tact_data_[i],mean,stddev);
00081 
00082                 if (params_.median_prefilter) {
00083 
00084                         // prefilter with median - can be disabled by parameter
00085                         cv::medianBlur(tact_data_filtered_[i],tact_data_filtered_[i],(unsigned int)params_.median_width);
00086 
00087                 }
00088 
00089                 cv::GaussianBlur(tact_data_filtered_[i],
00090                                 tact_data_filtered_[i],
00091                                 cv::Size((unsigned int)params_.gaussian_width, (unsigned int)params_.gaussian_height),
00092                                 (unsigned int)params_.gaussian_sigma_x,
00093                                 (unsigned int)params_.gaussian_sigma_y);
00094 
00095                 cv::meanStdDev(tact_data_filtered_[i],mean_f,stddev_f);
00096 
00097                 cv::minMaxLoc(tact_data_[i],&min,&max);
00098                 cv::minMaxLoc(tact_data_filtered_[i],&min_f,&max_f);
00099 
00100                 // print debugging info only if there are some values other than zero...
00101                 if (mean.val[0]!=0) {
00102 
00103                         //std::cout << "pad " << i << " " << mean.val[0] << ", filt: " << mean_f.val[0] << std::endl;
00104 
00105                         ROS_DEBUG("Pad %u, unfiltered: %d / %d,  %d / %d, filtered: %d / %d,  %d / %d",i,
00106                                         (int16_t)mean.val[0], (int16_t)stddev.val[0], (int16_t)min, (int16_t)max,
00107                                         (int16_t)mean_f.val[0], (int16_t)stddev_f.val[0], (int16_t)min_f, (int16_t)max_f);
00108 
00109                 }
00110 
00111         } // for
00112 
00113 
00114         // convert opencv representation back to TactileSensor message
00115         for (unsigned int i=0; i < data.tactile_matrix.size(); i++) {
00116 
00117                         int x = data.tactile_matrix[i].cells_x;
00118                         int y = data.tactile_matrix[i].cells_y;
00119 
00120                         cv::Mat tmp = tact_data_[i];
00121 
00122                         for(int a = 0; a < x*y; a++) {
00123 
00124                                 data.tactile_matrix[i].tactile_array[a] = tmp.at<int16_t>(a / y, a % x);
00125 
00126                         }
00127 
00128 
00129                 }
00130 
00131         // publish it
00132         tact_publisher_.publish(data);
00133 
00134 }
00135 
00136 int main(int argc, char** argv)
00137 {
00138 
00139       ROS_INFO("Starting tactile filtering node");
00140       ros::init(argc, argv, "but_tactile_filtering_node");
00141 
00142 
00143       TactileFilter filter;
00144 
00145       ROS_INFO("Spinning...");
00146 
00147       ros::spin();
00148       ros::shutdown();
00149 
00150 }


srs_assisted_grasping
Author(s): Zdenek Materna
autogenerated on Mon Oct 6 2014 07:59:09