Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Image Converter within Carla Client #18

Open
onebitme opened this issue Dec 21, 2020 · 0 comments
Open

Using Image Converter within Carla Client #18

onebitme opened this issue Dec 21, 2020 · 0 comments

Comments

@onebitme
Copy link

I've used some portion of your code.
In Client what I did to save the camera images:

        cam_bp = world.get_blueprint_library().find('sensor.camera.rgb')
        cam_bp.set_attribute("image_size_x",str(800))
        cam_bp.set_attribute("image_size_y",str(600))
        cam_bp.set_attribute("fov",str(105))
        cam_location = carla.Location(2,0,1)
        cam_rotation = carla.Rotation(0,90,0)
        cam_transform = carla.Transform(cam_location,cam_rotation)
        ego_cam = world.spawn_actor(cam_bp,cam_transform,attach_to=ego_vehicle, attachment_type=carla.AttachmentType.Rigid)
        def to_bgra_array(image):
            """Convert a CARLA raw image to a BGRA numpy array."""
            array = np.frombuffer(image.raw_data, dtype=np.dtype("uint8"))
            array = np.reshape(array, (image.height, image.width, 4))
            return array

        def to_rgb_array(image):
            """Convert a CARLA raw image to a RGB numpy array."""
            array = to_bgra_array(image)
            # Convert BGRA to RGB.
            array = array[:, :, :3]
            array = array[:, :, ::-1]
            return array

        def image_callback(image):
            print("Image is coming")
            image_no = image.frame
            image_rgb = to_bgra_array(image)
            path = '~/output/' + str(image_no)
            cv2.imwrite(path +'.jpg', image_rgb)

        ego_cam.listen(lambda image: image_callback(image))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant