def test_FileJson_interface(): # Given the following directory and dictionary data test_file, test_data = generate_file_and_data(data_type="dict") # When perform write it to file and read file_io.FileJson().write(test_data, test_file) read_data = file_io.FileJson().read(test_file) # Then it should be equal to the original test_data assert test_data == read_data # Remove test files and directory shutil.rmtree(os.path.dirname(test_file))
"--n_test_image", help="Number of Test Images", default=DEFAULT_N_TEST_IMAGE, type=int) parser.add_argument('-n', "--nms", help="Non Maxima Suppresiion", default=DEFAULT_NMS, type=int) parser.add_argument('-s', "--show_operation", help="Show Detect Running Operation", default=DEFAULT_SHOW_OP, type=int) args = vars(parser.parse_args()) conf = file_io.FileJson().read(args["config"]) test_image_files = file_io.list_files(conf["dataset"]["pos_data_dir"]) test_image_files = test_image_files[:args["n_test_image"]] # 2. Build detector and save it detector = factory.Factory.create_detector( conf["descriptor"]["algorithm"], conf["descriptor"]["parameters"], conf["classifier"]["algorithm"], conf["classifier"]["parameters"], conf["classifier"]["output_file"]) # 3. Run detector on Test images for image_file in test_image_files: test_image = cv2.imread(image_file) #test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY)
#-*- coding: utf-8 -*- import subprocess import object_detector.file_io as file_io CONFIG_FILE = "conf/car_side.json" #CONFIG_FILE = "conf/faces.json" N_RUNNING_TEST_IMAGE = 1 N_EVALUATION_TEST_IMAGE = "all" SHOW_RUNNING_OPERATION = 0 if __name__ == "__main__": conf = file_io.FileJson().read(CONFIG_FILE) print "\n[Step 1] Getting average size of the target object.\n\ You can set or edit your detector's window size referring this result.\n\ config_file.json[\"detector\"][\"window_dim\"]\n\ [INFO] current setting is {}".format( conf["detector"]["window_dim"]) subprocess.call("python 1_get_object_size.py -c {}".format(CONFIG_FILE)) print "\n[Step 2] Extracting features" subprocess.call("python 2_extract_features.py -c {}".format(CONFIG_FILE)) print "\n[Step 3] Training classifier. (Note: It can be time-consuming task)" subprocess.call("python 3_train.py -c {} -i {}".format(CONFIG_FILE, False)) print "\n[Step 4] Gathering Hard Negative Samples" subprocess.call("python 4_hard_negative_mine.py -c {}".format(CONFIG_FILE))
if __name__ == "__main__": # 1. Load configuration file and test images parser = ap.ArgumentParser() parser.add_argument('-c', "--config", help="Configuration File", default=DEFAULT_CONFIG_FILE) parser.add_argument('-t', "--n_test_image", help="Number of Test Images", default=DEFAULT_N_TEST_IMAGE, type=str) args = vars(parser.parse_args()) conf = file_io.FileJson().read(DEFAULT_CONFIG_FILE) test_image_files = file_io.list_files(conf["dataset"]["pos_data_dir"]) if args["n_test_image"] == "all": pass else: n_test_imgs = int(args["n_test_image"]) test_image_files = test_image_files[:n_test_imgs] print len(test_image_files) # 2. Build detector detector = factory.Factory.create_detector( conf["descriptor"]["algorithm"], conf["descriptor"]["parameters"], conf["classifier"]["algorithm"], conf["classifier"]["parameters"], conf["classifier"]["output_file"])