static char *run_failure_tests(int obstruct, catcierge_lockout_method_t lockout_method)
{
	char *e = NULL;
	size_t i;
	catcierge_grb_t grb;
	catcierge_args_t *args = &grb.args;

	catcierge_grabber_init(&grb);
	grb.running = 1;

	args->saveimg = 0;
	args->lockout_method = lockout_method;
	args->lockout_time = 2;
	args->matcher = "template";
	args->matcher_type = MATCHER_TEMPLATE;
	args->templ.match_flipped = 1;
	args->templ.match_threshold = 0.8;
	set_default_test_snouts(args);

	if (catcierge_matcher_init(&grb.matcher, (catcierge_matcher_args_t *)&args->templ))
	{
		return "Failed to init catcierge lib!\n";
	}

	catcierge_template_matcher_print_settings(&args->templ);

	catcierge_set_state(&grb, catcierge_state_waiting);

	//
	// Run the same twice so we're sure the timers work
	// several times properly.
	//
	for (i = 0; i < 2; i++)
	{
		// Obstruct the frame to begin matching.
		load_test_image_and_run(&grb, 1, 2);
		mu_assert("Expected MATCHING state", (grb.state == catcierge_state_matching));
	
		// Pass 4 frames (first ok, the rest not...)
		load_test_image_and_run(&grb, 1, 2);
		mu_assert("Expected MATCHING state", (grb.state == catcierge_state_matching));
	
		load_test_image_and_run(&grb, 1, 3);
		mu_assert("Expected MATCHING state", (grb.state == catcierge_state_matching));
	
		load_test_image_and_run(&grb, 1, 4);
		mu_assert("Expected MATCHING state", (grb.state == catcierge_state_matching));
	
		load_test_image_and_run(&grb, 1, 4);
		mu_assert("Expected LOCKOUT state", (grb.state == catcierge_state_lockout));
		catcierge_test_STATUS("Lockout state as expected");
	
		// Test the lockout logic.
		if ((e = run_lockout_tests(&grb, obstruct, lockout_method)))
		{
			return e;
		}
	}

	catcierge_matcher_destroy(&grb.matcher);
	catcierge_grabber_destroy(&grb);

	return NULL;
}
//
// Tests passing 1 initial image that triggers matching.
// Then pass 4 images that should result in a successful match.
// Finally if "obstruct" is set, a single image is passed that obstructs the frame.
// After that we expect to go back to waiting.
//
static char *run_success_tests(int obstruct)
{
	int i;
	int j;
	catcierge_grb_t grb;
	catcierge_args_t *args = &grb.args;

	catcierge_grabber_init(&grb);
	grb.running = 1;

	args->matcher = "template";
	args->matcher_type = MATCHER_TEMPLATE;
	args->saveimg = 0;
	args->templ.match_flipped = 1;
	args->templ.match_threshold = 0.8;
	args->templ.snout_paths[0] = CATCIERGE_SNOUT1_PATH;
	args->templ.snout_count++;
	args->templ.snout_paths[1] = CATCIERGE_SNOUT2_PATH;
	args->templ.snout_count++;

	if (catcierge_matcher_init(&grb.matcher, (catcierge_matcher_args_t *)&args->templ))
	{
		return "Failed to init catcierge lib!\n";
	}

	catcierge_template_matcher_set_debug((catcierge_template_matcher_t *)grb.matcher, 0);

	catcierge_template_matcher_print_settings(&args->templ);

	catcierge_set_state(&grb, catcierge_state_waiting);

	// Give the state machine a series of known images
	// and make sure the states are as expected.
	for (j = 1; j <= 5; j++)
	{
		catcierge_test_STATUS("Test series %d", j);

		// This is the initial image that obstructs the frame
		// and triggers the matching.
		load_test_image_and_run(&grb, j, 1);
		mu_assert("Expected MATCHING state", (grb.state == catcierge_state_matching));

		// Match against 4 pictures, and decide the lockout status.
		for (i = 1; i <= 4; i++)
		{
			load_test_image_and_run(&grb, j, i);
		}

		mu_assert("Expected KEEP OPEN state", (grb.state == catcierge_state_keepopen));

		if (obstruct)
		{
			// First obstruct the frame.
			load_test_image_and_run(&grb, j, 1);
			mu_assert("Expected KEEP OPEN state", (grb.state == catcierge_state_keepopen));

			// And then clear it.
			load_test_image_and_run(&grb, 1, 5);
			mu_assert("Expected WAITING state", (grb.state == catcierge_state_waiting));
		}
		else
		{
			// Give it a clear frame so that it will stop
			load_test_image_and_run(&grb, 1, 5);
			mu_assert("Expected WAITING state", (grb.state == catcierge_state_waiting));
		}
	}

	catcierge_template_matcher_destroy(&grb.matcher);
	catcierge_grabber_destroy(&grb);

	return NULL;
}
Example #3
0
void catcierge_print_settings(catcierge_args_t *args)
{
	#ifdef WITH_RFID
	size_t i;
	#endif

	printf("--------------------------------------------------------------------------------\n");
	printf("Settings:\n");
	printf("--------------------------------------------------------------------------------\n");
	printf("General:\n");
	printf("          Show video: %d\n", args->show);
	printf("        Save matches: %d\n", args->saveimg);
	printf("       Save obstruct: %d\n", args->save_obstruct_img);
	printf("          Save steps: %d\n", args->save_steps);
	printf("     Highlight match: %d\n", args->highlight_match);
	printf("       Lockout dummy: %d\n", args->lockout_dummy);
	printf("      Lockout method: %d\n", args->lockout_method);
	printf("           Lock time: %d seconds\n", args->lockout_time);
	printf("       Lockout error: %d %s\n", args->max_consecutive_lockout_count,
							(args->max_consecutive_lockout_count == 0) ? "(off)" : "");
	printf("   Lockout err delay: %0.1f\n", args->consecutive_lockout_delay);
	printf("       Match timeout: %d seconds\n", args->match_time);
	printf("            Log file: %s\n", args->log_path ? args->log_path : "-");
	printf("            No color: %d\n", args->nocolor);
	printf("        No animation: %d\n", args->noanim);
	printf("   Ok matches needed: %d\n", args->ok_matches_needed);
	printf("         Output path: %s\n", args->output_path);
	if (args->match_output_path && strcmp(args->output_path, args->match_output_path))
	printf("   Match output path: %s\n", args->match_output_path);
	if (args->steps_output_path && strcmp(args->output_path, args->steps_output_path))
	printf("   Steps output path: %s\n", args->steps_output_path);
	if (args->obstruct_output_path && strcmp(args->output_path, args->obstruct_output_path))
	printf("Obstruct output path: %s\n", args->obstruct_output_path);
	if (args->template_output_path && strcmp(args->output_path, args->template_output_path))
	printf("Template output path: %s\n", args->template_output_path);
	#ifdef WITH_ZMQ
	printf("       ZMQ publisher: %d\n", args->zmq);
	printf("            ZMQ port: %d\n", args->zmq_port);
	printf("       ZMQ interface: %s\n", args->zmq_iface);
	printf("       ZMQ transport: %s\n", args->zmq_transport);
	#endif // WITH_ZMQ
	printf("        Matcher type: %s\n", args->matcher);
	printf("\n"); 
	if (!args->matcher || !strcmp(args->matcher, "template"))
		catcierge_template_matcher_print_settings(&args->templ);
	else
		catcierge_haar_matcher_print_settings(&args->haar);
	#ifdef WITH_RFID
	printf("RFID:\n");
	printf("          Inner RFID: %s\n", args->rfid_inner_path ? args->rfid_inner_path : "-");
	printf("          Outer RFID: %s\n", args->rfid_outer_path ? args->rfid_outer_path : "-");
	printf("     Lock on no RFID: %d\n", args->lock_on_invalid_rfid);
	printf("      RFID lock time: %.2f seconds\n", args->rfid_lock_time);
	printf("        Allowed RFID: %s\n", (args->rfid_allowed_count <= 0) ? "-" : args->rfid_allowed[0]);
	for (i = 1; i < args->rfid_allowed_count; i++)
	{
		printf("                 %s\n", args->rfid_allowed[i]);
	}
	#endif // WITH_RFID
	printf("--------------------------------------------------------------------------------\n");

}