Saving image with OpenCV in online platform


Hello, I tried to save image with OpenCV using this code:

image_msg = camera_right.value
if image_msg is not None:
img = CvBridge().imgmsg_to_cv2(image_msg, “rgb8”)
cv2.imwrite(‘somefile.png’, img)

The image doesn’t save and i think it’s beacuse I have to specify the path.

I’d like to ask if there’s a path prefix I have to use when using online HBP or there’s other way to save image.

Thanks for your help.


Please try to give the “resources” path and check if the files is saved under “resources” from the online file explorer.



Thank you for your response.

I tried using only “resources”, but got an error, that there’s no writer for such file.

Current Code:

                    headers=["My_header1", "My_header2", "My_header3"])


def record_right_image (t, recorder, camera_right):
    image_msg = camera_right.value;
    if image_msg is not None:
        img = CvBridge().imgmsg_to_cv2(image_msg, "rgb8")
        recorder.record_entry('{:.0f}'.format(t), img, "data3", "data4")
        cv2.imwrite("resources/myfile2.png", img)

If I tried, to print img (converted file), I only got it in csv as [values] … [values] … [values], like it’s only preview of data. So the conversion is alright.

But still the last line doesn’t save the file. I assume the path should be specified in another way.


Also tried creating py Module I imported into resources:

import cv2
class FileSaver:
    def __init__(self):
def save_file(self, image):
    cv2.imwrite("file.png", image)

using import FileSaver I get an error:
global name ‘FileSaver’ is not defined (Runtime)


Dear Adrian,

There is actually no simple way to do it yet. So I added a feature request for you and we will handle this asap.

Sorry, that this is the best answer I can give you so far.
Best regards