Ejemplo n.º 1
0
 def data(self, downsample = 1):
     if self._type == "image":
         Image = misc.imread(self._path)[:, :, 0:3]
         if downsample != 1: Image = tb.downsampleImage(Image, downsample)
         return Image[..., np.r_[2, 1, 0]].transpose((2, 0, 1))
     elif self._type == "flow":
         flow = tb.readFlow(self._path)
         flow = flow[:, :, 0:2]
         if downsample != 1: flow = OpticalFlow.downsampleMedian(flow, downsample)
         flow = flow.transpose((2, 0, 1))
         nanMask = np.isnan(flow)
         data = (flow * 32.0).astype(np.int16)
         data[nanMask] = np.iinfo(np.int16).max
         return data
     elif self._type == "leftdisparity":
         disparity = tb.readDisparity(self._path)
         nanMask = np.isnan(disparity)
         disparity *= -1
         if downsample != 1: raise Exception("no downsampling implemented for disparity")
         data = (disparity * 32.0).astype(np.int16)
         data[nanMask] = np.iinfo(np.int16).max
         return data
     elif self._type == "rightdisparity":
         disparity = tb.readDisparity(self._path)
         nanMask = np.isnan(disparity)
         if downsample != 1: raise Exception("no downsampling implemented for disparity")
         data = (disparity * 32.0).astype(np.int16)
         data[nanMask] = np.iinfo(np.int16).max
         return data
     elif self._type == "leftdisparitychange":
         disparityChange = tb.readDisparity(self._path)
         nanMask = np.isnan(disparityChange)
         disparityChange *= -1
         if downsample != 1: raise Exception("no downsampling implemented for disparity")
         data = (disparityChange * 32.0).astype(np.int16)
         data[nanMask] = np.iinfo(np.int16).max
         return data
     elif self._type == "rightdisparitychange":
         disparityChange = tb.readDisparity(self._path)
         nanMask = np.isnan(disparityChange)
         if downsample != 1: raise Exception("no downsampling implemented for disparity")
         data = (disparityChange * 32.0).astype(np.int16)
         data[nanMask] = np.iinfo(np.int16).max
         return data
     else:
         raise Exception('unhandled data type')
Ejemplo n.º 2
0
def computeHistograms(resolution, subpath, collectionName, clips, skipIfExists=False, overwrite=True, numBins=5000, maxValue=1000):
    dataPath = '/misc/lmbraid17/sceneflownet/common/data/4_bin-db'
    savePath = '%s/hists/%s/%s' % (dataPath, resolution, subpath)
    saveFile = '%s/%s.npz' % (savePath, collectionName)

    completePath = os.path.dirname(saveFile)
    os.system('mkdir -p %s' % completePath)

    print 'savePath', savePath
    print 'completePath', completePath
    print 'saveFile', saveFile

    histFlow = np.zeros(numBins)
    histDisp = np.zeros(numBins)
    histDispChange = np.zeros(numBins)
    for clip in clips:
        print 'processing', clip
        for i in range(clip.startFrame(), clip.endFrame()+1):
            frame = clip.frame(i)

            if i%10 == 1:
              print '%d/%d' % (i - clip.startFrame() + 1, clip.endFrame() - clip.startFrame() + 1)

            # flow histogram
            if frame.hasForwardFlowL():
                values = tb.readFlow(frame.forwardFlowL())
                mag = np.power(np.sum(np.power(values, 2), axis=2), 0.5)
                curr_hist, _ = np.histogram(mag, bins=numBins, range=(0,maxValue))
                histFlow += curr_hist

            # disparity histogram
            if frame.hasDispL():
                values = tb.readDisparity(frame.dispL())
                mag = np.abs(values)
                curr_hist, _  = np.histogram(mag, bins=numBins, range=(0,maxValue))
                histDisp += curr_hist

            # disparity change histogram
            if frame.hasBackwardDispChangeL():
                values  = tb.readDisparity(frame.forwardDispChangeL())
                mag = np.abs(values)
                curr_hist, _  = np.histogram(mag, bins=numBins, range=(0,maxValue))
                histDispChange += curr_hist

    np.savez(saveFile, histFlow=histFlow, histDisp=histDisp, histDispChange=histDispChange)