Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

some Utilities:

#include <sstream>
#include <string>

#define SPACE_KEY (32)

    template<typename T> 
    inline std::string toString( const T& ao_Obj )
    {
      std::stringstream lo_stream;

      lo_stream << ao_Obj;

      return lo_stream.str();
    }

Then later in your code

  cv::imshow("OpenCV viewer uEye RGB", cv_ptr->image);    
  int key = cv::waitKey( 50 );

    if ( key == SPACE_KEY )
    {
       static int count = 0;
       ROS_ASSERT( cv::imwrite( std::string( "file" )  + toString( count++ )  + std::string( ".png" ), cv_ptr->image ) );
    }

Note that the cv window has to be the active one when the space key is pressed in order for saving the image. Note that your space press has to hit the 50 ms waiting duration, maybe a longer value is better here, but it will slow down your node....