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

How to get Mask value of an object #266

Open
hanyangyu1021 opened this issue Jan 14, 2025 · 1 comment
Open

How to get Mask value of an object #266

hanyangyu1021 opened this issue Jan 14, 2025 · 1 comment

Comments

@hanyangyu1021
Copy link

hanyangyu1021 commented Jan 14, 2025

When collecting demo, i can get the one-channel mask image. It seems like each mask value corresponding to a specific object. But how I can I find the correspondence map, like 145 corresponding to the pencil?

@hanyangyu1021 hanyangyu1021 changed the title How to get Mask value of a object How to get Mask value of an object Jan 14, 2025
@zhenglianchi
Copy link

def get_mask(sensor: VisionSensor, mask_fn):
    mask = None
    if sensor is not None:
        sensor.handle_explicitly()
        mask = mask_fn(sensor.capture_rgb())
    return mask

def rgb_handles_to_mask(rgb_coded_handles):
    # rgb_coded_handles should be (w, h, c)
    # Handle encoded as : handle = R + G * 256 + B * 256 * 256

    # If reading from a PIL image, the values will already be on the 
    # range [0, 255] and uint8. However, if rgb_coded_handles is read directly from 
    # a sensor, it will be on the range [0, 1].
    if rgb_coded_handles.dtype != np.uint8:
        rgb_coded_handles *= 255  # takes rgb range to 0 -> 255
    rgb_coded_handles.astype(int)
    return (rgb_coded_handles[:, :, 0] +
            rgb_coded_handles[:, :, 1] * 256 +
            rgb_coded_handles[:, :, 2] * 256 * 256)

查看源码你会发现mask值是通过上述代码计算,直接通过rgb像素值处理得到

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

2 participants