Beispiel #1
0
    def visualizeResults(self, points, normals, seeds, seeds_normals, scores, Y_real, num_of_points):
        num_of_samples = points.__len__()
        # Unscale the predictions:
        scores_unscaled = getUnscaledArray(scaled_points=scores, 
                                           mins=np.asarray(self.mins), 
                                           maxs=np.asarray(self.maxs),
                                           high=1.0,
                                           low=0.0)
        #new_shape = (num_of_samples, v.NUM_OF_POINTS, 2)
        #scores_unscaled = np.reshape(scores_unscaled, new_shape)
        Y_real_unscaled = getUnscaledArray(scaled_points=Y_real, 
                                    mins=np.asarray(self.mins), 
                                    maxs=np.asarray(self.maxs),
                                    high=1.0,
                                    low=0.0)
        #Y_real_unscaled = np.reshape(Y_real_unscaled, new_shape)



        for it in range(num_of_samples):
            score = scores_unscaled[it]
            score_real = Y_real_unscaled[it]
            
            sample_points = points[it]            
            sample_normals = normals[it]
            seed_point = seeds[it]
            seed_normal = seeds_normals[it]
            sample_points = [p + seed_point for p in sample_points]
            sample = fromNumpyArray(sample_points, sample_normals)
            rsv_predicted = rsv(sample)
            q = rsv_predicted.computeRadialPoint_i(seed_point, seed_normal, delta=score[0]) 
            r_prima = rsv_predicted.computeRadialVectorPrima_i(seed_normal, l=score[1]) 

            rsv_real = rsv(sample)
            q_real = rsv_real.computeRadialPoint_i(seed_point, seed_normal, delta=score_real[0]) 
            r_prima_real = rsv_real.computeRadialVectorPrima_i(seed_normal, l=score_real[1]) 

            vis = visualizer()
            vis.addPointcloud(sample)    
            vis.addSphere(center = seed_point, color=[0,0,0])
            vis.addSphere(center = q, color=[0,1,0])
            vis.addSphere(center = q_real, color=[0,0,1])
            vis.addLine(q, q_real)
            vis.addLine(seed_point, q_real, color=[1,0,0])
            vis.show()

            vis = visualizer()
            vis.addPointcloud(sample)
            vis.addSphere(center = seed_point, color=[0,0,0])
            vis.addSphere(center = q, color=[0,0,0])
            vis.addSphere(center = q + r_prima, color=[0,1,0])
            vis.addSphere(center = q + r_prima_real, color=[0,0,1])
            vis.addLine(q, q + r_prima_real)
            vis.addLine(q, q + r_prima)
            vis.addLine(seed_point, q, color=[1,0,0])
            vis.show()
Beispiel #2
0
def graph(amr_table, output_path, curt=False):
    import visualizer

    graph_path = output_path + 'graphs/'
    try: os.mkdir(graph_path)
    except OSError: pass

    for docid in sorted(amr_table):
        for senid in sorted(amr_table[docid]):
            sen = amr_table[docid][senid]
            if curt:
                visualizer.visualizer_curt(sen, graph_path)
            else:
                visualizer.visualizer(sen, graph_path)
Beispiel #3
0
def graph(amr_table, output_path, curt=False):
    import visualizer

    graph_path = output_path + 'graphs/'
    try: os.mkdir(graph_path)
    except OSError: pass

    for docid in sorted(amr_table):
        for senid in sorted(amr_table[docid]):
            sen = amr_table[docid][senid]
            if curt:
                visualizer.visualizer_curt(sen, graph_path)
            else:
                visualizer.visualizer(sen, graph_path)
Beispiel #4
0
 def visualizeRadialVector_withFrame(self, q, r_prima, R, num_of_samples):
     # Initialize visualizer
     vis = visualizer()
     vis.addPointcloud(cloud=self.cloud, color=CLOUD_COLOR)
     vis.addSphere(self.c, CENTER_COLOR, CENTER_RADIUS)
     # Randomly select a subsample of points
     indices = range(self.num_of_points)
     for index in np.random.choice(indices, num_of_samples):
         # Sphere to visualize the reference point
         vis.addSphere(self.points[index], P_PRIMA_COLOR, P_PRIMA_RADIUS)
         # Sphere to visualize the radial point
         vis.addSphere(q[index], RADIAL_POINT_COLOR, RADIAL_POINT_RADIUS)
         # Sphere to visualize the vote generated by r_prima
         vote = q[index] + r_prima[index]
         vis.addSphere(vote, VOTE_COLOR, VOTE_RADIUS)
         # Line from the vote to the radial point
         vis.addLine(vote, q[index])
         # Line from the p_prima to the radial point
         vis.addLine(self.points[index], q[index])
         # Add reference frame
         vis.addFrame(center=self.points[index],
                      size=FRAME_SIZE,
                      R=R[index])
     # Show results
     vis.show()
