예제 #1
0
//-------------------------------TLFEmptyAverageNNPredictor----------------------
TLFDblVector* TLFEmptyAverageNNPredictor::Features(ILFDetectEngine* engine, TLFRect* rect, int id)
{
	if (engine == NULL || rect == NULL)
		return NULL;
	ILFObjectDetector* d = engine->GetDetector(0);
	if (d == NULL)
		return NULL;
	TLFImage* img = d->GetImage();
	if (img == NULL)
		return NULL;
	TLFDblVector* data = new TLFDblVector(id);
	double w = (double)rect->Width() / 8;
	double h = (double)rect->Height() /8;
	double s = w*h;
	for (int y = 0; y < 8; y++)
	{
		int yy = (int)floor(rect->Top() + y*w + 0.5);
		for (int x = 0; x < 8 ; x++)
		{
			int xx = (int)floor(rect->Left() + x*w + 0.5);
			double value = img->CalcLnSum(xx, yy, (int)w, (int)h)/s;
			data->AddValue(value);
		}
	}
	return data;
}
예제 #2
0
TLFRect* TLFIntegralImagePredictor::Predict(ILFDetectEngine* engine)
{
	TLFFGEngine* e = dynamic_cast<TLFFGEngine*>(engine);
	if (e == NULL)
		return NULL;
	if (m_pPredicted != NULL)
	{
		delete m_pPredicted;
		m_pPredicted = NULL;
	}
	TLFImage* fg = e->GetForegroundImage();
	double max_s = 0;
	double value;
	double overlap;
	double s;
	int idx = -1;
	for (int i = 0; i < m_scanner->GetFragmentsCount(); i++)
	{
		awpRect rect = m_scanner->GetFragmentRect(i);
		s  = (rect.right - rect.left)*(rect.bottom - rect.top);

		overlap = m_rect.RectOverlap(rect);
		if (overlap > 0.5)
		{
			value = pow(1.1,overlap)*fg->CalcLnSum(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top) /s;
			if (value > max_s)
			{
				max_s = value;
				idx = i;
			}
		}
	}
	if (idx < 0)
	{
		m_pPredicted = NULL;
		return NULL;
	}
	else
	{
		TLFRect* r_result = new TLFRect();
		r_result->SetRect(m_scanner->GetFragmentRect(idx));
		awpRect rr = r_result->GetRect();
		//awpFillRect(e->GetForeground(), &rr, 0, 0);
		m_pPredicted = r_result;
		m_rect.SetRect(r_result->GetRect());
		return r_result;
	}
}
예제 #3
0
TLFDescriptor* TLFAverageNNTracker::Features(ILFDetectEngine* engine, TLFRect* rect, int id)
{
	if (engine == NULL || rect == NULL)
		return NULL;
	TSCObjectDetector* d = dynamic_cast<TSCObjectDetector*>(engine->GetDetector(0));
	if (d == NULL)
		return NULL;
	TLFImage* img = d->GetImage();
	if (img == NULL || img->GetImage() == NULL)
		return NULL;

	//
	int idx = d->GetStagesCount() - 1;
	TLFObjectList* stages = d->GetStrongs();

	TCSStrong* s = dynamic_cast<TCSStrong*>(stages->Get(idx));
	if (s == NULL)
		return NULL;
	double* data = (double*)malloc(s->GetCount()*sizeof(double));
	int width = rect->Width();
	double scale_coef = (double)width / (double)d->GetBaseWidth();
	TLFRect fragment;

	for (int i = 0; i < s->GetCount(); i++)
	{
		ILFWeak  * weak = s->GetWeak(i);
		if (weak != NULL)
		{
			TCSSensor* sensor = dynamic_cast<TCSSensor*>(weak->Fetaure());
			awpRect Fragment = sensor->GetRect();

			fragment.SetRect(Fragment);
			fragment.Scale(scale_coef);
			fragment.Shift(rect->Left(), rect->Top());

			Fragment = fragment.GetRect();
			double s = fragment.Width()*fragment.Height();
			double value = img->CalcLnSum(Fragment.left, Fragment.top, fragment.Width(), fragment.Height());
			value /= s;
			data[i] = value;

		}
	}
	TLFDescriptor* dscr = new TLFDescriptor(s->GetCount(), id, data);
	free(data);
	return dscr;
}
예제 #4
0
TLFDblVector* TLFAverageNNPredictor::Features(ILFDetectEngine* engine, TLFRect* rect, int id)
{
	if (engine == NULL || rect == NULL)
		return NULL;
	ILFObjectDetector* d = engine->GetDetector(0);
	if (d == NULL)
		return NULL;
	TLFImage* img = d->GetImage();
	img->GetIntegralImage();
	if (img == NULL || img->GetImage() == NULL)
		return NULL;

	//
	int idx = d->GetStagesCount() - 1;
	TLFObjectList* stages = d->GetStrongs();

	ILFStrong* s = dynamic_cast<TCSStrong*>(stages->Get(idx));
	if (s == NULL)
		return NULL;
	int width = rect->Width();
	double scale_coef = (double)width / (double)d->GetBaseWidth();
	TLFRect fragment;
	TLFDblVector* data = new TLFDblVector(id);
	for (int i = 0; i < s->GetCount(); i++)
	{
		ILFWeak  * weak = s->GetWeak(i);
		if (weak != NULL)
		{
			TCSSensor* sensor = dynamic_cast<TCSSensor*>(weak->Fetaure());
			awpRect Fragment = sensor->GetRect();

			fragment.SetRect(Fragment);
			fragment.Scale(scale_coef);
			fragment.Shift(rect->Left(), rect->Top());

			Fragment = fragment.GetRect();
			double s = fragment.Width()*fragment.Height();
			double value = img->CalcLnSum(Fragment.left, Fragment.top, fragment.Width(), fragment.Height());
			value /= s;
			data->AddValue(value);
		}
	}
	return data;
}