示例#1
0
rect_t MT::track(const unsigned char *gray)
{	
	number_coarse = number_MLK = number_iteration = 0;
	if (log != NULL) {
		(*log) << "roll = " << roll * 90.0f / PI_2 << endl;
		(*log) << "yaw = " << yaw * 90.0f / PI_2 << endl;
		(*log) << "pitch = " << pitch * 90.0f / PI_2 << endl;
	}
	feature.process(gray, roll);

	//the first attempt
	Warp w = warp;
	if (log != NULL)
		(*log) << "track at " << w.t.transpose() << " " << window(w.t) << endl;
	w = fine_test(w);
	float e = evaluate(w);
	if (e > fast_threshold) {
		//use coarse searching
		++number_coarse;
		Warp w2 = warp;
		w2.sett(fast_test(warp));
		if (log != NULL)
			(*log) << "search at " << w2.t.transpose() << " " << window(w2.t) << endl;
		w2 = fine_test(w2);
		float e2 = evaluate(w2);
		if (e2 < e) {
			w = w2;
			e = e2;
		}
	}
	update(w, e);

	return window(w.t);
}
示例#2
0
rect_t MT::retrack(const unsigned char *gray, const vector<rect_t> &detections)
{	
	number_coarse = number_MLK = number_iteration = 0;
	if (log != NULL) {
		(*log) << "roll = " << roll * 90.0f / PI_2 << endl;
		(*log) << "yaw = " << yaw * 90.0f / PI_2 << endl;
		(*log) << "pitch = " << pitch * 90.0f / PI_2 << endl;
	}
	feature.process(gray, 0.0f);

	//the first attempt
	Warp w = warp;
	w.setr(Vector3f(0.0f, 0.0f, 0.0f));
	if (log != NULL)
		(*log) << "track at " << w.t.transpose() << " " << window(w.t) << endl;
	w = fine_test(w);
	float e = evaluate(w);

	//use coarse searching
	Warp w2 = warp;
	w2.setr(Vector3f(0.0f, 0.0f, 0.0f));
	w2.sett(fast_test(warp));
	if (log != NULL)
		(*log) << "search at " << w2.t.transpose() << " " << window(w2.t) << endl;
	w2 = fine_test(w2);
	float e2 = evaluate(w2);
	if (e2 < e) {
		w = w2;
		e = e2;
	}

	//use re-detection
	for (auto d : detections) {
		Warp w3 = warp;
		w3.setr(Vector3f(0.0f, 0.0f, 0.0f));
		w3.sett(locate(d));
		if (log != NULL)
			(*log) << "detect at " << w3.t.transpose() << " " << window(w3.t) << endl;
		w3 = fine_test(w3);
		float e3 = evaluate(w3);
		if (e3 < e) {
			w = w3;
			e = e3;
		}
	}
	update(w, e);

	return window(w.t);
}
示例#3
0
Rect2f MT::track(Mat img, const vector<Rect2f> &detections)
{
	if (log != NULL) {
		(*log) << "roll = " << roll * 90.0f / PI_2 << endl;
		(*log) << "yaw = " << yaw * 90.0f / PI_2 << endl;
		(*log) << "pitch = " << pitch * 90.0f / PI_2 << endl;
	}	
	if (!detections.empty())
		roll = 0.0f;
	feature.process(img, roll);
	vector<Point3f> candidates;
	candidates.push_back(warp.t);
	candidates.push_back(fast_test(warp));
	for (auto d : detections)
		candidates.push_back(locate(d));
	
	Warp best_warp(image_size);
	float best_error = 1.0f;
	for (auto& t : candidates) {
		if (log != NULL)
			(*log) << "candidate " << t << " " << window(t) << endl;
		Warp w(image_size);
		if (detections.empty())
			w.set(warp.r);
		w.set(t);
		w = fine_test(w);
		float e = evaluate(w);
		if (log != NULL) {
			(*log) << "final translation = " << w.t << " " << window(w.t) << endl;
			(*log) << "final rotation = " << w.r << endl;
			(*log) << "final error = " << e << endl;
		}
		if (e < best_error) {
			best_warp = w;
			best_error = e;
		}
	}
	candidates.clear();

	error = best_error;
	if (error < threshold_error) {
		count = 0;
		warp = best_warp;
		warp.euler(roll, yaw, pitch);
		fine_train(warp);
	}
	else {
		++count;
		warp.t = best_warp.t * (warp.t.z / best_warp.t.z);
	}
	fast_train(warp);

	return window(best_warp.t);
}