import cv2 from src.controller.video_capture.VideoCapture import VideoCapture from src.debug.debugutils import DebugUtils debug = DebugUtils.get_instance() # TODO get_event class VideoCaptureOpenCV(VideoCapture): def __init__(self, camera): super().__init__(camera) # rtsp://USUARIO:SENHA@IP:PORTA/cam/realmonitor?channel=1&subtype=0 if camera.camera_string == '0': camera.camera_string = 0 self.video_capturer = cv2.VideoCapture(camera.camera_string) def initialize(self): # self.videoCap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('H', '2', '6', '4')); if not self.video_capturer.isOpened(): debug.msg("Cannot open the video cam") return False # TODO nao funciona # self.video_capturer.set(cv2.CAP_PROP_FRAME_HEIGHT, self.camera.y_res) # self.video_capturer.set(cv2.CAP_PROP_FRAME_WIDTH, self.camera.x_res) return True def rewind(self): self.video_capturer.set(cv2.CAP_PROP_POS_FRAMES, 1)
def test_face_trainer_lfw(self): tfe = tec.create_tf_env_default() # Experiment LFW exp = tec.create_experiment('lfw', tfe) logfilename = "{}{date:%Y%m%d-%H%M%S}.txt".format(exp.log_dir(), date=datetime.now()) DebugUtils.get_instance().set_logfilename(logfilename) DebugUtils.get_instance().open_file() camera = camera_controller.create_camera('camera_front', 'stringf', exp) dir_lfw = '/media/denis/dados/face_bds/lfw_face100_min30_max500' for person_name in os.listdir(dir_lfw): try: shutil.copytree( os.path.join(dir_lfw, person_name), os.path.join(exp.face_records_dir(), person_name)) except FileExistsError: pass for person_name in os.listdir(exp.face_records_dir()): pfr = pfrdao.create_person_face_records(exp, person_name, camera) pfrdao.update_object(pfr.person) fnumber = 0 person = pfr.person for file in [ f for f in os.listdir(person.person_db_dir()) if os.path.isfile(os.path.join(person.person_db_dir(), f)) ]: fnumber += 1 pfrc.person_add_face_record(person, file) train = tcc.create_train_configuration(5000, 128) id_train = train.id id_exp = exp.id results = {} for image_size in reversed( TrainConfiguration.get_architecture_sizes()): for relative_size in TrainConfiguration.get_architecture_relative_sizes( ): # for image_size in ['224']: # for relative_size in ['0.50']: tcc.set_image_size(train, int(image_size)) tcc.set_relative_size(train, relative_size) train_exec = train_test_invoker.invoke_trainer(exp, train) # Connection is loosy, invoke_trainer reconnects train = tcc.get_object_by_id(id_train) exp = ec.get_object_by_id(id_exp) results['{}_{}'.format( image_size, relative_size)] = train_exec.test_accuracy # TODO - accuracy varying # self.assertGreater(train_exec.test_accuracy, 0.80) debug.flush_file() debug.msg('Results:') configs = results.keys() for config in sorted(configs): debug.msg('Test accuracy for {}: {}'.format( config, '{0:.4f}%%'.format(results[config] * 100)))