Beispiel #5
0
 def generate(self):
     '''
     main function that generate the report and call the
     functions of the report sections
     '''
     self.doc.packages.append(
         Package('geometry', options=['tmargin=1cm', 'lmargin=0.5cm']))
     # cover page #
     self.doc.preamble.append(Command(
         'title',
         'Experiemts Report',
     ))
     self.doc.preamble.append(Command('author', 'ATOM'))
     self.doc.append(NoEscape(r'\maketitle'))
     self.doc.append(NoEscape(r'\pagebreak'))
     # summary #
     self.gen_summary(self.experiments.iloc[0][1])
     self.doc.append(NoEscape(r'\pagebreak'))  #start new page
     # Top N Models #
     self.draw_top_models(4)
     self.doc.append(NoEscape(r'\pagebreak'))  #start new page
     # Graphs #
     visu = visualizer(save_dir=self.path)
     self.gen_graphs(visu)
     # generate pdf file #
     self.doc.generate_pdf('example')
     print 'Finished Report Generation'
Beispiel #6
0
    def visualizePrediction(self, points, scores):
        """
        Visualization for the segments classified as object.
                
        Parameters
        ----------            
        points: N x num_of_points x num_of_dimensions array
            Point data for the set.
        scores: N x NUM_OF_CATEGORIES array
            Scores for the set.    
        """
        # Create visualizer object.
        vis = visualizer()
        # Loop through all the samples in order to assign the correct color
        # depending on their score
        num_of_samples = points.__len__()

        for i in range(num_of_samples):
            # Get the predicted class for the segment
            predicted_class = self.getPredictedClass(scores[i])
            # Get the segment as a point cloud
            segment = fromNumpyArray(points[i])
            if predicted_class == "object":
                vis.addPointcloud(segment, color=CANDIDATE_COLOR)

        vis.show()
Beispiel #7
0
 def visualizeVote(self, votes, R, q, num_of_votes: int):
     # Initialize visualizer
     vis = visualizer()
     vis.addPointcloud(self.cloud, CLOUD_COLOR)
     vis.addSphere(self.c, CENTER_COLOR, CENTER_RADIUS)
     vis.addFrame(self.c, FRAME_SIZE * 2)
     vis.addFrame([0.0, 0.0, 0.0], FRAME_SIZE * 2)
     # Add visualization aid to as many votes as requested
     for i in range(num_of_votes):
         # Select a random vote
         index = random.randint(0, self.num_of_points)
         # Sphere to visualize p_prima
         vis.addSphere(self.points[index], P_PRIMA_COLOR, P_PRIMA_RADIUS)
         # Line from p_prima to the radial point
         vis.addLine(self.points[index], q[index])
         # Sphere to visualize the radial point
         vis.addSphere(q[index], RADIAL_POINT_COLOR, RADIAL_POINT_RADIUS)
         # Get the vote data
         t_i = votes[index]
         R_i = R[index]
         # Get the tesallation_level
         [_, tesallation_level, _] = votes.shape
         # Loop through all the votes generated for the reference point
         # p_prima
         for j in range(tesallation_level):
             # Sphere to visualize the vote
             vis.addSphere(t_i[j], VOTE_COLOR, VOTE_RADIUS)
             # Reference frame for the vote
             vis.addFrame(t_i[j], FRAME_SIZE, t=None, R=R_i[j])
             # Line from the vote to the radial point
             vis.addLine(t_i[j], q[index])
     # Show results
     vis.show()
Beispiel #8
0
def html(amr_table, filename, output_path):
    output = open(output_path + '%s.html' % filename, 'w')
    import visualizer

    graph_path = output_path + 'graphs/'
    try: os.mkdir(graph_path)
    except OSError: pass

    # head = '<meta charset=\'utf-8\'>\n'
    head = os.path.dirname(os.path.abspath(__file__)) + '/html_head'
    output.write(open(head, 'r').read())

    for docid in sorted(amr_table):
        for senid in sorted(amr_table[docid]):
            sen = amr_table[docid][senid]
            visualizer.visualizer(sen, graph_path)
            get_sentence(sen, output)
