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)))
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)))
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.")
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)
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)
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!")
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
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
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!")
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)
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
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
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")
def fileImageToGreyScale(filename, type): imURI = dirs.path + dirs.imageDirectory + typeSwitcher(type) + filename image = ndimage.imread(imURI, flatten=True) misc.imsave(imURI, image)
def renderAll(self, type): files = os.listdir(dirs.path + dirs.sceneDirectory + typeSwitcher(type)) self.renderImages(files, type)
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)
def deleteAllImages(type): os.remove(dirs.path + dirs.imageDirectory + typeSwitcher(type))
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))
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))
def deleteAllScenes(type): os.remove(dirs.path + dirs.sceneDirectory + typeSwitcher(type))