Пример #1
0
void GazeTracker::updateGaussianProcesses() {
	std::vector<double> xLabels;
	std::vector<double> yLabels;

	for (int i = 0; i < _calTargets.size(); i++) {
		xLabels.push_back(_calTargets[i].point.x);
		yLabels.push_back(_calTargets[i].point.y);
	}

	std::vector<Utils::SharedImage> images = getSubVector(_calTargets, &CalTarget::image);
	//std::cout << "INSIDE updateGPs" << std::endl;
	//std::cout << "labels size: " << xLabels.size();
	//std::cout << "images size: " << images.size();
	_gaussianProcessX.reset(new ImProcess(images, xLabels, covarianceFunction, 0.01));
	_gaussianProcessY.reset(new ImProcess(images, yLabels, covarianceFunction, 0.01));
	_targets.reset(new Targets(getSubVector(_calTargets, &CalTarget::point)));
}
Пример #2
0
void GazeTracker::updateGaussianProcessesLeft() {
	std::vector<double> xLabels;
	std::vector<double> yLabels;

	for (int i = 0; i < _calTargetsLeft.size(); i++) {
		xLabels.push_back(_calTargetsLeft[i].point.x);
		yLabels.push_back(_calTargetsLeft[i].point.y);
	}

	std::vector<Utils::SharedImage> images = getSubVector(_calTargetsLeft, &CalTarget::image);

	_gaussianProcessXLeft.reset(new ImProcess(images, xLabels, covarianceFunction, 0.01));
	_gaussianProcessYLeft.reset(new ImProcess(images, yLabels, covarianceFunction, 0.01));
	//_targetsLeft.reset(new Targets(getSubVector(_calTargetsLeft, &CalTarget::point)));
}
Пример #3
0
void GazeTracker::printTrainingErrors() {
	int numMonitors = Gdk::Screen::get_default()->get_n_monitors();
	Gdk::Rectangle monitorGeometry;
	Glib::RefPtr<Gdk::Screen> screen = Gdk::Display::get_default()->get_default_screen();

	//return;

	// Geometry of main monitorGazeTracker.cpp:233:136: error: expected ‘;’ before string constant

	screen->get_monitor_geometry(numMonitors - 1, monitorGeometry);

	std::vector<Point> points = getSubVector(_calTargets, &CalTarget::point);

	//std::cout << "PRINTING TRAINING ESTIMATIONS: " << std::endl;
	//for (int i = 0; i < 15; i++) {
	//	int imageIndex = 0;
	//	int j = 0;
	//	while (j < inputCount && points[i].x == allOutputCoords[j][0] && points[i].y == allOutputCoords[j][1]) {
	//		std::cout << "X, Y: '" << _gaussianProcessX->getmean(SharedImage(allImages[j], &ignore)) << ", " << _gaussianProcessY->getmean(SharedImage(allImages[j], &ignore)) << "' and '" << _gaussianProcessXLeft->getmean(SharedImage(allImagesLeft[j], &ignore)) << ", " << _gaussianProcessYLeft->getmean(SharedImage(allImagesLeft[j], &ignore)) << "' " << std::endl;
	//		image_index++;
	//		j++;
	//	}
	//}
}
Пример #4
0
	std::vector<T> unifRandSelectionVec(const std::vector<T> & vec, uint32_t amt,
			bool withReplacement) {
		std::vector<T> ret;
		std::vector<uint32_t> rSel;
		if (withReplacement) {
			rSel = unifRandVector<uint32_t>(0, vec.size(), amt);
		} else {
			if (amt > vec.size()) {
				std::stringstream ss;
				ss << "Error in unifRandSelectionVec, requesting"
						" more than is in vec but said without replacement" << std::endl;
				throw std::runtime_error { ss.str() };
			} else {
				std::vector<uint32_t> rSelPos(vec.size());
				iota<uint32_t>(rSelPos, 0);
				shuffle(rSelPos, mtGen_);
				rSel = getSubVector(rSelPos, 0, amt);
			}
		}
		for (const auto & pos : rSel) {
			ret.emplace_back(vec[pos]);
		}
		return ret;
	}
