Пример #1
0
 def renderImages(self, files, type):
     renderCount = 0
     renderTotal = 0
     # Want the files to be in the dump for animations, static otherwise
     for fileName in files:
         if fileName[-(len(dirs.sceneExt)):] == dirs.sceneExt:
             renderTotal += 1
     startTime = time.time()
     for fileName in files:
             if(fileName[-(len(dirs.sceneExt)):] == dirs.sceneExt):
                 sceneName = fileName[:-4]
                 callArray = ["povray",
                              dirs.path + dirs.settings,
                              "./" + dirs.sceneDirectory + typeSwitcher(type) + fileName,
                              "+O" + dirs.path + dirs.imageDirectory + typeSwitcher(type) + dirs.dump + sceneName
                              ] + (self.callArrayOptions)
                 returncode = call(callArray, stdout=open(os.devnull, "w"),  stderr=STDOUT)
                 if returncode != 0 and verboseRender:
                     print("Fatal Error during rendering: " + str(returncode)
                          ," On scene with name: " + sceneName)
                     break
                 else:
                     renderCount += 1
                     if(renderCount % math.ceil(math.sqrt(renderTotal)) == 0
                            or renderCount == renderTotal or renderCount == 1):
                         print("Rendered " + str(renderCount) + "/" + str(renderTotal))
             #endif
     #EndFor
     print("Rendering time: {0} seconds".format(str(time.time() - startTime)))
Пример #2
0
 def renderImages(self, files, type):
     renderCount = 0
     renderTotal = 0
     # Want the files to be in the dump for animations, static otherwise
     for fileName in files:
         if fileName[-(len(dirs.sceneExt)):] == dirs.sceneExt:
             renderTotal += 1
     startTime = time.time()
     for fileName in files:
         if (fileName[-(len(dirs.sceneExt)):] == dirs.sceneExt):
             sceneName = fileName[:-4]
             callArray = [
                 "povray", dirs.path + dirs.settings,
                 "./" + dirs.sceneDirectory + typeSwitcher(type) + fileName,
                 "+O" + dirs.path + dirs.imageDirectory +
                 typeSwitcher(type) + dirs.dump + sceneName
             ] + (self.callArrayOptions)
             returncode = call(callArray,
                               stdout=open(os.devnull, "w"),
                               stderr=STDOUT)
             if returncode != 0 and verboseRender:
                 print("Fatal Error during rendering: " + str(returncode),
                       " On scene with name: " + sceneName)
                 break
             else:
                 renderCount += 1
                 if (renderCount % math.ceil(math.sqrt(renderTotal)) == 0
                         or renderCount == renderTotal or renderCount == 1):
                     print("Rendered " + str(renderCount) + "/" +
                           str(renderTotal))
         #endif
     #EndFor
     print("Rendering time: {0} seconds".format(str(time.time() -
                                                    startTime)))
Пример #3
0
def allImagesToGreyScale(type):
    files = os.listdir(dirs.path + dirs.imageDirectory + typeSwitcher(type))
    for file in files:
        if file[-4:] == dirs.imageExt:
            fileImageToGreyScale(file, type)
    print("COMPLETED: Converted all " + typeSwitcher(type)[:-1] +
          " images to greyscale.")
Пример #4
0
 def renderByName(self, name, type):
     files = os.listdir(dirs.path + dirs.sceneDirectory + typeSwitcher(type))
     desiredFiles = []
     for file in files:
         if name in file:
             desiredFiles.append(file)
     self.renderImages(desiredFiles, type)
Пример #5
0
def sceneFromObjCreator(sceneName, objC, dict, type, index_name, class_value=0):
    with open("./" + dirs.sceneDirectory + typeSwitcher(type) + sceneName + dirs.sceneExt, "w") as out:
        #Save the data
        pickleToIndex(dict, type, index_name)
        # Save the data to a text file as well
        writeToIndex(sceneName, index_name, class_value)
        #What actually creates the scene file
        out.write(objC.scene)
