Try to flip an image with transformImage

Typically: "How do I... ", "How can I... " questions
Post Reply
juhel
Posts: 29
Joined: 22 Nov 2020, 23:10

Try to flip an image with transformImage

Post by juhel »

Hi,

I want to flip an image in a publisher method so , following this post
https://forum.coppeliarobotics.com/view ... age#p36724
I use this python code :

Code: Select all

 data, resolution = sim.getVisionSensorImg(self.visionSensor)
        msg = Image()
        msg.header.stamp = self.get_clock().now().to_msg()
        msg.height = resolution[1]
        msg.width = resolution[0]
        msg.encoding = 'rgb8'
        msg.is_bigendian = 1
        msg.step = resolution[0] * 3
        msg.data = data
        sim.transformImage(msg.data,resolution,2)
        self.publisher.publish(msg)
but when I insert the line sim.transformImage(msg.data,resolution,2), I get this error message :

Code: Select all

[/ros2InterfaceControlledBubbleRob/script:warning]   Received non-serializable data: [array('B', [0, 0, 0, 0, 0, 0, 0, 0, .....
If I remove this line, everything is fine, except that the image in up side down.

What is the correct way to use this method?

Regards,

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

Re: Try to flip an image with transformImage

Post by coppelia »

Hello,

there is a bug in the Python version of sim.transformImage (as of CoppeliaSim V4.9.0. rev6). So you should use a workaround, something like:

Code: Select all

'''luaExec
function flip(data, res, opt)
    sim.transformImage(data, res, opt)
    return data
end
'''
...

msg.data = sim.transformImage(msg.data, resolution, 2)
Cheers
Post Reply