I am learning " OpenCV for Robotics". In first exercise, we need to show a picture from existed folder and save a picture from the drone. I can show picture from existed folder and from the drone:
But I cannot find the saved picture from the drone. I have tried to save it in default path and specific path, but both of them don’t work. Here is my code:
#! /usr/bin/env python import rospy import cv2 from sensor_msgs.msg import Image from cv_bridge import CvBridge class ROS_CV2_Image_Class(): def __init__(self): # define subscriber of topic '/camera/rgb/image_raw' self.camera_sub = rospy.Subscriber( '/camera/rgb/image_raw', Image, self.camera_callback) # define cv_bridge instance self.cv_bridge = CvBridge() # read a picture self.image_to_read_path = '/home/user/catkin_ws/src/opencv_for_robotics_images/Unit_2/Course_images/test_image_1.jpg' def camera_callback(self, msg): # get image from drone and save it self.image_from_drone = self.cv_bridge.imgmsg_to_cv2( msg, desired_encoding="bgr8") rospy.loginfo('show an image from the drone......') cv2.imshow('the image from the drone', self.image_from_drone) cv2.imwrite('drone_image.jpg', self.image_from_drone) cv2.waitKey(0) def main(self): # show an image rospy.loginfo('show an image that is already existed......') self.read_image = cv2.imread(self.image_to_read_path) cv2.imshow('the image to be read', self.read_image) try: rospy.spin() rospy.loginfo('receiving image......') except KeyboardInterrupt: print("Shutting down") cv2.destroyAllWindows() if __name__ == '__main__': rospy.init_node("ROS_cv2_image_node") ROS_cv2_image = ROS_CV2_Image_Class() ROS_cv2_image.main()
The saved image should be found in the path where this .py is runned or .launch file is launched, right?
Or did I do something wrong with