Beispiel #9
0
 def visualizeSegment(self, visualize, seed_points, s_neighboring_idx,
                      index):
     vis = visualizer()
     # Color the point cloud and the subset
     self.scene.paint_uniform_color([0, 1, 0])
     vis.addSphere(center=seed_points[index], color=[1, 0, 0], radius=3)
     np.asarray(self.scene.colors)[s_neighboring_idx[index], :] = [0, 0, 1]
     vis.addPointcloud(self.scene)
     vis.show()
Beispiel #10
0
    def evaluateOneSample(self, sample, scene_file_path, object, method='ADD', diagonal=0.0, visualize=False):
        # Load the corresponding scene pointcloud
        scene = o3d.io.read_point_cloud(scene_file_path)    
        # Load the sample transformations
        T_gt = self.getData(sample, 'T_ground_truth')
        T = self.getData(sample, 'T')
        T_icp_ptpoint = self.getData(sample, 'T_icp_ptpoint')
        T_icp_ptplane = self.getData(sample, 'T_icp_ptplane')

        if T_gt is None or T_icp_ptpoint is None or T_icp_ptplane is None or T is None:
            return 'None'
    
        T_gt = np.asarray(T_gt)
        T = np.asarray(T)
        T_icp_ptplane = np.asarray(T_icp_ptplane)
        T_icp_ptpoint = np.asarray(T_icp_ptpoint)

        # Apply transformations to the object
        object_gt = applyGroundTruthPoseToObject(object, T_gt)
        object_T = applyPoseToObject(object, T)
        object_icp_ptplane = applyPoseToObject(object, T_icp_ptplane)
        object_icp_ptpoint = applyPoseToObject(object, T_icp_ptpoint)

        # Compute evaluation metric
        if method == 'ADD':
            m_value_T, m_valid_T = self.computeADD(object_gt, object_T, diagonal)
            m_value_icp_ptplane, m_valid_icp_ptplane = self.computeADD(object_gt, object_icp_ptplane, diagonal)
            m_value_icp_ptpoint, m_valid_icp_ptpoint = self.computeADD(object_gt, object_icp_ptpoint, diagonal)

        elif method == 'CD':
            m_value_T, m_valid_T = self.computeCD(object_gt, object_T)
            m_value_icp_ptplane, m_valid_icp_ptplane = self.computeCD(object_gt, object_icp_ptplane)
            m_value_icp_ptpoint, m_valid_icp_ptpoint = self.computeCD(object_gt, object_icp_ptpoint)

        elif method == 'RD':
            max_angle = 5
            m_value_T, m_valid_T = self.computeRadialDistance(T_gt, T, 'z', Threshold=max_angle)
            m_value_icp_ptplane, m_valid_icp_ptplane = self.computeRadialDistance(T_gt, T_icp_ptplane, 'z', Threshold=max_angle)
            m_value_icp_ptpoint, m_valid_icp_ptpoint = self.computeRadialDistance(T_gt, T_icp_ptpoint, 'z', Threshold=max_angle)
    

        msg = 'Sample data: ' + sample + ' Result: | ' + str(m_valid_T) + ' , ' + str(m_valid_icp_ptplane) + ' , ' + str(m_valid_icp_ptpoint) + '  | '
        print(msg)

        if visualize is True:  
            vis = visualizer()

            #vis.addPointcloud(object_T, color=[1, 0.706, 0])
            vis.addPointcloud(object_icp_ptplane, color=[0, 1, 0])
            #vis.addPointcloud(object_icp_ptpoint, color=[0, 0.706, 0])
            
            scene = cropScene(object_gt, scene, radius = 200)
            vis.addPointcloud(scene)
            vis.show()

        return [m_valid_T, m_valid_icp_ptplane, m_valid_icp_ptpoint]
Beispiel #11
0
 def choose_model(self, tag):
     self.model = self.store.recognize(tag)
     if not (self.model is None):
         self.visual = visualizer(self.model, (self.leng, self.leng),
                                  self.samples.rang(), self.samples.rang())
         self.tab_parent.tab(1, state="normal")
         self.tab_parent.tab(2, state="disabled")
         self.tab_parent.tab(3, state="disabled")
         self.tab_parent.select(1)
         self.stop_process()
Beispiel #12
0
 def visualizeCloudCenter(self):
     """
     Visualize the input point cloud with its center
     """
     # Initialize visualizer
     vis = visualizer()
     vis.addPointcloud(self.cloud, CLOUD_COLOR)
     vis.addSphere(self.c, CENTER_COLOR, CENTER_RADIUS)
     # Show results
     vis.show()
Beispiel #13
0
def html(amr_table, filename, output_path, curt=False):
    output = open(output_path + '%s.html' % filename, 'w')
    import visualizer

    graph_path = output_path + 'graphs/'
    try: os.mkdir(graph_path)
    except OSError: pass

    # head = '<meta charset=\'utf-8\'>\n'
    head = os.path.dirname(os.path.abspath(__file__)) + '/html_head'
    output.write(open(head, 'r').read())

    for docid in sorted(amr_table):
        for senid in sorted(amr_table[docid]):
            sen = amr_table[docid][senid]
            if curt:
                visualizer.visualizer_curt(sen, graph_path)
            else:
                visualizer.visualizer(sen, graph_path)
            get_sentence(sen, output)
def visualizeSeedsRotationFrames(object, seeds, R_seeds):
    vis = visualizer()
    vis.addPointcloud(seeds)
    vis.addFrame(center=[0, 0, 0], size=10)
    vis.addSphere(center=object.get_center(), radius=2)
    seed_points = np.asarray(seeds.points)

    for i in range(len(R_seeds)):
        vis.addFrame(center=seed_points[i], size=9, R=R_seeds[i])

    vis.show()
Beispiel #15
0
    def visualizePrediction(self,
                            seeds,
                            scene,
                            scene_indices,
                            predicted_categories,
                            num_of_segments=10):
        """
        Visualize the predicted categories for different points. 
                
        Parameters
        ----------
        seeds: 
        
        scene:

        scene_indices: 
            Indices of the points from the original scene point cloud which 
            were used to generate each segment when splitting the scene.

        predicted_categories:
        
        num_of_segments:

        """
        # Visualize the predicted results
        vis = visualizer()
        for s in np.asarray(seeds.points):
            vis.addSphere(s, color=[0, 0, 0], radius=2)
        # Add point clouds to the visualization
        vis.addPointcloud(cloud=seeds)
        vis.addPointcloud(cloud=scene)
        # Get the points of both point clouds as numpy array
        seeds_points = np.asarray(seeds.points)
        scene_points = np.asarray(scene.points)
        # Add lines to visualize the correspondences
        for i in np.random.uniform(low=0,
                                   high=(len(scene_indices) - 1),
                                   size=num_of_segments):
            p1 = scene_points[scene_indices[int(i)]]
            c = predicted_categories[int(i)]
            p2 = seeds_points[c]
            if c is not -1:
                color = [0, 0, 1]
            else:
                color = [1, 0, 0]
            vis.addSphere(center=p1, color=color, radius=2)
            vis.addSphere(center=p2, color=color, radius=2)
            vis.addLine(p1, p2, color=color)
        vis.show()
    def __init__(self, logger=None):
        super().__init__()
        if conf()['compile_pyx_on_startup']:
            os.system("python setup.py build_ext --inplace")

        self.frame = 0
        self.logger = logger

        # Initialize all needed modules
        shapedetector()
        shapetracker()
        touchedshapetracker()
        handdetector()
        handtracker()
        visualizer()
        ui()
        shapepicker()
        shaperegionpicker()

        # Put the wires together
        handtracker().subscribe('hand_exit', shapetracker().clear_lost_shapes)
        handtracker().subscribe('finger_up',
                                touchedshapetracker().on_finger_up)
        handtracker().subscribe('finger_pressing', ui().on_finger_pressing)
        handtracker().subscribe('finger_up', ui().on_finger_up)
        handtracker().subscribe('finger_down', ui().on_finger_down)
        handtracker().subscribe('finger_pressing',
                                shapepicker().on_finger_pressing)
        handtracker().subscribe('finger_up', shapepicker().on_finger_up)
        handtracker().subscribe('hand_exit', handdetector().on_hand_exit)
        handtracker().subscribe('finger_pressing',
                                shaperegionpicker().on_finger_pressing)
        handtracker().subscribe('finger_up', shaperegionpicker().on_finger_up)
        handtracker().subscribe('hand_exit', shaperegionpicker().on_hand_exit)
        handtracker().subscribe('hand_exit',
                                shapepositionpicker().on_hand_exit)
    def next_frame(self):
        self.frame += 1
        self.publish('frame_begins', {'frame': self.frame})

        if not realsensecam().acquire_frames():
            return None

        handdetector().determine_hand_cnt()
        if handtracker().update() and not ui().menu_active:
            detected_shapes = shapedetector().detect_shapes()
            shapetracker().process_detected_shapes(detected_shapes)
            touchedshapetracker().update()
        if self.logger is not None:
            self.logger.logAll()
        return visualizer().visualize()
