コード例 #1
0
ファイル: MaskReader.py プロジェクト: personalrobotics/moped
    def filter(self, pts2D):
        """ Filter image points based on loaded mask. 
        
        Usage: Mask = BaseMask('mask.png')
               FilteredPts = Mask.filter(pts)
        
        Input:
            pts - 2-by-N numpy array of 2D points

        Output:
            FilteredPts - 2-by-N numpy array of 2D points. Those that agree 
            with the mask (i.e., those points [x, y] s.t. mask[x,y] = True)
            remain the same, while invalid points are zeroed.
        """
        
        # Find points that are not zero in image space
        idxPts = utils.find( np.logical_and(pts2D[0, :] > 0, pts2D[1,:] > 0) )

        # Get rounded and flattened (1D) pixel indexes for our 2D points
        idxPtsFlat = utils.ravel_index(pts2D[::-1, idxPts].astype(int), \
                                       self.data.shape)

        # Find invalid 2D points by comparing them to the mask
        idxInvalidPts = utils.find( self.data.flat[idxPtsFlat] == 0 )

        # Set invalid points to zero
        pts2D[:, idxPts[idxInvalidPts]] = 0

        return pts2D
コード例 #2
0
ファイル: camera_3d_calib.py プロジェクト: DavidB-CMU/moped
    def getClicks3D(self):
        """ Display depth image and get click positions.
        
        Usage: pts3D = getClicks3D()

        Input:
            -NONE-
        Output:
            pts3D - 3-by-N array of 3d points in 3d map corresponding to clicks
        """
        
        # Get just the depth values
        depth = self.cloud[2,:]
        depth = depth.reshape(self.img.shape)
        
        temp_ = tempfile.NamedTemporaryFile(suffix='.png', delete = False)

        Image.fromarray( (depth*500).astype(np.uint8) ).save(temp_.name)

        clicker = ck.Clicker()
        clicker.clicker(temp_.name)
        self.pcd_clicks = np.array(clicker.coords)
        
        idx = utils.ravel_index(self.pcd_clicks[:, ::-1], self.img.shape)
        
        # Find points that have actual depth and not nans
        pts = list()
        for i, val in enumerate(idx):
            count_x = 0
            count_y = 0
            counter = 0
            while any(np.isnan(self.cloud[:,val+count_x + \
                                          count_y*self.img.shape[1]])):
                counter += 1
                if counter % 2:
                    count_x += 1
                else:
                    count_y += 1
            idx[i] = val + count_x + count_y * self.img.shape[1]

        pts3D = np.zeros((3, idx.size))
        for i in range(3):
            pts3D[i,:] = self.cloud[i, idx]

        return pts3D
コード例 #3
0
 def getn(self, idx):
     """
         Given an index return a single number n representing the corresponding index on the flattened grid
     """
     from utils import ravel_index
     return ravel_index(idx, self.shape)