--- image_pipeline.bak/image_view/src/nodes/image_saver.cpp	2013-10-26 19:24:57.928517468 +0900
+++ image_pipeline/image_view/src/nodes/image_saver.cpp	2013-11-01 10:25:42.255514317 +0900
@@ -13,51 +13,64 @@
 std::string encoding;
 std::string format_string;
 std::string enc_param, format_param;
+std::string topic;
 
 bool service(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res) {
   save_image_service = true;
-  return true;
+  float waitTime = 5.0;
+  if (ros::topic::waitForMessage<sensor_msgs::Image>(topic, ros::Duration(waitTime)))
+  {
+	  return true;
+  } else {
+	  ROS_WARN("Couldn't save image, no image data received in topic %s for %f secs!", topic.c_str(), waitTime);
+	  return false;
+  }
 }
 
 void callback(const sensor_msgs::ImageConstPtr& image_msg, const sensor_msgs::CameraInfoConstPtr& info)
 {
-  ros::param::get(format_param, format_string);
-  g_format.parse(format_string);
-  ros::param::get(enc_param, encoding);
+	ros::param::get(format_param, format_string);
+	g_format.parse(format_string);
+	ros::param::get(enc_param, encoding);
 
   cv::Mat image;
   try
   {
-    image = cv_bridge::toCvShare(image_msg, encoding)->image;
+	  image = cv_bridge::toCvShare(image_msg, encoding)->image;
   } catch(cv_bridge::Exception)
   {
-    ROS_ERROR("Unable to convert %s image to bgr8", image_msg->encoding.c_str());
-    return;
+	  ROS_ERROR("Unable to convert %s image to bgr8", image_msg->encoding.c_str());
+	  return;
   }
+
   
-    if (!image.empty()) {
-      std::string filename;
-      try {
-        filename = (g_format).str();
-      } catch (...) { g_format.clear(); }
-      try {
-        filename = (g_format % g_count).str();
-      } catch (...) { g_format.clear(); }
-      try {
-        filename = (g_format % g_count % "jpg").str();
-      } catch (...) { g_format.clear(); }
-      if ( save_all_image || save_image_service ) {
-        cv::imwrite(filename, image);
-        ROS_INFO("Saved image %s", filename.c_str());
-        filename = filename.replace(filename.rfind("."), filename.length(),".ini");
-        camera_calibration_parsers::writeCalibration(filename, "camera", *info);
+  if ( save_all_image || save_image_service ) {
+	  if (!image.empty()) {
+		  std::string filename;
+		  try {
+			  filename = (g_format).str();
+		  } catch (...) { g_format.clear(); }
+		  try {
+			  filename = (g_format % g_count).str();
+		  } catch (...) { g_format.clear(); }
+		  try {
+			  filename = (g_format % g_count % "jpg").str();
+		  } catch (...) { g_format.clear(); }
+		  if ( cv::imwrite(filename, image)) {
+			  ROS_INFO("Saved image %s", filename.c_str());
+			  filename = filename.replace(filename.rfind("."), filename.length(),".ini");
+			  camera_calibration_parsers::writeCalibration(filename, "camera", *info);
         
-        g_count++;
-        save_image_service = false;
-      }
-    } else {
-      ROS_WARN("Couldn't save image, no data!");
-    }
+			  g_count++;
+		  } else {
+			  ROS_WARN("Couldn't save image %s", filename.c_str());
+			  ROS_WARN("Does the specified folder exist? Please specify an absolute path.");
+		  }
+	  } else {
+		  ROS_WARN("Couldn't save image, no data!");
+	  }
+	  save_image_service = false;
+  }
 }
 
 int main(int argc, char** argv)
@@ -65,7 +78,7 @@
   ros::init(argc, argv, "image_saver", ros::init_options::AnonymousName);
   ros::NodeHandle nh;
   image_transport::ImageTransport it(nh);
-  std::string topic = nh.resolveName("image");
+  topic = nh.resolveName("image");
   image_transport::CameraSubscriber sub = it.subscribeCamera(topic, 1, &callback);
   ros::NodeHandle local_nh("~");
   std::string format_string;