Beispiel #18
0
    def visualizeSceneAndSeeds(self, seeds):
        """
        Visualize the scene pointcloud with the generated seeds.

        Parameters
        ----------
        seeds: o3d.geometry.PointCloud
            Pointcloud containing the seeds.
        """
        vis = visualizer()
        vis.addPointcloud(self.scene)
        # Add a sphere in order to visualize each seed
        for s in np.asarray(seeds.points):
            vis.addSphere(center=s, color=SEED_COLOR, radius=SEED_RADIUS)
        vis.show()
Beispiel #19
0
    def visualizeMatches(self, seeds, scene, segments_categories,
                         scene_indices, num_of_points):
        vis = visualizer()
        vis.addPointcloud(scene)
        for p in np.asarray(seeds.points):
            vis.addSphere(center=p, color=[0, 0, 0], radius=2)

        idx = np.random.uniform(low=0,
                                high=(len(scene_indices) - 1),
                                size=num_of_points)
        for i in idx:
            s = np.asarray(scene.points)[scene_indices[int(i)]]
            o = np.asarray(seeds.points)[segments_categories[int(i)]]
            vis.addSphere(center=s, color=[0, 0, 1], radius=2)
            vis.addSphere(center=o, color=[0, 1, 0], radius=3)
            vis.addLine(o, s)
        vis.show()
Beispiel #20
0
 def visualizeVotes(self, votes):
     """
     Visualize the input point cloud with the generated votes
     """
     # Initialize visualizer
     vis = visualizer()
     vis.addPointcloud(self.cloud, color=CLOUD_COLOR)
     # Get the number of votes
     [_, tesallation_level, _] = votes.shape
     number_of_votes = tesallation_level * self.num_of_points
     # Reshape the votes container
     votes_r = np.reshape(votes, (number_of_votes, 3))
     # Convert the votes into a point cloud
     votes_cloud = fromNumpyArray(votes_r)
     vis.addPointcloud(votes_cloud, color=VOTE_COLOR)
     # Show results
     vis.show()
Beispiel #21
0
    def computeDiagonal(self, object, vis=False):
        points = np.asarray(object.points)

        c = (object.get_center())
        p1 = getFurthestPoint(object, c)  
        p2 = getFurthestPoint(object, p1) 
        
        diagonal = getEuclidianDistance(p1, p2)

        if vis is True:
            vis = visualizer()
            vis.addPointcloud(object)
            vis.addSphere(center=p1, color=[0,1,0], radius=2)
            vis.addSphere(center=p2, color=[0,0,1], radius=2)
            vis.addLine(p1,p2)
            vis.show()

        return diagonal
Beispiel #22
0
    def visualizeDensity(self, votes_r, density, t_candidates, R_candidates,
                         model):
        """
        Visualize the vote density 

        Parameters
        ----------
        votes 

        R

        density

        model:o3d.geometry.PointCloud

        num_of_candidates: int
            Number of candidates to be shown.
        """
        # Initialize visualizer
        vis = visualizer()
        vis.addPointcloud(self.cloud, CLOUD_COLOR)
        # Convert the votes into a point cloud
        votes_cloud = fromNumpyArray(votes_r)
        # Scale the density values to be within [0,1]
        color_code, _, _ = getScaledArray(density, high=1, low=0)
        # Color Coding the votes: First, Paint the cloud uniformly in order for
        # the points to have a color attribute
        votes_cloud.paint_uniform_color([1, 1, 1])
        # Color Coding the votes: Second, Assign a color to each point
        # depending on its density value
        votes_color_coded = np.array([[c, 0, 0] for c in color_code])
        votes_cloud.colors = o3d.utility.Vector3dVector(votes_color_coded)
        vis.addPointcloud(votes_cloud)
        # Run until the number of candidates is satisfied
        for i in range(len(t_candidates)):
            t_c = t_candidates[i]
            R_c = R_candidates[i]
            # Sphere to visualize the candidate
            vis.addSphere(t_c, CANDIDATE_COLOR, CANDIDATE_RADIUS)
            vis.addFrame(t_c, FRAME_SIZE, R=R_c)
            # Candidate object point cloud
            vis.addPointcloud(copy.deepcopy(model), t=t_c, R=R_c)
        # Show results
        vis.show()
