-
Notifications
You must be signed in to change notification settings - Fork 453
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
keypoints annotation in BlenderProc #134
Comments
Hey @soans1994, until now we do not support keypoint annotations at all. So you would need to implement this feature from scratch. Let me know if you need any further guidance. |
@cornerfarmer Thank you for your reply. Is it easy to create the script similar to CocoAnnotaionsWriter for keypoints? I will try to generate the script. Please let me know if you build this and add a simple example. |
Writing the keypoints to a coco annotations file should not be that hard, as in the end its just a json file. |
Can you please update an example to save keypoints location from 3d model. I have used the annotating tool in blender to put the points on the edge of a simple cube. How can i convert these to 2d location and export to a text file. |
Hey @soans1994 here is a simple module that projects all annotation points to 2D and writes them to a npy file: import bpy
import bpy_extras
import os
from src.main.Module import Module
import numpy as np
from src.utility.Utility import Utility
class AnnotationWriter(Module):
def __init__(self, config):
Module.__init__(self, config)
def run(self):
width, height = bpy.context.scene.render.resolution_x, bpy.context.scene.render.resolution_y
for frame_id in range(bpy.context.scene.frame_start, bpy.context.scene.frame_end):
bpy.context.scene.frame_set(frame_id)
annotatons = []
for pencil in bpy.data.grease_pencils.values():
for layer in pencil.layers.values():
for frame in layer.frames.values():
for stroke in frame.strokes.values():
for point in stroke.points.values():
point2d_blender = bpy_extras.object_utils.world_to_camera_view(bpy.context.scene, bpy.context.scene.camera, point.co)
annotatons.append([point2d_blender[0] * width, (1 - point2d_blender[1]) * height])
np.save(os.path.join(self._determine_output_dir(), "annotations_" + ("%04d" % frame_id) + ".npy"), np.array(annotatons))
Utility.register_output(self._determine_output_dir(), "annotations_", "annotations", ".npy", "1.0.0") Let me know if this solves your problem. |
@cornerfarmer |
Hey @soans1994 the annotation writer was properly executed in your example, however it writes it output to the temporary directory per default and as you do not use the HDF5 Writer it is not written automatically to the output directory.
The module I wrote should output annotations as well as grease pencil objects. They are basically the same thing, only that grease pencil objects are actual objects in the scene graph. I personally would not use the annotations or grease pencil objects for specifying keypoints, as they are more built for adding notes to 3d models and not for precisely setting 3d points. Alternatively you could for example add empty objects in blender and then use their locations as keypoints. Or you can also iterate over the vertices of an object an use their locations as keypoints: for vert in bpy.context.scene.objects["Cube"].data.vertices:
point2d_blender = bpy_extras.object_utils.world_to_camera_view(bpy.context.scene, bpy.context.scene.camera, vert.co)
annotatons.append([point2d_blender[0] * width, (1 - point2d_blender[1]) * height])
|
Thank you very much, now i can save the keypoints into numpy format from the 3d model. I will try to combine this function with the COCO writer module to get json format. |
Glad that it works 👍 |
Hey, @cornerfarmer,
|
Hey, on which BlenderProc version are you? There is no class Best, |
I'm on the master branch, |
Hey @luigifaticoso, since when I posted the code, the way to register a new output moved into the Utility class. Utility.register_output(self._determine_output_dir(), "annotations_", "annotations", ".npy", "1.0.0") The utility class also needs to be imported via from src.utility.Utility import Utility Let me know if that solves the issue |
@cornerfarmer If so, could you also update the example above? :) |
@cornerfarmer yes it did, thank you very much! |
27 minutes from problem to fix, not bad ;) |
Hey @cornerfarmer @themasterlink , |
Hello Authors,
Thank you for your project. Is there any example to save pose, keypoints annotation in COCO format or any other formats along with the bounding box information.
The text was updated successfully, but these errors were encountered: