void compute_stereo_permutation(MonoProcessorNew& mono_processor0, MonoProcessorNew& mono_processor1,
								PointResolver& point_resolver, PointerMapper& pointer_mapper, Mat& image0, Mat& image1)
{
	MonoData mono_data_large;
	MonoData mono_data_small;
	MonoData mono_data0;
	MonoData mono_data1;
	bool side_flipped;
	if (mono_processor0.fingertip_points.size() > mono_processor1.fingertip_points.size())
	{
		mono_data_large = MonoData(&mono_processor0.fingertip_points, &mono_processor0, image0, 0);
		mono_data_small = MonoData(&mono_processor1.fingertip_points, &mono_processor1, image1, 1);
		mono_data0 = mono_data_large;
		mono_data1 = mono_data_small;
		side_flipped = false;
	}
	else
	{
		mono_data_small = MonoData(&mono_processor0.fingertip_points, &mono_processor0, image0, 0);
		mono_data_large = MonoData(&mono_processor1.fingertip_points, &mono_processor1, image1, 1);
		mono_data1 = mono_data_large;
		mono_data0 = mono_data_small;
		side_flipped = true;
	}

	const int large_array_size = mono_data_large.array->size() > 5 ? 5 : mono_data_large.array->size();
	const int small_array_size = mono_data_small.array->size() > 5 ? 5 : mono_data_small.array->size();

	compute_permutations(large_array_size, small_array_size);

	float dist_sigma_min = 9999;
	StereoPair stereo_pair_dist_sigma_min;

	Point pt_y_max_large = get_y_max_point(*mono_data_large.array);
	Point pt_y_max_small = get_y_max_point(*mono_data_small.array);
	int alignment_y_diff = pt_y_max_large.y - pt_y_max_small.y;
	int alignment_x_diff = mono_data_large.mono_processor->pt_alignment.x - mono_data_small.mono_processor->pt_alignment.x;

	for (vector<int>& rows : permutations)
	{
		float dist_sigma = 0;
		StereoPair stereo_pair;

		int small_array_index = 0;
		for (int large_array_index : rows)
		{
			stereo_pair.push_large_index(large_array_index);
			stereo_pair.push_small_index(small_array_index);

			Point pt_small_array = (*mono_data_small.array)[small_array_index];
			Point pt_large_array = (*mono_data_large.array)[large_array_index];

			pt_small_array.x += alignment_x_diff;
			pt_small_array.y += alignment_y_diff;

			float dist = get_distance(pt_small_array, pt_large_array, false);
			dist_sigma += dist;

			++small_array_index;
		}
		if (dist_sigma < dist_sigma_min)
		{
			dist_sigma_min = dist_sigma;
			stereo_pair_dist_sigma_min = stereo_pair;
		}
	}

	stereo_pair_dist_sigma_min.compute(mono_data_large.array,                           mono_data_small.array,
									   mono_data_large.mono_processor->fingertip_blobs, mono_data_small.mono_processor->fingertip_blobs,
									   mono_data0,                                      mono_data1,
									   side_flipped);

	Mat image_visualization = Mat::zeros(HEIGHT_LARGE, WIDTH_LARGE, CV_8UC1);

	Point pt_resolved_pivot0 = point_resolver.reprojector->remap_point(mono_data0.mono_processor->pt_palm, mono_data0.side, 4);
	Point pt_resolved_pivot1 = point_resolver.reprojector->remap_point(mono_data1.mono_processor->pt_palm, mono_data1.side, 4);

	static const int frame_cache_num = 3;
	static int cached_count = -1;
	static bool begin_action = false;

	++cached_count;
	if (cached_count == frame_cache_num)
	{
		cached_count = 0;
		begin_action = true;
	}

	static StereoPair stereo_pair_vec[frame_cache_num];
	stereo_pair_vec[cached_count] = stereo_pair_dist_sigma_min;

	if (!begin_action)
		return;

	int index_before = cached_count - (frame_cache_num - 1);
	if (index_before < 0)
		index_before = frame_cache_num + index_before;

	StereoPair stereo_pair_current = stereo_pair_vec[index_before];

	for (int i = 0; i < stereo_pair_current.pt_vec_large_sorted.size(); ++i)
	{
		BlobNew* blob_large = &stereo_pair_current.blob_vec_large_sorted[i];
		BlobNew* blob_small = &stereo_pair_current.blob_vec_small_sorted[i];
		BlobNew* blob0 = stereo_pair_current.side_flipped ? blob_small : blob_large;
		BlobNew* blob1 = stereo_pair_current.side_flipped ? blob_large : blob_small;

		Point2f pt_resolved0 = point_resolver.compute(blob0->pt_tip,
							       stereo_pair_current.mono_data0.image, stereo_pair_current.mono_data0.side);
		Point2f pt_resolved1 = point_resolver.compute(blob1->pt_tip,
								   stereo_pair_current.mono_data1.image, stereo_pair_current.mono_data1.side);

#if 0
		circle(image_visualization, pt_resolved0, 5, Scalar(127), 2);
		circle(image_visualization, pt_resolved1, 5, Scalar(254), 2);
		circle(image_visualization, pt_resolved_pivot0, 10, Scalar(127), 2);
		circle(image_visualization, pt_resolved_pivot1, 10, Scalar(254), 2);
#endif

#if 1
		if (pt_resolved0.x != 9999 && pt_resolved1.x != 9999)
		{
			Point3f pt3d = point_resolver.reprojector->reproject_to_3d(pt_resolved0.x, pt_resolved0.y,
																	   pt_resolved1.x, pt_resolved1.y);
			
			circle(image_visualization, Point(320 + pt3d.x, 240 + pt3d.y), pow(1000 / pt3d.z, 2), Scalar(127), 1);
		}
#endif
	}
	imshow("image_visualizationiuhuewli", image_visualization);
}
示例#2
0
////////////////////////////////////////////////////////////////////////////////////////////////
///// ********** PUBLIC METHODS ////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
RRSchedule::RRSchedule(int _max_weeks, int _max_times, int _max_courts, int _max_teams, char* _FILENAME, int SKIP_FIRST)
{
    max_weeks = _max_weeks;
    max_times = _max_times;
    max_courts = _max_courts;
    max_teams = _max_teams;
    skip_first = SKIP_FIRST;
    
    
    FILENAME = _FILENAME;
    
    week0 = (skip_first > 0);   // Check if special considerations need to be made for the first week (allowing a meeting)
    
    min_per_night = (max_courts * max_times * 2) / max_teams;
    w0_min_per_night = (max_courts * (max_times-skip_first) * 2) / max_teams;
    
    max_per_night = (max_courts * max_times * 2) / max_teams + ( ((max_courts * max_times * 2) % max_teams) != 0);
    w0_max_per_night = (max_courts * (max_times - skip_first) * 2) / max_teams + ( ((max_courts * (max_times - skip_first) * 2) % max_teams) != 0);
    
    MAX_PLAYED_GAP = 1; // <= Gap between min times played and max times played
    
    if (max_per_night > 2) then:
    {
        MAX_WAIT_TIME = min_per_night;   // <= Max time a team can wait each night
    }
    else
    {
        MAX_WAIT_TIME = min_per_night;
    }
    
    MAX_WAIT_GAP = 1; //*max_times ; // /2;   // <= Gap between min team wait time and max team wait time
    
    MAX_TIMESLOT_GAP = 2 ; //max_weeks / 2; // <=  Gap between count of min timeslot vs. max timeslot appearances
    TIMESLOT_FUDGE = 0; // *max_per_night; // Allow teams to play in a timeslot # over "ideal"
    max_per_time = (max_weeks * max_courts * 2) / max_teams + ( ((max_weeks * max_courts * 2) % max_teams) != 0) + TIMESLOT_FUDGE; //    std::cout << "**" <<std:endl;
    
    
    fullSolution = false;
    total_wait_time = 0;
    
    init1D(this_week_played, max_teams);
    allocate1D(courts, max_courts*2);
    init1D(total_played, max_teams);
    init1D(total_waiting_by_team, max_teams);
    
    init2D(opponent_counts, max_teams, max_teams);
    allocate2D(timeslots, max_times, max_courts*2);
    allocate2D(matchups, max_weeks * max_times * max_courts, 2);
    init2D(this_week_matchups, (max_times-skip_first)*max_courts, 2);
    init2D(timeslots_played, max_teams, max_times);
    init2D(courts_played, max_teams, max_courts);
    allocate2D(timePermutes, FACTS[max_times], max_times);
    compute_permutations();
    allocate2D(total_this_week_played,max_weeks, max_teams);
    
    allocate3D(weeks, max_weeks, max_times, max_courts*2);
    
    
    // clear old file
    std::ofstream outputfile;
    outputfile.open(FILENAME);
    outputfile.close();
}