heremaps / pptk

The Point Processing Toolkit (pptk) is a Python package for visualizing and processing 2-d/3-d point clouds.
https://heremaps.github.io/pptk
MIT License
610 stars 112 forks source link

Non blocking annotation #17

Open lelouedec opened 5 years ago

lelouedec commented 5 years ago

It seems to be impossible to use the viewer and run an infinite loop in charge of getting selected points. I want to use pptk to annotate point clouds for segmentation, however when ever I start the viewer and try in a loop to get the selected points and adding them to an array when the number of points is greater than 0, the viewer freeze not allowing me to select anything and crashes. Any idea how to get a non blocking visualization where I can do somethings else while keeping the viewer up ? What I got until now :

import numpy as np
import pptk
import open3d

pcd    = open3d.read_point_cloud("../PointCloudCode/Data/Samples/strawberry_3d_v3/15.ply")
P      = np.asarray(pcd.points)
colors = np.asarray(pcd.colors)
v = pptk.viewer(P,colors)
v.set(point_size=0.007)
while(True):
    if(len(v.get('selected'))>0):
        print(len(v.get('selected')),"  points selected")
    v.set(point_size=0.007)
kentaroy47 commented 5 years ago

you can use ipython and run v.get('selected') periodically. I made a annotation class for handyness..

class save_annotation():
    def __init__(self, data, filename="hogehoge"):
        self.v = pptk.viewer(data)
        self.data = data
        self.filename=filename

    def check(self):
        """
        check annotation
        """
        color = []
        ann = []

        # check
        for i, points in enumerate(self.annotation):
            ann.extend(denoisedlidardata[points])
            color.extend(i*10*np.ones(len(points)))
        pptk.viewer(ann, color)

    def save(self):
        np.save(self.filename, self.annotation)

    def add(self):
        self.annotation.append(self.v.get("selected"))

annotater =  save_annotation(data)

you can add annotations by annotater.add() after selecting stuff.

you can also check and save your annotations too.