Example #1
0
vector<FloatRect> Sampler::PixelSamples(FloatRect centre, int radius, bool halfSample)
{
	vector<FloatRect> samples;
	
	IntRect s(centre);
	samples.push_back(s);
	
	int r2 = radius*radius;
	for (int iy = -radius; iy <= radius; ++iy)
	{
		for (int ix = -radius; ix <= radius; ++ix)
		{
			if (ix*ix+iy*iy > r2) continue;
			if (iy == 0 && ix == 0) continue; // already put this one at the start
			
			int x = (int)centre.XMin() + ix;
			int y = (int)centre.YMin() + iy;
			if (halfSample && (ix % 2 != 0 || iy % 2 != 0)) continue;
			
			s.SetXMin(x);
			s.SetYMin(y);
			samples.push_back(s);
		}
	}
	
	return samples;
}
Example #2
0
void Tracker::UpdateDebugImage(const vector<FloatRect>& samples, const FloatRect& centre, const vector<double>& scores)
{
	double mn = VectorXd::Map(&scores[0], scores.size()).minCoeff();
	double mx = VectorXd::Map(&scores[0], scores.size()).maxCoeff();
	m_debugImage.setTo(0);
	for (int i = 0; i < (int)samples.size(); ++i)
	{
		int x = (int)(samples[i].XMin() - centre.XMin());
		int y = (int)(samples[i].YMin() - centre.YMin());
		m_debugImage.at<float>(m_config.searchRadius+y, m_config.searchRadius+x) = (float)((scores[i]-mn)/(mx-mn));
	}
}
Example #3
0
void LaRank::Update(const MultiSample& sample, int y)
{
	// add new support pattern
	SupportPattern* sp = new SupportPattern;
	const vector<FloatRect>& rects = sample.GetRects();
	FloatRect centre = rects[y];
	for (int i = 0; i < (int)rects.size(); ++i)
	{
		// express r in coord frame of centre sample
		FloatRect r = rects[i];
		r.Translate(-centre.XMin(), -centre.YMin());
		sp->yv.push_back(r);
		if (!m_config.quietMode && m_config.debugMode)
		{
			// store a thumbnail for each sample
			Mat im(kTileSize, kTileSize, CV_8UC1);
			IntRect rect = rects[i];
			cv::Rect roi(rect.XMin(), rect.YMin(), rect.Width(), rect.Height());
			cv::resize(sample.GetImage().GetImage(0)(roi), im, im.size());
			sp->images.push_back(im);
		}
	}
	// evaluate features for each sample
	sp->x.resize(rects.size());
	const_cast<Features&>(m_features).Eval(sample, sp->x);
	sp->y = y;
	sp->refCount = 0;
	m_sps.push_back(sp);

	ProcessNew((int)m_sps.size()-1);
	BudgetMaintenance();
	
	for (int i = 0; i < 10; ++i)
	{
		Reprocess();
		BudgetMaintenance();
	}
}
Example #4
0
vector<FloatRect> Sampler::RadialSamples(FloatRect centre, int radius, int nr, int nt)
{
	vector<FloatRect> samples;
	
	FloatRect s(centre);
	float rstep = (float)radius/nr;
	float tstep = 2*(float)M_PI/nt;
	samples.push_back(centre);
	
	for (int ir = 1; ir <= nr; ++ir)
	{
		float phase = (ir % 2)*tstep/2;
		for (int it = 0; it < nt; ++it)
		{
			float dx = ir*rstep*cosf(it*tstep+phase);
			float dy = ir*rstep*sinf(it*tstep+phase);
			s.SetXMin(centre.XMin()+dx);
			s.SetYMin(centre.YMin()+dy);
			samples.push_back(s);
		}
	}
	
	return samples;
}
Example #5
0
HaarFeature::HaarFeature(const FloatRect& bb, int type) :
    m_bb(bb) {
    assert(type < 6);

    switch (type) {
    case 0: {
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width(), bb.Height() / 2));
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin() + bb.Height() / 2, bb.Width(), bb.Height() / 2));
        m_weights.push_back(1.f);
        m_weights.push_back(-1.f);
        m_factor = 255 * 1.f / 2;
        break;
    }

    case 1: {
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width() / 2, bb.Height()));
        m_rects.push_back(FloatRect(bb.XMin() + bb.Width() / 2, bb.YMin(), bb.Width() / 2, bb.Height()));
        m_weights.push_back(1.f);
        m_weights.push_back(-1.f);
        m_factor = 255 * 1.f / 2;
        break;
    }

    case 2: {
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width() / 3, bb.Height()));
        m_rects.push_back(FloatRect(bb.XMin() + bb.Width() / 3, bb.YMin(), bb.Width() / 3, bb.Height()));
        m_rects.push_back(FloatRect(bb.XMin() + 2 * bb.Width() / 3, bb.YMin(), bb.Width() / 3, bb.Height()));
        m_weights.push_back(1.f);
        m_weights.push_back(-2.f);
        m_weights.push_back(1.f);
        m_factor = 255 * 2.f / 3;
        break;
    }

    case 3: {
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width(), bb.Height() / 3));
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin() + bb.Height() / 3, bb.Width(), bb.Height() / 3));
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin() + 2 * bb.Height() / 3, bb.Width(), bb.Height() / 3));
        m_weights.push_back(1.f);
        m_weights.push_back(-2.f);
        m_weights.push_back(1.f);
        m_factor = 255 * 2.f / 3;
        break;
    }

    case 4: {
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width() / 2, bb.Height() / 2));
        m_rects.push_back(FloatRect(bb.XMin() + bb.Width() / 2, bb.YMin() + bb.Height() / 2, bb.Width() / 2, bb.Height() / 2));
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin() + bb.Height() / 2, bb.Width() / 2, bb.Height() / 2));
        m_rects.push_back(FloatRect(bb.XMin() + bb.Width() / 2, bb.YMin(), bb.Width() / 2, bb.Height() / 2));
        m_weights.push_back(1.f);
        m_weights.push_back(1.f);
        m_weights.push_back(-1.f);
        m_weights.push_back(-1.f);
        m_factor = 255 * 1.f / 2;
        break;
    }

    case 5: {
        m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width(), bb.Height()));
        m_rects.push_back(FloatRect(bb.XMin() + bb.Width() / 4, bb.YMin() + bb.Height() / 4, bb.Width() / 2, bb.Height() / 2));
        m_weights.push_back(1.f);
        m_weights.push_back(-4.f);
        m_factor = 255 * 3.f / 4;
        break;
    }
    }
}