Пример #5
0
void GazeTracker::calculateTrainingErrors() {
	int numMonitors = Gdk::Screen::get_default()->get_n_monitors();
	Gdk::Rectangle monitorGeometry;
	Glib::RefPtr<Gdk::Screen> screen = Gdk::Display::get_default()->get_default_screen();

	// Geometry of main monitor
	screen->get_monitor_geometry(numMonitors - 1, monitorGeometry);

	std::vector<Point> points = getSubVector(_calTargets, &CalTarget::point);

	//std::cout << "Input count: " << _inputCount;
	//std::cout << ", Target size: " << _calTargets.size() << std::endl;

	for (int i = 0; i < _calTargets.size(); i++) {
		double xTotal = 0;
		double yTotal = 0;
		double sampleCount = 0;

		//std::cout << points[i].x << ", " << points[i].y << " x " << allOutputCoords[j][0] << ", " << allOutputCoords[j][1] << std::endl;

		int j = 0;
		while (j < _inputCount && points[i].x == allOutputCoords[j][0] && points[i].y == allOutputCoords[j][1]) {
			double xEstimate = (_gaussianProcessX->getmean(Utils::SharedImage(allImages[j], &ignore)) + _gaussianProcessXLeft->getmean(Utils::SharedImage(allImagesLeft[j], &ignore))) / 2;
			double yEstimate = (_gaussianProcessY->getmean(Utils::SharedImage(allImages[j], &ignore)) + _gaussianProcessYLeft->getmean(Utils::SharedImage(allImagesLeft[j], &ignore))) / 2;

			//std::cout << "i, j = (" << i << ", " << j << "), est: " << xEstimate << "(" << _gaussianProcessX->getmean(SharedImage(allImages[j], &ignore)) << "," << _gaussianProcessXLeft->getmean(SharedImage(allImagesLeft[j], &ignore)) << ")" << ", " << yEstimate << "(" << _gaussianProcessY->getmean(SharedImage(allImages[j], &ignore)) << "," << _gaussianProcessYLeft->getmean(SharedImage(allImagesLeft[j], &ignore)) << ")" << std::endl;

			xTotal += xEstimate;
			yTotal += yEstimate;
			sampleCount++;
			j++;
		}

		xTotal /= sampleCount;
		yTotal /= sampleCount;

		*outputFile << "TARGET: (" << _calTargets[i].point.x << "\t, " << _calTargets[i].point.y << "\t),\tESTIMATE: (" << xTotal << "\t, " << yTotal << ")" << std::endl;
		//std::cout << "TARGET: (" << _calTargets[i].point.x << "\t, " << _calTargets[i].point.y << "\t),\tESTIMATE: (" << xTotal << "\t, " << yTotal << "),\tDIFF: (" << fabs(_calTargets[i].point.x- x_total) << "\t, " << fabs(_calTargets[i].point.y - y_total) << ")" << std::endl;

		// Calibration error removal
		_xv[i][0] = xTotal;		// Source
		_xv[i][1] = yTotal;

		// Targets
		_fvX[i] = _calTargets[i].point.x;
		_fvY[i] = _calTargets[i].point.y;
		_sigv[i] = 0;

		int targetId = getTargetId(Point(xTotal, yTotal));

		if (targetId != i) {
			std::cout << "Target id is not the expected one!! (Expected: "<< i << ", Current: " << targetId << ")" << std::endl;
		}
	}

	// Add the corners of the monitor as 4 extra data points. This helps the correction for points that are near the edge of monitor
	_xv[_calTargets.size()][0] = monitorGeometry.get_x();
	_xv[_calTargets.size()][1] = monitorGeometry.get_y();
	_fvX[_calTargets.size()] = monitorGeometry.get_x()-40;
	_fvY[_calTargets.size()] = monitorGeometry.get_y()-40;

	_xv[_calTargets.size()+1][0] = monitorGeometry.get_x() + monitorGeometry.get_width();
	_xv[_calTargets.size()+1][1] = monitorGeometry.get_y();
	_fvX[_calTargets.size()+1] = monitorGeometry.get_x() + monitorGeometry.get_width() + 40;
	_fvY[_calTargets.size()+1] = monitorGeometry.get_y() - 40;

	_xv[_calTargets.size()+2][0] = monitorGeometry.get_x() + monitorGeometry.get_width();
	_xv[_calTargets.size()+2][1] = monitorGeometry.get_y() + monitorGeometry.get_height();
	_fvX[_calTargets.size()+2] = monitorGeometry.get_x() + monitorGeometry.get_width() + 40;
	_fvY[_calTargets.size()+2] = monitorGeometry.get_y() + monitorGeometry.get_height() + 40;

	_xv[_calTargets.size()+3][0] = monitorGeometry.get_x();
	_xv[_calTargets.size()+3][1] = monitorGeometry.get_y() + monitorGeometry.get_height();
	_fvX[_calTargets.size()+3] = monitorGeometry.get_x() - 40;
	_fvY[_calTargets.size()+3] = monitorGeometry.get_y() + monitorGeometry.get_height() + 40;

	int pointCount = _calTargets.size() + 4;
	int N = pointCount;
	N = binomialInv(N, 2) - 1;

	// Find the best beta and gamma parameters for interpolation
	mirBetaGamma(1, 2, pointCount, (double *)_xv, _fvX, _sigv, 0, NULL, NULL, NULL, N, 2, 50.0, &_betaX, &_gammaX);
	mirBetaGamma(1, 2, pointCount, (double *)_xv, _fvY, _sigv, 0, NULL, NULL, NULL, N, 2, 50.0, &_betaY, &_gammaY);

	*outputFile << std::endl << std::endl;
	std::cout << std::endl << std::endl;

	outputFile->flush();

	std::cout << "ERROR CALCULATION FINISHED. BETA = " << _betaX << ", " << _betaY << ", GAMMA IS " << _gammaX << ", " << _gammaY << std::endl;
	for (int i = 0; i < pointCount; i++) {
		std::cout << _xv[i][0] << ", " << _xv[i][1] << std::endl;
	}

	//checkErrorCorrection();
}