Пример #1
0
static void
add_line_to_postscript(paps_private_t *paps,
		       GString *line_str,
		       double x_pos,
		       double y_pos,
		       PangoLayoutLine *line)
{
  PangoRectangle ink_rect, logical_rect;

  pango_layout_line_get_extents(line,
                                &ink_rect,
                                &logical_rect);




#if 0
  // TBD - Handle RTL scripts
  if (paps->pango_dir == PANGO_DIRECTION_RTL) {
      x_pos += page_layout->column_width  - logical_rect.width / (page_layout->pt_to_pixel * PANGO_SCALE);
  }
#endif

  draw_contour(paps, line_str, line, x_pos, y_pos);
}
Пример #2
0
/* Find fastest path from known maze information
 * and return the FRBL turn array to the caller.
 * if first turn is one of RBL, it means that the
 * mouse has to make back turn or smooth L/R turn.
 * In that case, no diagonal turns.
 *
 * fast_path_type: 0 find all possible pathes
 *                 1 find from only known blocks
 */
unsigned char *find_maze_fastest_path(
    unsigned char cur_mouse_pos, char cur_mouse_dir,
    unsigned int search_type, struct s_link *f_node,
    int fast_path_type)
{
    unsigned char *path;
    struct s_link *mouse_path;
    struct s_link *sl_fast_path;
#ifdef DEBUG
    int i;
#endif

    if (!f_node)
        print_exit("f_node NULL\n");
    print_dbg(DEBUG_SEARCH, "mouse pos:%d,%d mouse_dir:%d "
              "search_type:%d\n", pos_x(cur_mouse_pos),
              pos_y(cur_mouse_pos), cur_mouse_dir,
              search_type);
    /* draw contour map from the goal */
    draw_contour(maze_search, contour_map,
                 search_type, cur_mouse_pos);
    /* generate full binary tree with all pathes */
    mouse_path = gen_bin_tree(maze_search,
                              contour_map, cur_mouse_pos, cur_mouse_dir);
    /* find the fastest path and get the node */
    sl_fast_path = find_fastest_path(mouse_path, fast_path_type);

    if (sl_fast_path) {

        memcpy(f_node, sl_fast_path, sizeof(struct s_link));

        /* Free sl_nodes after searching the fastest path */
        sl_node_free(mouse_path);
    } else {
        sl_node_free(mouse_path);
        return NULL;
    }

    /* generate FRBL array for the fastest path */
    path = gen_frbl_from_node(f_node);

#ifdef DEBUG
    printf("%s\n", __func__);
    for (i = 0; path[i] != 0xff; i++)
        printf("%C",
               (path[i] == FD) ? 'F' : \
               ((path[i] == RD) ? 'R' : \
                ((path[i] == BD) ? 'B' : \
                 ((path[i] == LD) ? 'L' : 'X'))));
    printf("\n");
#endif

    return path;
}
Пример #3
0
int main (int argc, char *argv[])
{
	IplImage *rgb, *depth, *tmp, *body, *hand;
	CvMat **tr, *mean, *cov;
	CvFileStorage *fs;
	int count=0, p=0, warmup=1;

	parse_args(argc, argv);

	rgb = cvCreateImage(cvSize(W,H), 8, 3);
	tr = (CvMat**)malloc(sizeof(CvMat*)*num);
	init_training_data(tr,num);
	mean = cvCreateMat(1, FD_NUM, CV_64FC1);
	cov  = cvCreateMat(FD_NUM, FD_NUM, CV_64FC1);

	fs = cvOpenFileStorage(outfile, NULL, CV_STORAGE_WRITE, NULL);
	assert(fs);

	for (;;) {
		int z, k, c;
		CvMat *fd;
		CvSeq *cnt;
		
		tmp = freenect_sync_get_rgb_cv(0);
		cvCvtColor(tmp, rgb, CV_BGR2RGB);
		depth = freenect_sync_get_depth_cv(0);
		body = body_detection(depth);
		hand = hand_detection(body, &z);

		if (!get_hand_contour_advanced(hand, rgb, z, &cnt, NULL))
		 	continue; 

		if (warmup) {
			draw_contour(cnt);
			if (k = cvWaitKey(T) == 'g') {
				warmup = 0;
				cvDestroyAllWindows();
			}
			continue;
		}

		fd = get_fourier_descriptors(cnt);
		add_training_data(tr[count], fd);

		if (count == 0)
			printf("---> training hand pose %d\n", p);

		if (++count == num) {
			int c;

			cvCalcCovarMatrix((void*)tr, count, cov, mean, CV_COVAR_NORMAL);
			cvInvert(cov, cov, CV_LU);
			save_posture_model(fs, mean, cov);
			p++;
			count = 0;

			printf("save and quit:s  exit:q  next:any \n");
			
			if ((c = cvWaitKey(0)) == 's') {
				break;
			} else if (c == 'q') {
				break;
			} else {
				continue;
			}
		}

		draw_contour(cnt);
		cvWaitKey(T);
	}

	cvWriteInt(fs, "total", p);

	freenect_sync_stop();

	free_training_data(tr,num);
	cvReleaseFileStorage(&fs);
	cvReleaseMat(&mean);
	cvReleaseMat(&cov);
	cvReleaseImage(&rgb);

	return 0;
}
void compute_optimized()
{
	const int divisions = 5;
	const int generations = 10;
	const int initial_seed_num = 10;
	const int min_seed_num = 1;
	const int max_seed_num = 10;

	const int items_in_each_division = points_collection.size() / divisions;
	const int points_collection_size = points_collection.size();

	int total_iterations = 0;

	bool checker[1000] { 0 };
	unordered_map<int, float> division_dist_min_checker;
	unordered_map<float, int> dist_min_division_checker;
	unordered_map<float, bool> dist_min_checker;
	unordered_map<float, int> dist_min_index_checker;

	float dist_min_selected = 9999;
	vector<Point> database_points_selected;

	for (int i = 0; i < generations; ++i)
	{
		for (int a = 0; a < (points_collection_size - 1); a += items_in_each_division)
		{
			int index_min = a;
			int index_max = a + items_in_each_division;

			vector<int> seed_indexes;
			for (int b = index_min; b <= index_max; ++b)
				seed_indexes.push_back(b);

			if (seed_indexes.size() == 0)
				continue;

			int seed_num = initial_seed_num;
			if (i > 0)
			{
				float dist_min = division_dist_min_checker[a];
				int index_division = dist_min_index_checker[dist_min];
				seed_num = map_val(index_division, 0, divisions - 1, min_seed_num, max_seed_num);
			}

			for (int b = 0; b < seed_num; ++b)
			{
				int k = get_random(0, seed_indexes.size() - 1);
				int seed_index = seed_indexes[k];

				if (checker[seed_index] == true)
					continue;

				checker[seed_index] = true;

				vector<Point> database_points = points_collection[seed_index];
				float dist = compute_dtw_dist(points_current, database_points);

				if (dist < dist_min_selected)
				{
					dist_min_selected = dist;
					database_points_selected = database_points;
				}

				++total_iterations;

				float dist_min = division_dist_min_checker.count(a) > 0 ? division_dist_min_checker[a] : 9999;
				if (dist >= dist_min)
					continue;

				dist_min = dist;
				while (dist_min_checker.count(dist_min) > 0)
					dist_min += 0.001;

				dist_min_checker[dist_min] = true;
				division_dist_min_checker[a] = dist_min;
				dist_min_division_checker[dist_min] = a;
			}
		}

		vector<float> dist_min_vec;
		for (int a = 0; a < (points_collection_size - 1); a += items_in_each_division)
			dist_min_vec.push_back(division_dist_min_checker[a]);

		std::sort(dist_min_vec.begin(), dist_min_vec.end(), decreasing());

		int index = -1;
		for (float& dist_min : dist_min_vec)
		{
			++index;
			dist_min_index_checker[dist_min] = index;
		}
	}

	Mat image_haha = Mat::zeros(HEIGHT_SMALL, WIDTH_SMALL, CV_8UC1);
	draw_contour(database_points_selected, image_haha, 254, 1, 0);
	imshow("image_haha", image_haha);

	waitKey(1);

	cout << total_iterations << endl;
}