movement_from_image.cpp
Go to the documentation of this file.
1 /*
2 * Copyright 2019 Shadow Robot Company Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
27 #include <iostream>
28 #include <string>
29 
31 #include <ros/ros.h>
32 
33 namespace shadowrobot
34 {
35  MovementFromImage::MovementFromImage(std::string image_path)
36  : PartialMovement()
37  {
38  image_ = boost::shared_ptr<Magick::Image>( new Magick::Image() );
39  image_->read(image_path);
40 
41  nb_cols_ = image_->columns();
42  nb_rows_ = image_->rows();
43 
45  }
46 
48  {}
49 
50 
52  {
53  Magick::Color white("white");
54 
55  for (ssize_t col = 0; col < nb_cols_; ++col)
56  {
57  bool no_pixel = true;
58  for (ssize_t row = 0; row < nb_rows_; ++row)
59  {
60  if (image_->pixelColor(row, col) != white)
61  {
62  no_pixel = false;
63  steps.push_back(1.0 - static_cast<double>(row) / static_cast<double>(nb_rows_));
64  break;
65  }
66  }
67  if (no_pixel)
68  {
69  // not sending any targets for this point.
70  steps.push_back(-1.0);
71  }
72  }
73  }
74 } // namespace shadowrobot
75 
76 /* For the emacs weenies in the crowd.
77 Local Variables:
78  c-basic-offset: 2
79 End:
80 */
ssize_t nb_cols_
The number of columns in the image.
Reads a png file and creates a movement from it.
ssize_t nb_rows_
The number of rows in the image.
boost::shared_ptr< Magick::Image > image_
The image from which the movement is generated.
MovementFromImage(std::string image_path)
std::vector< double > steps


sr_movements
Author(s): Ugo Cupcic
autogenerated on Fri Mar 11 2022 03:29:39