コード例 #1
0
ファイル: YARPBlobFinder.cpp プロジェクト: paulfitz/poker
void YARPBlobFinder::RemoveNonValid (void)
{
	const int max_size = m_lp.GetSize() * m_lp.GetSize() / 8;
	const int min_size = 100;

	for (int i = 1; i < m_last_tag;)
	{
		int area = TotalArea (m_boxes[i]);
		if (m_boxes[i].valid == false || 
			m_boxes[i].total_pixels < 5 ||
			area < min_size ||
			area > max_size)
		{
			if (i == (m_last_tag-1))
				m_last_tag--;
			else
			{
				memcpy (&(m_boxes[i]), &(m_boxes[i+1]), sizeof(YARPBox) * (m_last_tag - i - 1));
				m_last_tag--;
			}
		}
		else
			i++;
	}
}
コード例 #2
0
ファイル: tmix.c プロジェクト: AEonZR/GtkRadiant
void Cmd_TextureMix()
{
    miptex32_t		*qtex32;
    char			filename[1024];
    int				size;

    InitVars();

    GetScriptToken (false);

    strcpy(root, token);
    RemoveExt(root);
    RemoveLeading(root);

    strcpy(filename, ExpandPathAndArchive(token));
    if (SetVars(filename))
    {
        // Create combined texture
        percent = ((TotalArea() * 100) / (out.w * out.h));
        printf("Total area consumed : %d%%\n", percent);
        printf("Texture resolution  : %dx%d pixels.\n", xcharsize, ycharsize);
        CreateMain();

        // Save image as m32
        sprintf (filename, "%spics/misc/%s.m32", gamedir, out.name);
        qtex32 = CreateMip32((unsigned *)outpixels, out.w, out.h, &size, false);

        qtex32->contents = 0;
        qtex32->value = 0;
        qtex32->scale_x = 1.0;
        qtex32->scale_y = 1.0;
        sprintf (qtex32->name, "misc/%s", out.name);

        printf ("\n\nwriting %s\n", filename);
        SaveFile (filename, (byte *)qtex32, size);
        free (qtex32);

        // Save out script file
        sprintf (filename, "%spics/misc/%s.fnt", gamedir, outscript);
        printf("Writing %s as script file\n", filename);
        if (!SaveScript(filename))
        {
            printf("Unable to save output script.\n");
        }
    }
    printf("Everythings groovy.\n");
    Cleanup();
}
コード例 #3
0
ファイル: YARPBlobFinder.cpp プロジェクト: paulfitz/poker
void YARPBlobFinder::PrintBoxes (YARPBox *m_boxes, int size)
{
	for (int i = 0; i < size; i++)
	{
		printf ("box : %d\n", i);

		if (m_boxes[i].valid)
		{
			printf ("area : %d\n", TotalArea (m_boxes[i]));

			printf ("cmin, cmax : %d %d\n", m_boxes[i].cmin, m_boxes[i].cmax);
			printf ("rmin, rmax : %d %d\n", m_boxes[i].rmin, m_boxes[i].rmax);
			printf ("xmin, xmax : %d %d\n", m_boxes[i].xmin, m_boxes[i].xmax);
			printf ("ymin, ymax : %d %d\n", m_boxes[i].ymin, m_boxes[i].ymax);
			printf ("total_sal : %d\n", m_boxes[i].total_sal);
			printf ("total_pix : %d\n", m_boxes[i].total_pixels);
			printf ("sx, sy : %d %d\n", m_boxes[i].xsum, m_boxes[i].ysum);
		}
	}

}
コード例 #4
0
ファイル: YARPBlobFinder.cpp プロジェクト: paulfitz/poker
void YARPBlobFinder::_apply(const YARPGenericImage& is, YARPGenericImage& id)
{
	// hsv_enhanced is already filled out.

	m_last_tag = SpecialTagging (m_tagged, m_hsv_enhanced);

	// I've got the tagged image now.
	assert (m_last_tag <= MaxBoxesBlobFinder);

	//printf ("last_tag is %d\n", m_last_tag);

	const int w = is.GetWidth ();
	const int h = is.GetHeight ();
	for(int i = 0; i <= m_last_tag; i++)
	{
		m_boxes[i].cmax = m_boxes[i].rmax = 0;
		m_boxes[i].cmax = m_boxes[i].rmax = 0;
		m_boxes[i].cmin = w;
		m_boxes[i].rmin = h;

		m_boxes[i].xmax = m_boxes[i].ymax = 0;
		m_boxes[i].xmin = m_boxes[i].ymin = m_lp.GetSize();

		m_boxes[i].total_sal = 0;
		m_boxes[i].total_pixels = 0;
		m_boxes[i].xsum = m_boxes[i].ysum = 0;
		m_boxes[i].valid = false;
	}
  
	// special case for the null tag (0)
	m_boxes[0].rmax = m_boxes[0].rmin = h/2;
	m_boxes[0].cmax = m_boxes[0].cmin = w/2;
	m_boxes[0].xmax = m_boxes[0].xmin = m_lp.GetSize() / 2;
	m_boxes[0].ymax = m_boxes[0].ymin = m_lp.GetSize() / 2;
	m_boxes[0].valid = true;

	// build all possible bounding boxes out of the tagged image.

	// pixels are logpolar, averaging is done in cartesian.
	unsigned char *source = (unsigned char *)m_hsv_enhanced.GetArray()[0];	// Hue. 
	short *tmp = m_tagged;
	for(int r = 0; r < h; r++)
		for(int c = 0; c < w; c++)
		{
			short tag_index = *tmp++;
			if (tag_index != 0)
			{
				m_boxes[tag_index].total_pixels++;

				// the saliency here is the average hue.
				m_boxes[tag_index].total_sal += *source;
				source += 3;

				m_boxes[tag_index].valid = true;

				// x,y.
				double x, y;
				m_lp.Lp2Cart (double(c), double(r), x, y);

				if (m_boxes[tag_index].ymax < int(y)) m_boxes[tag_index].ymax = int(y);
				if (m_boxes[tag_index].ymin > int(y)) m_boxes[tag_index].ymin = int(y);
				if (m_boxes[tag_index].xmax < int(x)) m_boxes[tag_index].xmax = int(x);
				if (m_boxes[tag_index].xmin > int(x)) m_boxes[tag_index].xmin = int(x);

				if (m_boxes[tag_index].rmax < r) m_boxes[tag_index].rmax = r;
				if (m_boxes[tag_index].rmin > r) m_boxes[tag_index].rmin = r;
				if (m_boxes[tag_index].cmax < c) m_boxes[tag_index].cmax = c;
				if (m_boxes[tag_index].cmin > c) m_boxes[tag_index].cmin = c;

				m_boxes[tag_index].ysum += int(y);
				m_boxes[tag_index].xsum += int(x);
			}
		}
	
	RemoveNonValid ();
	MergeBoxes (); //further clustering not needed.

	// merge boxes which are too close.
	// statically. Clearly this procedure could be more effective 
	// if it takes time into account.
	// LATER: update also the logpolar coordinates during
	//	the merger of the boxes.

	int max_tag, max_num;

	// create now the subset of attentional boxes.
	for (int box_num = 0; box_num < MaxBoxes; box_num++)
    {
		// find the most frequent tag, zero does not count 
		max_tag = max_num = 0;
		for(int i = 1; i < m_last_tag; i++)
		{
			int area = TotalArea (m_boxes[i]);
			if (area > max_num && m_boxes[i].total_pixels > 0)
			//if(m_boxes[i].total_pixels > max_num)
			{
				max_num = area; //m_boxes[i].total_pixels;
				max_tag = i;
			}
		}

		if (max_tag != 0)
		{
			// compute saliency of region.
			// it cannot be done here.
			m_attn[box_num] = m_boxes[max_tag];

			m_attn[box_num].valid = true;
			m_attn[box_num].centroid_y = m_boxes[max_tag].ysum / max_num;
			m_attn[box_num].centroid_x = m_boxes[max_tag].xsum / max_num;
			
			m_boxes[max_tag].total_pixels = 0;
		}
		else
		{
			// no motion, return the center 
			m_attn[box_num].valid = false;
			m_attn[box_num].centroid_x = m_lp.GetSize() / 2;
			m_attn[box_num].centroid_y = m_lp.GetSize() / 2;
		}
	}

	//PrintBoxes (m_attn, MaxBoxes);

	// I've here MaxBoxes boxes accounting for the largest 
	// regions in the image.
	// remember that there's a bias because of logpolar.

	// destination image is not changed.
	// should I store the result of the tagging process?
}