def writeFeatures(self):
        img = pp.readInImg(
            os.path.join(self.dataDir, "sub01/EP02_01f/reg_img46.jpg"))

        ## For each subject
        for sub in os.listdir(self.dataDir):
            ## For each video
            for vid in os.listdir(os.path.join(self.dataDir, sub)):
                print vid
                if vid.endswith("avi"):  #skip avis
                    break
                ## Process each frame
                for frame in os.listdir(os.path.join(self.dataDir, sub, vid)):
                    img = pp.readInImg(
                        os.path.join(self.dataDir, sub, vid, frame))
                    kernels = self.gabor.generateGaborKernels()

                    newFeatures = np.ravel(
                        self.gabor.processGaborRaw(img, kernels))
                    featStr = map(lambda x: '%.15f' % x, newFeatures)
                    featOut = str.join(',', featStr)
                    f = open(
                        os.path.join(
                            self.featureOut, "Gabors-S%d-O%d.csv" %
                            (self.nScales, self.nOrient)), "a")

                    f.write("%s\n" % featOut)
                    f.close()
    def run( self ):
        ## Read in excel file to data frame
        excelFile = os.path.join( self.mainDir, self.excelFile )
        table = pd.ExcelFile( excelFile )
        t = table.parse( )


        ## Init parsed data containers
        labelInfo  = {}
        frameInfo = {}

        #Probe sample image for dims
        img = pp.readInImg( os.path.join( self.dataDir, "sub01/EP02_01f/reg_img46.jpg" )    )
        self.nh, self.nw = pp.imgRes( img, self.imgRes )
        dims = self.nScales * self.nOrient * self.nh * self.nw
        featureInfo = np.array([ ] ).reshape( 0, dims )


        tf = 0
        s = 0
        
        ## Iterate through files and generate labels and features
        complete = True
        ## For each subject
        for sub in os.listdir( self.dataDir ): 
            v = 0
            
            ## For each video 
            for vid in os.listdir( os.path.join( self.dataDir, sub ) ):
                if vid.endswith( "avi" ):   #skip avis
                    break
               
                ## Each line in main excel file proports to one video, get that info here
                intLabelInfo, labelParams = CASMELabels.getLabelInfo( sub, vid, t, [s, v] )
                f = 0
                
                ## Process each frame
                for frame in os.listdir( os.path.join( self.dataDir, sub, vid ) ):

                    frameInfo = CASMELabels.getFrameParams( intLabelInfo, labelParams, f, frame )
                    frameInfo.update( intLabelInfo )
                    labelInfo.update( { tf :  frameInfo } )
                    img =  pp.readInImg( os.path.join( self.dataDir, sub, vid, frame ) )
                    img = pp.downsample( img, self.nh, self.nw ) 
                    

                    kernels = self.gabor.generateGaborKernels( ) 
                    try:
                        featureInfo = np.vstack( [ featureInfo, gab.processGabor( img, kernels ) ])
                    except MemoryError:
                        #print "S%d   O%d    H%d    W%d.csv" % (self.nScales, self.nOrient, self.nh, self.nw )
                        complete = False
                        break
                    f += 1
                    tf += 1
                v += 1
            s += 1

        return featureInfo, labelInfo, complete
    def writeFeatures( self ):
        img = pp.readInImg( os.path.join( self.dataDir, "sub01/EP02_01f/reg_img46.jpg" )    )

       ## For each subject
        for sub in os.listdir( self.dataDir ): 
            ## For each video 
            for vid in os.listdir( os.path.join( self.dataDir, sub ) ):
                print vid
                if vid.endswith( "avi" ):   #skip avis
                    break
                ## Process each frame
                for frame in os.listdir( os.path.join( self.dataDir, sub, vid ) ):
                    img =  pp.readInImg( os.path.join( self.dataDir, sub, vid, frame ) )
                    kernels = self.gabor.generateGaborKernels( )

                    newFeatures = np.ravel(self.gabor.processGaborRaw( img, kernels )  )
                    featStr = map( lambda x : '%.15f' % x, newFeatures )
                    featOut = str.join( ',' , featStr )
                    f = open( os.path.join( self.featureOut, "Gabors-S%d-O%d.csv" % (self.nScales, self.nOrient)), "a" )
                    
                    f.write( "%s\n" % featOut )
                    f.close()
import os
from image_processing.PreProcessing import PreProcessing as pp
from feature_extraction.GaborWindowExtractor import GaborWindowExtractor as w
data = "C:\Users\Valerie\Desktop\MicroExpress\CASME2\Cropped\Cropped"
sub = "sub01"
ep = "EP02_01f"
img = "reg_img46.jpg"
I = pp.readInImg( os.path.join( data, sub, ep, img) )

gw = w( 5, 8, 15, 8 )
gw.process( I ) 
Exemple #5
0
import os
from image_processing.PreProcessing import PreProcessing as pp
from feature_extraction.GaborWindowExtractor import GaborWindowExtractor as w
data = "C:\Users\Valerie\Desktop\MicroExpress\CASME2\Cropped\Cropped"
sub = "sub01"
ep = "EP02_01f"
img = "reg_img46.jpg"
I = pp.readInImg(os.path.join(data, sub, ep, img))

gw = w(5, 8, 15, 8)
gw.process(I)