def makeHandsHuman(): files = getFiles() total_file = len(files) Console.info("Image total:", total_file) num_processes = multiprocessing.cpu_count() if platform.system() == "Linux" and num_processes > 1: processes = [] lot_size = int(total_file / num_processes) for x in range(1, num_processes + 1): if x < num_processes: lot_img = files[(x - 1) * lot_size:((x - 1) * lot_size) + lot_size] else: lot_img = files[(x - 1) * lot_size:] processes.append(Process(target=mpStart, args=(lot_img, output))) if len(processes) > 0: Console.info("Get histogram of the images...") for p in processes: p.start() result = [] for x in range(num_processes): result.append(output.get(True)) for p in processes: p.join() updateProgress(1, total_file, total_file, "") else: Console.info("No podemos dividir la cargan en distintos procesadores") exit(0)
def loadDataSet(files=[]): total_file = len(files) # defined path path = os.path.join(__location__, "dataset") path_original = os.path.join(path, "original") path_hands = os.path.join(path, "hands") X_img = [] y_img = [] for i in range(total_file): img_file = files[i] # Update the progress bar progress = float(i / total_file), (i + 1) updateProgress(progress[0], progress[1], total_file, img_file) # Get image's path x_path = os.path.join(path_original, img_file) y_path = os.path.join(path_hands, img_file) x_img = cv2.imread(x_path) # Read a image y_img = cv2.imread(y_path) # Read a image for x_img, y_img in dataAugmentation(x_img, y_img): X_img.append(processeImg(x_img)) y_img.append(processeImg(y_img)) return X_img, y_img
def processeImg(files, y_lower_upper): total_file = len(files) Console.log("Process", total_file, "images") x_files = [] for i in range(total_file): min_color = int(y_lower_upper[0][i]) max_color = int(y_lower_upper[1][i]) min_color = min_color if min_color > 0 else 0 max_color = max_color if max_color < 255 else 255 x_files.append((files[i], min_color, max_color)) # Usado en caso de usar multiples core output = multiprocessing.Queue() num_processes = multiprocessing.cpu_count() if platform.system() == "Linux" and num_processes > 1: processes = [] lot_size = int(total_file / num_processes) for x in range(1, num_processes + 1): if x < num_processes: lote = x_files[(x - 1) * lot_size: ((x - 1) * lot_size) + lot_size] else: lote = x_files[(x - 1) * lot_size:] processes.append(Process(target=mpProcessImg, args=(lote, output))) if len(processes) > 0: Console.info("Fix colors of the images...") for p in processes: p.start() result = [] for x in range(num_processes): result.append(output.get(True)) for p in processes: p.join() X_values = [] for x in result: X_values = X_values + x updateProgress(1, total_file, total_file, "") Console.log("Image processed:", len(X_values)) else: Console.info("We can not divide the load into different processors") # X_values = mpGetHistogramFormFiles(files) exit(0) return X_values
def progressImg(files=[]): global img_file total_file = len(files) for i in range(total_file): (img_file, lower, upper) = files[i] # Update the progress bar progress = float(i / total_file), (i + 1) updateProgress(progress[0], progress[1], total_file, img_file) # Get image's path img_path = os.path.join(train_dir, img_file) # Read a image img = cv2.imread(img_path, 0) img = histogramsLevelFix(img, lower, upper) writeImage("hands", img)
def progressFiles(path_input, files, hands_valid): path = os.path.join(__location__) for p in path_input: path = os.path.join(path, p) total_file = len(files) Console.info("Image total:", total_file) num_processes = multiprocessing.cpu_count() if platform.system() == "Linux" and num_processes > 1: processes = [] lot_size = int(total_file / num_processes) for x in range(1, num_processes + 1): if x < num_processes: lot_img = files[(x - 1) * lot_size:((x - 1) * lot_size) + lot_size] else: lot_img = files[(x - 1) * lot_size:] processes.append( Process(target=mpStart, args=(path, lot_img, hands_valid, output, x))) if len(processes) > 0: Console.info("Get histogram of the images...") for p in processes: p.start() result = [] for x in range(num_processes): result.append(output.get(True)) for p in processes: p.join() X_train = [] y_train = [] for mp_X_train, mp_y_train in result: X_train = X_train + mp_X_train y_train = y_train + mp_y_train updateProgress(1, total_file, total_file, "") return X_train, y_train else: Console.info("No podemos dividir la cargan en distintos procesadores") exit(0)
def mpProcessImg(files, output): global img_file rta = [] total_file = len(files) for i in range(total_file): (img_file, lower, upper) = files[i] # Update the progress bar progress = float(i / total_file), (i + 1) updateProgress(progress[0], progress[1], total_file, img_file) # Get image's path img_path = os.path.join(train_dir, img_file) # Read a image img = cv2.imread(img_path, 0) img = histogramsLevelFix(img, lower, upper) rta.append((img_file, img, getHistogram(img))) output.put(rta)
def mpGetHistogramFormFiles(files, output): global img_file total_file = len(files) rta = [] for i in range(total_file): img_file = files[i] # Update the progress bar progress = float(i / total_file), (i + 1) updateProgress(progress[0], progress[1], total_file, img_file) # Get image's path img_path = os.path.join(train_dir, img_file) # Read a image img = cv2.imread(img_path, 0) # Get histogram of hands rta.append((img_file, getHistogram(img))) output.put(rta)
def getHistogramFormFiles(files=[]): total_file = len(files) Console.log("Process", total_file, "images") # Usado en caso de usar multiples core output = multiprocessing.Queue() num_processes = multiprocessing.cpu_count() if platform.system() == "Linux" and num_processes > 1: processes = [] lot_size = int(total_file / num_processes) for x in range(1, num_processes + 1): if x < num_processes: lote = files[(x - 1) * lot_size: ((x - 1) * lot_size) + lot_size] else: lote = files[(x - 1) * lot_size:] processes.append(Process(target=mpGetHistogramFormFiles, args=(lote, output))) if len(processes) > 0: Console.info("Get histogram of the images...") for p in processes: p.start() result = [] for x in range(num_processes): result.append(output.get(True)) for p in processes: p.join() X_values = [] for x in result: X_values = X_values + x updateProgress(1, total_file, total_file, "") Console.log("Image processed:", len(X_values)) else: Console.info("We can not divide the load into different processors") # X_values = mpGetHistogramFormFiles(files) exit(0) return X_values
def loadDataSet(path, files=[], hands_valid=1): X_train = [] y_train = [] total_file = len(files) for i in range(total_file): img_file = files[i] # Update the progress bar progress = float(i / total_file), (i + 1) updateProgress(progress[0], progress[1], total_file, img_file) # Get image's path img_path = os.path.join(path, img_file) # Read a image img = cv2.imread(img_path, 0) X_train.append(getHistogram(img)) y_train.append(hands_valid) return X_train, y_train