robotology / yarp

YARP - Yet Another Robot Platform
http://www.yarp.it
Other
527 stars 195 forks source link

Error : Failed to connect to the camera module in Gazebo with yarp server #3125

Open 16239014 opened 3 months ago

16239014 commented 3 months ago

@LoreMoretti I am working on gazebo with an icub humanoid robot model running this example https://icub-tech-iit.github.io/documentation/sw_installation/check_your_installation/#check-icub

when I run these commands it shows that it did not connect with the camera. can you help to resolve it?

To view the output from the cameras in terminals

yarpview --name /view/left
yarpview --name /view/right

And to connect them:

yarp connect /icubSim/cam/left/rgbImage:o /view/left
yarp connect /icubSim/cam/right/rgbImage:o /view/right

I also try code:

import yarp
import sys
# Initialize YARP network
yarp.Network.init()

# Create a port to read from the camera
image_port = yarp.Port()
image_port.open("/client/image/in")

# Connect to the camera port
if not yarp.Network.connect("/icubSim/cam/left/rgbImage:0", "/client/image/in"):
    print("Failed to connect to the camera 123.")
    sys.exit()

# Prepare a YARP image to receive data
yarp_image = yarp.ImageRgb()
yarp_image.resize(640, 480)  # Set the resolution

# Read from the port
if image_port.read(yarp_image):
    print("Image received!")

# Close the port
image_port.close()
yarp.Network.fini()
randaz81 commented 2 months ago

The code contains a typo: rgbImage:0 instead of rgbImage:o. If you still have issues, use the command yarp name list to verify the name of the ports streaming the robot cameras, then use the command yarp stats <PORT_NAME> to check the output of these ports.