コード例 #1
0
ファイル: tubeList.py プロジェクト: caomw/apt
    def read(self, path):
        """
        Read tubes from path; 
        A tube is a tupel of 4 numbers (xmin, ymin, xmax, ymax).
        """
        
        if not os.path.exists(path):    
            raise Exception('Path does not exist: %s' % (path) )
            
        pp = os.path.join(path, '*.txt')
        #print pp
        files = glob.glob( pp )
        nrFiles = len(files) # nr Frames
        print '\treading tubes:', path, '; Number of tubes read:', nrFiles
        
        if nrFiles == 0:
            raise Exception('No files found in: %s' % (pp) )
        files.sort()
        #files.reverse()

        for i in xrange(nrFiles):

            f = files[i]
            tube = SingleTube()
            tube.read(f)
            self._tubes.append( tube )
コード例 #2
0
ファイル: tubeList.py プロジェクト: yanxia-fxpal/apt
    def read(self, path):
        """
        Read tubes from path; 
        A tube is a tupel of 4 numbers (xmin, ymin, xmax, ymax).
        """

        if not os.path.exists(path):
            raise Exception('Path does not exist: %s' % (path))

        pp = os.path.join(path, '*.txt')
        #print pp
        files = glob.glob(pp)
        nrFiles = len(files)  # nr Frames
        print '\treading tubes:', path, '; Number of tubes read:', nrFiles

        if nrFiles == 0:
            raise Exception('No files found in: %s' % (pp))
        files.sort()
        #files.reverse()

        for i in xrange(nrFiles):

            f = files[i]
            tube = SingleTube()
            tube.read(f)
            self._tubes.append(tube)
コード例 #3
0
def traj2tube(frameNumEnd, tubeFeatSpat, xmax=np.inf, ymax=np.inf, regionSize=15, framesPerTrack=15):
    """convert a trajectory to a SingleTube proposal"""
    frameNumStart = int(frameNumEnd - framesPerTrack)

    # make a tube as a tupel of 4 numbers (xmin, ymin, xmax, ymax).
    tube = np.zeros( (framesPerTrack, 4), dtype='float32' )
    
    # a trajectory has x,y in the center, with a size of 2*regionSize
    i = np.arange(framesPerTrack)
    tube[i,0] = np.maximum(0,tubeFeatSpat[i*2] - regionSize) # xmin
    tube[i,1] = np.maximum(0,tubeFeatSpat[i*2+1] - regionSize) # ymin
    tube[i,2] = np.minimum(xmax,tubeFeatSpat[i*2] + regionSize) # xmax
    tube[i,3] = np.minimum(ymax,tubeFeatSpat[i*2+1] + regionSize) # ymax    
    
    return SingleTube(frameNumStart,tube)
コード例 #4
0
ファイル: tubeList.py プロジェクト: caomw/apt
    def readHDF5(self, inHDF5fileName):
        """
        Read tubes from hdf5 fileName; 
        A tube is a tupel of 4 numbers (xmin, ymin, xmax, ymax).
        """
        
        if not os.path.exists(inHDF5fileName):    
            print 'Path does not exist: %s' % (inHDF5fileName) 
            raise Exception('Path does not exist: %s' % (inHDF5fileName) )
            
        inHDF5file = h5py.File(inHDF5fileName, 'r')    
        nrTubes = len(inHDF5file) 
        print '\treading tubes:', inHDF5fileName, '; Number of tubes to read:', nrTubes
        
        if nrTubes == 0:
            raise Exception('No tubes found in: %s' % (pp) )

        for i in xrange(nrTubes):

            tube = SingleTube()
            tube.readHDF5(inHDF5file, str(i) )
            self._tubes.append( tube )

        inHDF5file.close()
コード例 #5
0
ファイル: tubeList.py プロジェクト: yanxia-fxpal/apt
    def readHDF5(self, inHDF5fileName):
        """
        Read tubes from hdf5 fileName; 
        A tube is a tupel of 4 numbers (xmin, ymin, xmax, ymax).
        """

        if not os.path.exists(inHDF5fileName):
            print 'Path does not exist: %s' % (inHDF5fileName)
            raise Exception('Path does not exist: %s' % (inHDF5fileName))

        inHDF5file = h5py.File(inHDF5fileName, 'r')
        nrTubes = len(inHDF5file)
        print '\treading tubes:', inHDF5fileName, '; Number of tubes to read:', nrTubes

        if nrTubes == 0:
            raise Exception('No tubes found in: %s' % (pp))

        for i in xrange(nrTubes):

            tube = SingleTube()
            tube.readHDF5(inHDF5file, str(i))
            self._tubes.append(tube)

        inHDF5file.close()
コード例 #6
0
ファイル: tubeList.py プロジェクト: yanxia-fxpal/apt
    def readFrameFormat(self,
                        path,
                        readWHformat=False,
                        spatialSubSampleRate=1):
        """
        Read tubes from path; dense format = a tube at each frame number
        A tube is a tupel of 4 numbers (xmin, ymin, xmax, ymax).
        if readWHformat == True:
            A tube is converted from (xmin, ymin, w, h) format.
        Every frame X should have a X.txt file with tubes.
        Every .txt file has a fixed nr of lines, each line is a tube; All .txt files have the same nr of tubes.
        If a tube is not visible in a frame XXX.txt, set the tube to (0,0,0,0)
        """

        if not os.path.exists(path):
            raise Exception('Path does not exist: %s' % (path))

        pp = os.path.join(path, '*.txt')
        #print pp
        files = glob.glob(pp)
        nrFiles = len(files)  # nr Frames
        print 'readFrameFormat:', path, 'nrFiles', nrFiles,

        if nrFiles == 0:
            raise Exception('No files found in: %s' % (pp))
        files.sort()
        #files.reverse()

        for i in xrange(nrFiles):

            f = files[i]
            #print f

            fileIn = open(f, 'r')
            lines = fileIn.readlines()

            nrLines = len(lines)  # nr proposals

            if i == 0:
                # if first element, reserve space
                data = np.zeros((nrFiles, nrLines, 4), dtype='float32')
                print 'nrTubes', nrLines
            else:
                # nr tubes cannot differ per file
                if nrLines != data.shape[1]:
                    raise Exception('NrLines in %s should be %d, but is %d' %
                                    (f, nrLines, data.shape[0]))

            for j in range(nrLines):
                line = lines[j]
                d = line.split(',')
                if len(d) == 1:
                    d = line.split()
                data[i, j, :] = np.array(
                    [float(s) / spatialSubSampleRate for s in d[:4]])
                if readWHformat:
                    data[i, j, 2] = data[i, j, 2] + data[i, j, 0]
                    data[i, j, 3] = data[i, j, 3] + data[i, j, 1]

            fileIn.close()

        # convert data array to SingleTube objects
        nrTubes = data.shape[1]
        for t in range(nrTubes):

            # find frames without BBs: sum the BBs, empty are <= 0
            minFrameNr = 0
            maxFrameNr = nrFiles - 1

            summedBB = np.sum(data[:, t, :], axis=1)
            emptyIdx = np.nonzero(summedBB <= 0)[0]

            # if pre-BB empty
            if summedBB[0] < 0:
                minFrameNr = min(emptyIdx)
            # if post-BB empty
            if summedBB[-1] < 0:
                maxFrameNr = max(emptyIdx)

            bbList = []
            for f in range(nrFiles):
                if f >= minFrameNr and f <= maxFrameNr:
                    bb = data[f, t, :]
                    bbList.append(bb)
            tube = SingleTube(minFrameNr, bbList)

            # add tube to list
            self._tubes.append(tube)