Beispiel #23
0
 def visualizeSegments(self, seeds, segments, seeds_indices):
     # Generate a color code in order to have a different color for each
     # seed
     seeds = np.asarray(seeds.points)
     [num_of_seeds, _] = seeds.shape
     np.random.seed(10)
     color_code = np.random.rand(num_of_seeds, 3)
     # Initialize visualizer
     vis = visualizer()
     # Add a sphere in order to visualize each seed
     for s in seeds:
         vis.addSphere(center=s, color=SEED_COLOR, radius=SEED_RADIUS)
     # Loop through all the segments, add a point cloud for each one and
     # color it depending on the category.
     [num_of_segments, _, _] = segments.shape
     for i in range(1):  #range(num_of_segments):
         segment_color = color_code[int(seeds_indices[i]), :]
         vis.addPointcloud(fromNumpyArray(segments[i]), color=segment_color)
     vis.show()
Beispiel #24
0
 def visualizeBestCandidates(self, points):
     """
     Visualization for the selected candidates.
             
     Parameters
     ----------            
     points: N x num_of_points x num_of_dimensions array
         Point data for the candidates.
     """
     # Create visualizer object.
     vis = visualizer()
     # Loop through all the candidates
     for c in points:
         # Add cloud with the candidate points
         candidate = fromNumpyArray(c)
         vis.addPointcloud(candidate, color=CANDIDATE_COLOR)
         # Add sphere to visualize the cloud center
         vis.addSphere(candidate.get_center(), CENTER_COLOR, CENTER_RADIUS)
     vis.show()
Beispiel #25
0
  def __init__(self,  num_class = 14, limit = None):
    self.num_class = num_class
    self.iteration = 0

    # data
    self.data = loadData.loadData(limit = limit).getDataArray()
    print "number of training data:", len(self.data)

    # model parameters
    # for each pixel in each class, there are: 
      # 1. pi representing probability of the class
      # 2. alpha representing probability of being foreground
      # 3. mu and sigma representing gaussian of observation vs fg/bg data
    self.param_pi = np.array([1.0/self.num_class] * self.num_class)
    self.param_alpha = np.zeros((self.num_class, len(self.data[0]))) + 0.5
    self.param_mu = np.random.random((self.num_class, len(self.data[0]))) 
    self.param_sigma = np.ones((self.num_class, len(self.data[0]))) * 10

    # visualizer
    self.visualizer = visualizer.visualizer()
Beispiel #26
0
 def visualizeData(self, data_points, num_of_samples: int):
     """
     Visualization for the PointNet data.
         Visualize an specified number of samples.
             
     Parameters
     ----------            
     data_points: N x num_of_points x num_of_dimensions array
         Point data for the set.
     num_of_samples: int
         Number of samples to be visualized.    
     """
     # Create visualizer object.
     vis = visualizer()
     for d in range(num_of_samples):
         offset = d * 2
         sample = data_points[d, :, 0:num_of_dimensions] / 100
         sample[:, 0] = sample[:, 0] + offset
         vis.addPointcloud(fromNumpyArray(sample))
     vis.show()
Beispiel #27
0
 def visualizeBestCandidates(self, scene, object, t_candidates, R_candidates):
     vis = visualizer()
     vis.addPointcloud(scene)
     for i in range(len(t_candidates)):
         vis.addPointcloud(copy.deepcopy(object), t=t_candidates[i], R=R_candidates[i])
     vis.show()
Beispiel #28
0
 def __init__(self, game):
     self.vision = vision()
     self.visualizer = visualizer()
     self.current_tile = (0, 0)
     self.game = game