Пример #6
0
 def renderByName(self, name, type):
     files = os.listdir(dirs.path + dirs.sceneDirectory +
                        typeSwitcher(type))
     desiredFiles = []
     for file in files:
         if name in file:
             desiredFiles.append(file)
     self.renderImages(desiredFiles, type)
Пример #7
0
 def appendImages(self, name, type="PTRAIN"):
     path = dirs.imageDirectory + typeSwitcher(type)
     # Only appends files with name as prefix
     files, fileNames = getDesiredFiles("./" + path + dirs.dump, name)
     print("Num files appended: {}".format(len(files)))
     # Put the concatenated images into the anim directory
     commandArray = ["convert", "+append", path + animSwitcher(self.animType) + name + dirs.imageExt]
     commandArray[1:1] = files
     returnCode = call(commandArray)
     if returnCode != 0:
         print("Fatal error during image concatenation!")
Пример #8
0
def unPickleIndex(type, index_name):
    with open(dirs.path + dirs.indices + typeSwitcher(type) + index_name + dirs.index_ext, "rb") as file:
        file.seek(0)
        lst = []
        while 1:
            try:
                lst.append(pickle.load(file))
            except EOFError:
                break
        #st.append(pickle.load(file))
        return lst
Пример #9
0
def unPickleIndex(type, index_name):
    with open(
            dirs.path + dirs.indices + typeSwitcher(type) + index_name +
            dirs.index_ext, "rb") as file:
        file.seek(0)
        lst = []
        while 1:
            try:
                lst.append(pickle.load(file))
            except EOFError:
                break
        #st.append(pickle.load(file))
        return lst
Пример #10
0
 def appendImages(self, name, type="PTRAIN"):
     path = dirs.imageDirectory + typeSwitcher(type)
     # Only appends files with name as prefix
     files, fileNames = getDesiredFiles("./" + path + dirs.dump, name)
     print("Num files appended: {}".format(len(files)))
     # Put the concatenated images into the anim directory
     commandArray = [
         "convert", "+append",
         path + animSwitcher(self.animType) + name + dirs.imageExt
     ]
     commandArray[1:1] = files
     returnCode = call(commandArray)
     if returnCode != 0:
         print("Fatal error during image concatenation!")
Пример #11
0
def sceneFromObjCreator(sceneName,
                        objC,
                        dict,
                        type,
                        index_name,
                        class_value=0):
    with open(
            "./" + dirs.sceneDirectory + typeSwitcher(type) + sceneName +
            dirs.sceneExt, "w") as out:
        #Save the data
        pickleToIndex(dict, type, index_name)
        # Save the data to a text file as well
        writeToIndex(sceneName, index_name, class_value)
        #What actually creates the scene file
        out.write(objC.scene)
Пример #12
0
 def get_dataset(self, type="", name="", file_limit=None):
     print("Loading image files...")
     if file_limit == None:
         file_limit = sys.maxsize
     desired_files, names = getDesiredFiles(dirs.path + dirs.imageDirectory + typeSwitcher(type) + animSwitcher(self.anim_type), name)
     if(len(names) == 0):
         print("Could not find any files with type {}, anim_type {}, name {}".format(type,self.anim_type,name))
     # Limit the number of classes and images to the filelimit
     file_list, name_list = desired_files[:file_limit], names[:file_limit]
     image_array = []
     class_array = []
     for path_file, image_name in zip(file_list, name_list):
         image_array.append(readImage(path_file))
         class_array.append(self.getClass(image_name, type, name))
     print("COMPLETED: Loading image files")
     return image_array, class_array
