Cannot save image from the drone

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)


    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)

            rospy.loginfo('receiving image......')
        except KeyboardInterrupt:
            print("Shutting down")


if __name__ == '__main__':

    ROS_cv2_image = ROS_CV2_Image_Class()

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 cv2.imwrite() ?

if you do not find the correct path you could do several things.

1 - look at the expected path
2 - import os and print the path
import os
3 - in the command line look for the expected file by: find / -name test_image_1.jpg | grep test_image_1.jpg

Remember that you are executing the code in a path probably different from the saved path

Hi @issaiass ,
thank you! I find the saved image. I took it for granted that the excuting path is where my .py file is, but it turns out that it is /home/simulation/.ros.

1 Like