RPI3: Trying to cv::imwrite to external usb

asked 2017-03-15 05:01:41 -0600

Agju gravatar image

updated 2017-03-15 05:02:17 -0600

I'm trying to save an image received from a callback to an external USB drive using OpenCV3.1 cv::imwrite.

I have mounted the USB into /media/usb with ownership to "pi", and I can move/copy/delete files using CLI without the need of "su" nor "sudo", so I think I did it right.

The problem is that when I try to save an image using cv::imwrite, it simply does not save. I added a ROS_ASSERT to the cv::imwrite, and the node simply shutsdown. I also looked at the logs, but cannot find anything relevant because the node simply shutsdown.

Here's the code:

bool camera::takeScreenshotService(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res)
{
    time_t now;
    time(&now);
    struct tm* current_time = localtime(&now);
    char buffer[256];
    strftime(buffer, sizeof(buffer), "%Y-%m-%d_%T", current_time);
    std::string current_time_s(buffer);
    std::string image_name = save_image_path + current_time_s + image_extension;

    ROS_ASSERT( cv::imwrite(image_name, image_rec) );

    res.success = true;
    return true;
}

image_rec is received in the camera callback, and save_image_path and image_extension are global parameters. All these are set correctly, because when I change the path to a "local" path (like /home/pi) it works flawlessly.

Is it possible that I need to change or modify the ownership or persmissions when mounting the USB in order to be able to save files using ROS?

edit retag flag offensive close merge delete

Comments

This is most likely not ROS specific. Can you create a minimal test program that tries to save a file on your usb storage device? If that uses the same code and also "simply does not save", then that would point to something else.

gvdhoorn gravatar image gvdhoorn  ( 2017-03-15 13:55:22 -0600 )edit

I have created a very simple program using "fopen" and it works flawlessly also: I'm able to write a "file.txt" directly to the USB drive. I think that maybe when "launching" ROS the user/permissions are not the same as running a program directly from CL

Agju gravatar image Agju  ( 2017-03-16 03:49:36 -0600 )edit