Пример #13
0
 def get_dataset(self, type="", name="", file_limit=None):
     print("Loading image files...")
     if file_limit == None:
         file_limit = sys.maxsize
     desired_files, names = getDesiredFiles(
         dirs.path + dirs.imageDirectory + typeSwitcher(type) +
         animSwitcher(self.anim_type), name)
     if (len(names) == 0):
         print(
             "Could not find any files with type {}, anim_type {}, name {}".
             format(type, self.anim_type, name))
     # Limit the number of classes and images to the filelimit
     file_list, name_list = desired_files[:file_limit], names[:file_limit]
     image_array = []
     class_array = []
     for path_file, image_name in zip(file_list, name_list):
         image_array.append(readImage(path_file))
         class_array.append(self.getClass(image_name, type, name))
     print("COMPLETED: Loading image files")
     return image_array, class_array
Пример #14
0
 def CARAS():
     type = "PTRAIN"
     if(typeSwitcher(type) == ""):
         print("ERROR: Invalid type: {}".format(type))
         sys.exit(0)
     frames = 20
     numAnims = 1000
     # Use this to vary the name of the images we want to create
     index_name = "CaffeImage"
     sc.clearPickleIndex(type, index_name)
     sc.clearIndex(index_name)
     for i in range(numAnims):
         #need a delimiter to separate scene# from frame#
         delim = "D"
         name = index_name + str(i) + delim
         #bugfix
         sc.secondAnimation(name, type, index_name)
         # sc.createBasicAnimation(name, 0)
         renderer = r.Renderer(frames=None)
         renderer.renderByName(name, type)
         renderer.appendImages(name, type)
     print("Completed Anim rendering")
Пример #15
0
def allImagesToGreyScale(type):
    files = os.listdir(dirs.path + dirs.imageDirectory + typeSwitcher(type))
    for file in files:
        if file[-4:] == dirs.imageExt:
            fileImageToGreyScale(file, type)
    print("COMPLETED: Converted all " + typeSwitcher(type)[:-1] + " images to greyscale.")
Пример #16
0
def fileImageToGreyScale(filename, type):
    imURI = dirs.path + dirs.imageDirectory + typeSwitcher(type) + filename
    image = ndimage.imread(imURI, flatten=True)
    misc.imsave(imURI, image)
Пример #17
0
def fileImageToGreyScale(filename, type):
    imURI = dirs.path + dirs.imageDirectory + typeSwitcher(type) + filename
    image = ndimage.imread(imURI, flatten=True)
    misc.imsave(imURI, image)
Пример #18
0
 def renderAll(self, type):
     files = os.listdir(dirs.path + dirs.sceneDirectory +
                        typeSwitcher(type))
     self.renderImages(files, type)
Пример #19
0
 def renderAll(self, type):
     files = os.listdir(dirs.path + dirs.sceneDirectory + typeSwitcher(type))
     self.renderImages(files, type)
Пример #20
0
def pickleToIndex(dict, type, index_name):
    with open(dirs.path + dirs.indices + typeSwitcher(type) + index_name +
              dirs.index_ext,
              mode="a+b") as out:
        pickle.dump(dict, out)
Пример #21
0
def deleteAllImages(type):
    os.remove(dirs.path + dirs.imageDirectory + typeSwitcher(type))
Пример #22
0
def pickleToIndex(dict, type, index_name):
    with open(dirs.path + dirs.indices + typeSwitcher(type) + index_name + dirs.index_ext, mode="a+b") as out:
        pickle.dump(dict, out)
Пример #23
0
def clearPickleIndex(type, index_name):
    open(
        dirs.path + dirs.indices + typeSwitcher(type) + index_name +
        dirs.index_ext, "w").close()
    print("Cleared {} Index".format(
        typeSwitcher(type) + index_name + dirs.index_ext))
Пример #24
0
def clearPickleIndex(type, index_name):
    open(dirs.path + dirs.indices + typeSwitcher(type) + index_name + dirs.index_ext, "w").close()
    print("Cleared {} Index".format(typeSwitcher(type) + index_name + dirs.index_ext))
Пример #25
0
def deleteAllScenes(type):
    os.remove(dirs.path + dirs.sceneDirectory + typeSwitcher(type))