movement_from_image.cpp
Go to the documentation of this file.
1 
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  const Magick::PixelPacket* pixel_cache = image_->getConstPixels(0, 0, nb_cols_, nb_rows_);
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  const Magick::PixelPacket* tmp_pixel = pixel_cache + row * nb_cols_ + col;
61  if (tmp_pixel->red != 0xFFFF && tmp_pixel->green != 0xFFFF
62  && tmp_pixel->blue != 0xFFFF)
63  {
64  no_pixel = false;
65  steps.push_back(1.0 - static_cast<double>(row) / static_cast<double>(nb_rows_));
66  break;
67  }
68  }
69  if (no_pixel)
70  {
71  // not sending any targets for this point.
72  steps.push_back(-1.0);
73  }
74  }
75  }
76 } // namespace shadowrobot
77 
78 /* For the emacs weenies in the crowd.
79 Local Variables:
80  c-basic-offset: 2
81 End:
82 */
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 Tue Oct 13 2020 03:50:46