Save Greyscale Image from Vision Sensor

Typically: "How do I... ", "How can I... " questions
Post Reply
mirovoellmy
Posts: 1
Joined: 25 Jan 2019, 13:06

Save Greyscale Image from Vision Sensor

Post by mirovoellmy »

Hi,
I'm trying to record a greyscale vision sensor and save some images to drive using sim.saveImage().
The documentation describes that the the function can only handle rgb and rgbd images. Did I miss something or do I have to manually convert my greyscale [res_x * res_y] image to a rgb [res_x * res_y * 3] image everytime I want to save an image?

If yes, it would be nice to have an option in the saveImage() function so it can also save grayscale images. :)

Thanks

Miro

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Save Greyscale Image from Vision Sensor

Post by coppelia »

Hello,

you can use sim.transformBuffer for that:

Code: Select all

rgbImage=sim.transformBuffer(greyImage,sim.buffer_uint8,1,0,sim.buffer_uint8rgb)
Cheers

ales_v
Posts: 4
Joined: 12 May 2020, 08:29

Re: Save Greyscale Image from Vision Sensor

Post by ales_v »

Hello,

I would like to ask if there is an oportunity to save grayscale image (monocolor or 8bit depth).

My goal is to have a small file but in good quality.

Thank you

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Save Greyscale Image from Vision Sensor

Post by coppelia »

Hello,

as of CoppeliaSim 4.0.0, this is unfortunately not possible. But in next release you'll be able to do that with, e.g.:

Code: Select all

        local img,resX,resY=sim.getVisionSensorCharImage(visionSensorHandle)
        img=sim.transformBuffer(img,sim.buffer_uint8rgb,1,0,sim.buffer_uint8)
        sim.saveImage(img,{resX,resY},2,"testImg.png",100)
Cheers

lynsdu
Posts: 5
Joined: 21 May 2020, 14:51

Re: Save Greyscale Image from Vision Sensor

Post by lynsdu »

hi there,

I am currently using b0 remote API with C++ on visual studio, do you know how to save an image from the vision sensor?

Code: Select all

int visionsensor = b0RemoteApi::readInt(client.simxGetObjectHandle("Vision_sensor", client.simxServiceCall()), 1);
std::vector<msgpack::object>* imginfo = client.simxGetVisionSensorImage(visionsensor, 0, client.simxServiceCall());
b0RemoteApi::print(imginfo);
I have been checking examples but with any clue how to use functions to save it as an image. could you please provide some examples for that?

thanks.

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Save Greyscale Image from Vision Sensor

Post by coppelia »

Hello,

to save an image from CoppeliaSim is quite immediate with the sim.saveImage function. From an external application, you'll have to use your own or a third-library routines to handle that. Here if you use Qt.

Cheers

ask4jubad
Posts: 21
Joined: 21 Sep 2021, 07:46

Re: Save Greyscale Image from Vision Sensor

Post by ask4jubad »

Hello Coppelia,

When one uses sim.saveImage where does the image reside?

I can seem to find it - perhaps it's not working for me. I don't get any error, so I am not sure if the saveImage works or not.

From either the external script or within an actuation function in my simulator, I run this:

Code: Select all

local img, resX, resY, sim.getVisionSensorCharImage(visionSensorHandle) -- in external python script, there is no keyword local though
sim.saveImage(img, {resX, resY}, 0, "test.png", 100) -- i've also tried [resX, resY] and I can't remember which combination returns an error.

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Save Greyscale Image from Vision Sensor

Post by coppelia »

Hello,

as far as I know, this will place the file in the CoppeliaSim folder. Best is to specify an absolute path.

Cheers

Post Reply