Skip to content

The shadows of the vehicle and around objects maybe rendered incorrectly in the image that captured by a camera sensor with beamNG.tech v0.34.2.0 and beamngpy 1.31 #295

Open
@dli2016

Description

@dli2016

Hi, I meet an issue, i.e., the object shadow is not rendered correctly, when I collect images through attaching a camera senor on the "hopper" vehicle in the "johnson_valley" scenario (BeamNG v0.34.2 and beamngpy 1.31).

The settings for the camera sensor are as follows (the time of day is 9:00 am):

 # Create beamng
 my_bng = BeamNGpy(self.host, self.port, home=self.home, user=self.user)
 my_bng.open(launch=True)

 # Create ego car
 ego_id = 'offroadveh'
 ego_model = 'hopper'
 ego_part_config = 'vehicles/hopper/offroad.pc'
 ego_license = 'offroad-01'
 my_ego = Vehicle(ego_id, model=ego_model, license=ego_license,
                  part_config=ego_part_config)

 # Set scenario
 scenario_level = 'johnson_valley'
 scenario_name = 'jv_offroad_v0'
 scenario = Scenario(scenario_level, scenario_name)

 # Add vehicle to the scenario
 ego_init_quat= angle_to_quat((0, 0, 180))
 spwan_pt = (-1079.603, -794.779, 116.169)
 scenario.add_vehicle(my_ego, pos=spawn_pt, rot_quat=ego_init_quat)

 # Generate
 scenario.make(my_bng)
 my_bng.settings.set_deterministic(50)
 my_bng.scenario.load(scenario)
 my_bng.scenario.start()

 # Attach camera sensor
 cam_front_pos = (0, -1.5, 1.1)
 cam_front_dir = (0, -1, -0.4)
 cam_front_res = (1024, 544)
 cam_front_fov = 60
 cam_front_nfp = (0.05, 500)
 self.camera_front = Camera(name='cam_front', bng=my_bng, vehicle=my_ego,
                            pos=cam_front_pos, dir=cam_front_dir,
                            resolution=cam_front_res, field_of_view_y=cam_front_fov,
                            near_far_planes=cam_front_nfp, is_render_depth=False, 
                            is_render_annotations=True, is_streaming=True,
                            is_using_shared_memory=True)

And, I get the RGB data like following:

img_w = 1024
img_h = 544
cam_front_data = self.camera_front.stream_raw()['colour']
cam_front_data_dec = convert_to_image(cam_front_data, img_w, img_h)

in which,

def convert_to_image(raw_data, w, h):
    if raw_data is None or len(raw_data) == 0:
        return None
    ## data = raw_data if isinstance(raw_data, bytes) else raw_data.encode()
    data = raw_data.encode() if isinstance(raw_data, str) else raw_data
    # Re-shape the array, based on the number of channels present in the data.
    decoded = np.frombuffer(data, dtype=np.uint8)
    decoded = decoded.reshape(h, w, 4)
    # Convert to image format.
    b = Image.fromarray(decoded)
    return b

Finally, I save the image as follows:
img.convert('RGB').save(save_fpath)

However, the shadow in the saved image is not as expected.
Image shown in Beamng window:

Image

Result got by Beamng0.34.2:

Image

Result got in Beamng0.33.3:

Image

I didn't meet the issue with beamng 0.33.3 (as shown in above images).
Could you please help us check if our codes are incorrect, thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions