示例#1
0
    def grab_and_save_img_execute_cb(self, grab_and_save_img_goal,
                                     action_client, action_server):
        grab_imgs_goal = GrabImagesGoal()
        self.convert_goals(grab_and_save_img_goal, grab_imgs_goal)

        action_client.send_goal(grab_imgs_goal)
        action_client.wait_for_result(rospy.Duration.from_sec(10.0))
        grab_imgs_result = action_client.get_result()

        grab_and_save_img_result = GrabAndSaveImageResult()

        if grab_imgs_result is not None and grab_imgs_result.success:
            filename = grab_and_save_img_goal.img_storage_path_and_name
            try:
                cv_img = CvBridge().imgmsg_to_cv2(
                    grab_imgs_result.images[0], desired_encoding='passthrough')
            except CvBridgeError as exception:
                rospy.logerr('Error converting img_msg_to_cv_img: ' +
                             str(exception))
                grab_and_save_img_result.success = False

            rospy.loginfo('Writing image to ' + filename)
            cv2.imwrite(filename, cv_img)
            grab_and_save_img_result.success = True
        else:
            grab_and_save_img_result.success = False
        action_server.set_succeeded(grab_and_save_img_result)
    def trigger_cb(self, msg):
        grab_imgs_goal = GrabImagesGoal()

        grab_imgs_goal.exposure_given = True
        grab_imgs_goal.exposure_times = [
            rospy.get_param('~exposure_time', 20000.0)
        ]
        grab_imgs_goal.gain_given = True
        grab_imgs_goal.gain_values = [0.2]
        grab_imgs_goal.gain_auto = False

        self._grab_imgs_rect_ac.send_goal(grab_imgs_goal)
        self._grab_imgs_rect_ac.wait_for_result(rospy.Duration.from_sec(10.0))
        grab_imgs_result = self._grab_imgs_rect_ac.get_result()
        rospy.loginfo("Got image")
        if len(grab_imgs_result.images) > 0:
            rospy.loginfo("publish image")
            self.pub.publish(grab_imgs_result.images[0])