def createFeatureFileGrayScaleSequences(imageSize, imageDirectory, featuresDirectory, featuresName, log):

        directory = imageDirectory        
        
        classesPath = os.listdir(directory)                
        featuresSetGray =  []        
        classNumber = 0
        for classs in classesPath:   
            sequences = os.listdir(directory+"/"+classs)
            for s in sequences:
                files = os.listdir(directory+os.sep+classs+os.sep+s+os.sep)      
                for image in files:                    
                 if (not "txt" in image and not "db" in image):                    
                    log.printMessage(("Reading:", directory+os.sep+classs+os.sep+s+os.sep+image))
                    img = cv2.imread(directory+os.sep+classs+os.sep+s+os.sep+image)
                    featuresGray = grayImage(img,imageSize,False,"")

                    featuresGray = whiten(featuresGray) 
                    featuresGray = resize(featuresGray,imageSize) 

                                                                                                                                                        
                    
                    newFeatures = [] 
                    newFeatures.append(int(classNumber)) 
                    
                    for x in featuresGray:
                       for y in x:
                            newFeatures.append(y)                                
                    
                    featuresSetGray.append(newFeatures)                
                
            classNumber = classNumber+1                             
        DataUtil.writeSingleFile(featuresSetGray,featuresDirectory+os.sep+featuresName, False) 
def createFeatureFile(imageSize, imageDirectory, featuresDirectory, featuresName, log, inputType):

        print "Input type:", inputType, "-", DataUtil.INPUT_TYPE["Sequence"]
        
        if inputType == DataUtil.INPUT_TYPE["3D"] or inputType == DataUtil.INPUT_TYPE["Sequence"]:
            createFeatureFileGrayScaleSequences(imageSize, imageDirectory,featuresDirectory, featuresName,log)
        else:    
            directory = imageDirectory        
            
            classesPath = os.listdir(directory)                
            featuresSetGray =  []        
            classNumber = 0
            for classs in classesPath:        
                    files = os.listdir(directory+os.sep+classs+os.sep)                      
                    for image in files:                    
                     if ( not "db" in image and not ".directory" in image):                
                        log.printMessage(("Reading:", directory+os.sep+classs+os.sep+image))
                        img =  Image.open(directory+os.sep+classs+os.sep+image)
                        img = numpy.array(img)   
                        if len(img.shape) == 3:
                            b,g,r = cv2.split(img)
                            img = cv2.merge([r,g,b])
                        
                        
                        #cv2.imwrite("/informatik2/wtm/home/barros/demo_ws/src/dialog/scripts/networkPosture/test/test1.jpg",img)
                        if not inputType ==  DataUtil.INPUT_TYPE["Color"]:
                            img = grayImage(img,imageSize,False,"")
                            
                        img = whiten(img) 
                        #cv2.imwrite("/informatik2/wtm/home/barros/demo_ws/src/dialog/scripts/networkPosture/test/test2.jpg",img)
                        img = resize(img,imageSize)
                        #cv2.imwrite("/informatik2/wtm/home/barros/demo_ws/src/dialog/scripts/networkPosture/test/test3.jpg",img)
                        
                        newFeatures = [] 
                        newFeatures.append(int(classNumber)) 
                        
                        for x in img:
                           for y in x:
                               if inputType ==  DataUtil.INPUT_TYPE["Color"]:
                                   colors = []
                                   for c in y:
                                       colors.append(c)
                                   newFeatures.append(colors)  
                               else:
                                    newFeatures.append(y)                                
                        
                        featuresSetGray.append(newFeatures)                
                    
                    classNumber = classNumber+1          
                    
            #print "Total features:", len(featuresSetGray)
            DataUtil.writeSingleFile(featuresSetGray,featuresDirectory+os.sep+featuresName, inputType ==  DataUtil.INPUT_TYPE["Color"])
def createFeatureFile(imageSize, imageDirectory, featuresDirectory, featuresName, log, inputType):

        if inputType == DataUtil.INPUT_TYPE["3D"]:
            createFeatureFileGrayScaleSequences(imageSize, imageDirectory,featuresDirectory, featuresName,log)
        else:    
            directory = imageDirectory        
            
            classesPath = os.listdir(directory)                
            featuresSetGray =  []        
            classNumber = 0
            for classs in classesPath:        
                    files = os.listdir(directory+os.sep+classs+os.sep)                      
                    for image in files:                    
                     if (not "db" in image and not ".directory" in image):                
                        log.printMessage(("Reading:", directory+os.sep+classs+os.sep+image))
                        img =  Image.open(directory+os.sep+classs+os.sep+image)
                        img = numpy.array(img)                        
                        
                        if not inputType ==  DataUtil.INPUT_TYPE["Color"]:
                            img = grayImage(img,imageSize,False,"")
                            
                        img = whiten(img) 
                        img = resize(img,imageSize)
                        newFeatures = [] 
                        newFeatures.append(int(classNumber)) 
                        
                        for x in img:
                           for y in x:
                               if inputType ==  DataUtil.INPUT_TYPE["Color"]:
                                   colors = []
                                   for c in y:
                                       colors.append(c)
                                   newFeatures.append(colors)  
                               else:
                                    newFeatures.append(y)                                
                        
                        featuresSetGray.append(newFeatures)                
                    
                    classNumber = classNumber+1          
                    
            print "Total features:", len(featuresSetGray)
            DataUtil.writeSingleFile(featuresSetGray,featuresDirectory+os.sep+featuresName, inputType ==  DataUtil.INPUT_TYPE["Color"])