Beispiel #29
0
    def getMatches(self, object:o3d.geometry.PointCloud, 
                         scene:o3d.geometry.PointCloud, 
                         distance_threshold:float, 
                         radial_vector_length, 
                         scalar_projection):
        visualize = False
        # Container to save the sample data
        sample_data  = np.array([])
        # Construct kd-tree in order to search through the object points
        object_tree = o3d.geometry.KDTreeFlann(object)
        # Compute normals of the scene point cloud 
        scene = computeNormals(cloud=scene, orient_normals=True)
        scene_points = np.asarray(scene.points)
        scene_normals = np.asarray(scene.normals)
        [number_of_points_scene,_]=scene_points.shape     
  
        scene_points_indices = np.array([], dtype=int)
        # Loop through all the points in the scene point cloud
        for i in range(number_of_points_scene): 
            # Find the closest point of the object to the scene point
            [k, idx, _] = object_tree.search_knn_vector_3d(scene_points[i], 1)
            object_point = np.asarray(object.points)[idx] 
            # Compute the euclidian distance between the object and scene point
            dist = getEuclidianDistance(scene_points[i],object_point)
            # If the points are close enough, save the data
            if dist < distance_threshold: 
                scene_points_indices = np.append(scene_points_indices, i)
                # Storing the sample data:
                # [scene_point(x,y,z),
                # radial_vector_length,
                # scalar_projection,
                # normal]    
                point_data = np.hstack([scene_points[i], 
                                        radial_vector_length[idx], 
                                        scalar_projection[idx], 
                                        scene_normals[i]])   
                if sample_data.size == 0:
                    sample_data = point_data
                else:
                    sample_data = np.row_stack([sample_data, point_data])

        if visualize is True:
            vis = visualizer()
            scene.paint_uniform_color([0,1,0])
            np.asarray(scene.colors)[scene_points_indices[1:], :] = [0,0,1]
            vis.addPointcloud(scene)
            vis.show()

        scene_tree = o3d.geometry.KDTreeFlann(scene)
        indices = np.random.uniform(low=0, high=(sample_data.__len__()-1), size=50)
        for it in indices:
            it = int(it)
            seed = sample_data[it, 0:3]
            [k, idx, _] = scene_tree.search_radius_vector_3d(seed, v.SEGMENT_RADIUS)
            
            if visualize is True:
                vis = visualizer()
                scene.paint_uniform_color([0,1,0])
                np.asarray(scene.colors)[idx[1:], :] = [0,0,1]
                vis.addPointcloud(scene)
                vis.addSphere(center=seed, color=[1,0,0], radius=2)
                vis.show()

            idx = np.asarray(idx)
            np.random.shuffle(idx)
            idx = idx[0:v.NUM_OF_POINTS]
            points = copy.deepcopy(np.asarray(scene.points)[idx])
            points = np.asarray([[p - seed for p in points]])
            normals = [copy.deepcopy(np.asarray(scene.normals)[idx])]

            if visualize is True:
                vis = visualizer()
                scene.paint_uniform_color([0,1,0])
                np.asarray(scene.colors)[idx[1:], :] = [0,0,1]
                vis.addPointcloud(scene)
                vis.addSphere(center=seed, color=[1,0,0], radius=2)
                vis.show()
            
            [_, m, _] = points.shape
            if m == v.NUM_OF_POINTS:
                gf_vector = self.getGlobalFeatureVectors([points])
            else:
                return None
        
            if self.dataset.size == 0:
                self.dataset = np.asarray([sample_data[it, :]])
                self.dataset_out = np.asarray(gf_vector)
                self.dataset_cloud = np.asarray(points)
                self.dataset_normals = np.asarray(normals)
            else:
                self.dataset = np.row_stack([self.dataset, [sample_data[it, :]]])
                self.dataset_out = np.row_stack([self.dataset_out, gf_vector])
                self.dataset_cloud = np.row_stack([self.dataset_cloud, points])
                self.dataset_normals = np.row_stack([self.dataset_normals, normals])
                
        return sample_data       
Beispiel #30
0
from config import gen_args
from data import KnittedVestDataset

from utils import to_np, set_seed, get_lr
from models import CNNCali

args = gen_args()
print(args)

