-
Notifications
You must be signed in to change notification settings - Fork 454
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
Saving segmentation mask to image in bop_writer #155
Comments
First, you don't need to write custom code for that, #134 is for keypoint annotations not masks. The BopWriter does not output masks because the bop_toolkit can already compute masks. Please have a look here: Alternatively, if you want to do it within BlenderProc, just add a SegMapRenderer to your config. |
@MartinSmeyer Thank you for the answer. {
"module": "renderer.SegMapRenderer",
"config": {
"map_by": ["instance", "class", "cp_bop_dataset_name"],
"default_values": {"class":0, "cp_bop_dataset_name": "None"}
}
} I am checking the bop_toolkit right now |
I agree that the documentation does not read super well in this case, but it does say
So you find the mapping in the generated hdf5 file. You can print all keys of the hdf5 file using
|
In fact, you also need the hdf5 writer for that. |
Thank you. Ok, I see it, I have never had previous experience with hdf5, didn't know how they work. Going to use that output to generate the mask image, thank you a lot. I can consider the issue closed! |
Yeah hdf5 files are useful because they can store data in a compressed way and you can access it like a dictionary. If you still want just the raw outputs and not use the hdf5 writer, you can also set the global config to |
Hi @MartinSmeyer
I can't find any information about coordinates of the mask, am I missing something? {
"module": "renderer.SegMapRenderer",
"config": {
"map_by": ["instance", "class", "cp_bop_dataset_name"],
"default_values": {"class":0, "cp_bop_dataset_name": "none"},
"output_is_temp": False,
}
}, The csv |
The csv ouput is in there under The actual masks are save under |
Thank you @MartinSmeyer
{
"module": "renderer.SegMapRenderer",
"config": {
"map_by": "class",
"output_is_temp": False,
"default_values": {"class": 0}
}
},
black_img = 255*np.ones((512, 512 , 3), dtype=np.uint8)
for i in range(len(segmap)):
for j in range(len(segmap[i])):
if(segmap[i][j]==100.0): # <- this is my "cp_category_id"
black_img[i][j] = (255,255,255)
else:
black_img[i][j] = (0,0,0) Could have been done differently and maybe simpler, but this solution works to me. I was trying to use the bop toolkit and had a problem with config and paths. May I ask you if the possibility of saving the png image of binary segmentation mask will be implemented in the future? |
There are several reasons, first if you only need grey colors, you are limited to 255 classes, which in instance setting might be limiting. We wanted to make sure that our solution scales to any problem.
This can be done a bit simpler in python: black_img = np.zeros(segmap.shape, dtype=np.uint8)
black_img[segmap == 100.0] = 255
# this last line is only needed if the output really needs to have 3 channels, matplotlib can also vis images without 3 channels
black_img = np.repeat(np.reshape(black_img, (black_img.shape[0], black_img.shape[1], 1)), 3, axis=-1) |
Hello again,
Thank you for all the previous issues, always hoping they could help someone in the same situation.
I am currently using the bop writer to save my renders.
I was trying to generate a binary image for the mask ( like in
linemod_preprocessed
dataset ), I have tried to use the Annotation writer explained in #134 using the other solution:At this point, the resulting output results in points with coordinate out of the dimension of my image (mine is 512x512 and coordinates are like 950 or 1100)
Here is an example:
these are the annotations saved in
Annotations_0000.npy
This is the Segmentation output from Hdf5:
I don't know much about the bpy module. Is it an easy task to output them as an image directly using the bopWriter or have correct coordinates to draw a mask using OpenCV?
I have also tried extracting the segmentation keypoints from the
coco_annotations.json
, but, in that form, they don't look like the coordinates I need to generate the mask imageThe text was updated successfully, but these errors were encountered: