def __init__(self): self.list_out = [] self.list_pic = [] try: self.input_dir = sys.argv[1] self.output_dir = sys.argv[2] self.vehicle_threshold = .5 self.vehicle_weights = 'data/vehicle-detector/yolo-voc.weights' self.vehicle_netcfg = 'data/vehicle-detector/yolo-voc.cfg' self.vehicle_dataset = 'data/vehicle-detector/voc.data' self.vehicle_net = dn.load_net(self.vehicle_netcfg, self.vehicle_weights, 0) self.vehicle_meta = dn.load_meta(self.vehicle_dataset) self.imgs_paths = image_files_from_folder(self.input_dir) self.imgs_paths.sort() #if not isdir(self.output_dir): # makedirs(self.output_dir) except: traceback.print_exc() sys.exit(1)
def main(): args = parse_args() # Retrieve the names of the input images imgs_paths = image_files_from_folder(args.input_folder) for img_path in imgs_paths: # Process each image individually process_image(img_path, args)
def generate_outputs(input_dir, output_dir): img_files = image_files_from_folder(input_dir) for img_file in img_files: bname = splitext(basename(img_file))[0] I = cv2.imread(img_file) detected_cars_labels = '%s/%s_cars.txt' % (output_dir, bname) Lcar = lread(detected_cars_labels) sys.stdout.write('%s' % bname) if Lcar: for i, lcar in enumerate(Lcar): draw_label(I, lcar, color=YELLOW, thickness=3) lp_label = '%s/%s_%dcar_lp.txt' % (output_dir, bname, i) lp_label_str = '%s/%s_%dcar_lp_str.txt' % (output_dir, bname, i) if isfile(lp_label): Llp_shapes = readShapes(lp_label) pts = Llp_shapes[0].pts * lcar.wh().reshape(2, 1) + lcar.tl().reshape(2, 1) ptspx = pts * np.array(I.shape[1::-1], dtype=float).reshape(2, 1) draw_losangle(I, ptspx, RED, 3) if isfile(lp_label_str): with open(lp_label_str, 'r') as f: lp_str = f.read().strip() llp = Label(0, tl=pts.min(1), br=pts.max(1)) write2img(I, llp, lp_str) sys.stdout.write(',%s' % lp_str) cv2.imwrite('%s/%s_output.png' % (output_dir, bname), I)
input_dir = sys.argv[1] output_dir = sys.argv[2] vehicle_threshold = .5 vehicle_weights = 'data/vehicle-detector/yolo-voc.weights' #.encode('ascii') vehicle_netcfg = 'data/vehicle-detector/yolo-voc.cfg' #.encode('ascii').encode('ascii') vehicle_dataset = 'data/vehicle-detector/voc.data' #.encode('ascii') vehicle_weights = vehicle_weights.encode('ascii') vehicle_netcfg = vehicle_netcfg.encode('ascii') vehicle_dataset = vehicle_dataset.encode('ascii') #print(vehicle_weights) vehicle_net = dn.load_net(vehicle_netcfg, vehicle_weights, 0) vehicle_meta = dn.load_meta(vehicle_dataset) imgs_paths = image_files_from_folder(input_dir) imgs_paths.sort() if not isdir(output_dir): makedirs(output_dir) print('Searching for vehicles using YOLO...') for i, img_path in enumerate(imgs_paths): print('\tScanning %s' % img_path) bname = basename(splitext(img_path)[0]) img_path2 = img_path.encode('ascii') R, _ = detect(vehicle_net,
outdir = args.output_dir iterations = args.iterations batch_size = args.batch_size dim = 208 if not isdir(outdir): makedirs(outdir) model, model_stride, xshape, yshape = load_network(args.model, dim) opt = getattr(keras.optimizers, args.optimizer)(lr=args.learning_rate) model.compile(loss=loss, optimizer=opt) print('Checking input directory...') Files = image_files_from_folder(train_dir) Data = [] for file in Files: labfile = splitext(file)[0] + '.txt' if isfile(labfile): L = readShapes(labfile) I = cv2.imread(file) Data.append([I, L[0]]) print('%d images with labels found' % len(Data)) dg = DataGenerator( data=Data, \ process_data_item_func=lambda x: process_data_item(x,dim,model_stride),\ xshape=xshape, \ yshape=(yshape[0],yshape[1],yshape[2]+1), \
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8') import cv2 import numpy as np from os.path import splitext, basename, isfile from src.utils import image_files_from_folder from src.drawing_utils import draw_label, draw_losangle, write2img from src.label import lread, Label, readShapes YELLOW = (0, 255, 255) RED = (0, 0, 255) input_dir = sys.argv[1] output_dir = sys.argv[2] img_files = image_files_from_folder(input_dir) for img_file in img_files: bname = splitext(basename(img_file))[0] I = cv2.imread(img_file) detected_cars_labels = '%s/%s_cars.txt' % (output_dir, bname) Lcar = lread(detected_cars_labels) sys.stdout.write('%s' % bname) if Lcar:
input_dir = sys.argv[1] output_dir = sys.argv[2] vehicle_threshold = .5 vehicle_weights = 'data/vehicle-detector/yolo-voc.weights'.encode( 'utf-8') vehicle_netcfg = 'data/vehicle-detector/yolo-voc.cfg'.encode('utf-8') vehicle_dataset = 'data/vehicle-detector/voc.data'.encode('utf-8') vehicle_net = dn.load_net(vehicle_netcfg, vehicle_weights, 0) vehicle_meta = dn.load_meta(vehicle_dataset) imgs_paths = [path.encode('utf-8') for path in image_files_from_folder(input_dir)] imgs_paths.sort() if not isdir(output_dir): makedirs(output_dir) print('Searching for vehicles using YOLO...') for i, img_path in enumerate(imgs_paths): print('\tScanning %s' % img_path) bname = basename(splitext(img_path)[0]) R, _ = detect(vehicle_net, vehicle_meta, img_path, thresh=vehicle_threshold)
def __init__(self, path, img_size=208): self.img_files = image_files_from_folder(path) n = len(self.img_files) assert n > 0, 'No images found in %s' % path self.img_size = img_size