use_gpu = torch.cuda.is_available()
set_seed(42)
'''
visualizer
'''
if args.knit_name in ['kuka_calibration']:
    vis_glove = visualizer('glove', 'right')
    vis_kuka = visualizer('kuka')
'''
model
'''
model_glove = CNNCali(args,
                      vis_glove.mask,
                      scale_factor=1.0,
                      position_bias=True)
model_kuka = CNNCali(args, vis_kuka.mask)

# load pretrained glove network
model_name = 'net_glove_pretrained.pth'
model_path = os.path.join(args.ckp_path, model_name)
print("Loading pretrained glove network from %s" % model_path)
model_glove.load_state_dict(torch.load(model_path))
Beispiel #31
0
from utils import to_np, set_seed, get_lr
from models import CNNCali


args = gen_args()
print(args)

use_gpu = torch.cuda.is_available()
set_seed(42)


'''
visualizer
'''
side = 'left'
vis = visualizer('sock', side)



'''
model
'''
model = CNNCali(args, vis.mask)

if args.eval == 0:
    if args.resume == 1:
        model_name = 'net_epoch_%d_iter_%d.pth' % (args.epoch, args.iter)
        model_path = os.path.join(args.ckp_path, model_name)
        print("Loading network from %s" % model_path)
        model.load_state_dict(torch.load(model_path))
    else:
Beispiel #32
0
from utils import to_np, set_seed, get_lr
from models import CNNCali


args = gen_args()
print(args)

use_gpu = torch.cuda.is_available()
set_seed(42)


'''
visualizer
'''
if args.knit_name in ['glove_calibration']:
    vis = visualizer(sensor_type='glove', side='right')


'''
model
'''
model = CNNCali(args, vis.mask)

if args.eval == 0:
    if args.resume == 1:
        model_name = 'net_epoch_%d_iter_%d.pth' % (args.epoch, args.iter)
        model_path = os.path.join(args.ckp_path, model_name)
        print("Loading network from %s" % model_path)
        model.load_state_dict(torch.load(model_path))
    else:
        print("Randomly initialize the network")
Beispiel #33
0
# -*- coding: utf-8 -*-
"""
Visualisazion of the shot prediction
"""
############################ VISUALISATION OF PREDICTION #####################
from visualizer import visualizer

video = 'test_data/final.mp4'
csv = 'test_data/final.csv'
"""
Instructions:
    k: stop or resume panel video
    n: next frame 
    q: quit video 
"""
#compare prediction from the Conv3D model and cineast
comp = visualizer(10, video, csv)
comp.compare_prediction('test_data/predict.csv', 'test_data/cineast.csv')

#prediction from model
# conv = visualizer(10,video, 'test_data/predict.csv')
# conv.eval_csv()

# #prediction from cineast
# cin = visualizer(10,video, 'test_data/cineast.csv')
# cin.eval_csv()

# #true cuts as reference
# ref = visualizer(10,video, csv)
# ref.eval_csv()
Beispiel #34
0
# Center the cloud in the origin
scene = downsample(scene, leaf_size)
scene.translate([100, 100, 100])
scene.paint_uniform_color([0, 1, 0])
o3d.visualization.draw_geometries([scene])
# Split the scene cloud in segments with the correct size for the pointnet
# module. We use all the scene points as seed since we want a segment per point
cs = cloud_splitter(scene, oc.INPUT_SHAPE)
segments_data = cs.getSegments(scene, oc.SEGMENT_RADIUS)
# If  no segments are found, stopt the execution of the script.
if segments_data is None:
    sys.exit()
# Unpack the segments data
[X_test, X_test_u, X_normals, X_indices, _] = segments_data
# Visualize the segments
vis = visualizer()
num_of_segments = 3
for i in np.random.uniform(low=0,
                           high=(len(X_test_u) - 1),
                           size=num_of_segments):
    c = np.random.uniform(low=0, high=1, size=(3, ))
    vis.addPointcloud(cloud=fromNumpyArray(X_test_u[int(i)]), color=c)
vis.show()
# Declare the PointNet model
object_class = object_classifier(oc.INPUT_SHAPE, oc.NUM_OF_CATEGORIES)
# Load the pretrained model
object_class.loadModel(f.OBJ_CLASS_POINTNET_LOAD)
# Run the pointnet in order to classify the segments into the different parts
# of the object
scores = object_class.predict(X_test)
predicted_categories = object_class.getPredictedCategory(scores,