34 #include <image_view/ImageViewConfig.h> 38 #include <dynamic_reconfigure/server.h> 41 #include <opencv2/highgui/highgui.hpp> 43 #include <boost/format.hpp> 44 #include <boost/thread.hpp> 45 #include <boost/filesystem.hpp> 68 void imageCb(
const sensor_msgs::ImageConstPtr& msg)
84 if (msg->encoding ==
"32FC1") {
86 }
else if (msg->encoding ==
"16UC1") {
97 msg->encoding.c_str(), e.what());
109 static void mouseCb(
int event,
int x,
int y,
int flags,
void* param)
111 if (event == cv::EVENT_LBUTTONDOWN) {
112 ROS_WARN_ONCE(
"Left-clicking no longer saves images. Right-click instead.");
114 }
else if (event != cv::EVENT_RBUTTONDOWN) {
123 ROS_WARN(
"Couldn't save image, no data!");
128 if (cv::imwrite(filename, image)) {
129 ROS_INFO(
"Saved image %s", filename.c_str());
132 boost::filesystem::path full_path = boost::filesystem::complete(filename);
133 ROS_ERROR_STREAM(
"Failed to save image. Have permission to write there?: " << full_path);
138 int main(
int argc,
char **argv)
142 ROS_WARN(
"Topic 'image' has not been remapped! Typical command-line usage:\n" 143 "\t$ rosrun image_view image_view image:=<image topic> [transport]");
155 std::string format_string;
156 local_nh.
param(
"filename_format", format_string, std::string(
"frame%04i.jpg"));
161 local_nh.
param(
"autosize", autosize,
false);
162 cv::namedWindow(
g_window_name, autosize ? (CV_WINDOW_AUTOSIZE | CV_WINDOW_KEEPRATIO | CV_GUI_EXPANDED) : 0);
165 if(autosize ==
false)
172 local_nh.
getParam(
"height", height);
185 std::string transport;
186 local_nh.
param(
"image_transport", transport, std::string(
"raw"));
189 for (
size_t i = 1; i < myargv.size(); ++i) {
190 if (myargv[i][0] !=
'-') {
191 transport = myargv[i];
199 g_pub = local_nh.
advertise<sensor_msgs::Image>(
"output", 1);
201 dynamic_reconfigure::Server<image_view::ImageViewConfig> srv;
202 dynamic_reconfigure::Server<image_view::ImageViewConfig>::CallbackType
f =
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
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())
void imageCb(const sensor_msgs::ImageConstPtr &msg)
bool g_do_dynamic_scaling
static void mouseCb(int event, int x, int y, int flags, void *param)
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char **argv)
boost::format g_filename_format
boost::mutex g_image_mutex
std::string resolveName(const std::string &name, bool remap=true) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
#define ROS_ERROR_THROTTLE(rate,...)
std::vector< std::string > V_string
ROSCPP_DECL std::string remap(const std::string &name)
std::string g_window_name
#define ROS_WARN_ONCE(...)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
CvImageConstPtr cvtColorForDisplay(const CvImageConstPtr &source, const std::string &encoding=std::string(), const CvtColorForDisplayOptions options=CvtColorForDisplayOptions())
ROSCPP_DECL void removeROSArgs(int argc, const char *const *argv, V_string &args_out)
void reconfigureCb(image_view::ImageViewConfig &config, uint32_t level)
bool hasParam(const std::string &key) const
#define ROS_ERROR_STREAM(args)