Esempio n. 1
0
/**
 * Reads the recorded gesture data from the files and brings it in the format ready for training. 
 */
vector<FeatureSet> GestureManagement::readData() {
	// read all takes for each gesture
	vector<FeatureSet> sets;
	sets.clear();
	for (int i=0; i<=NUMBER_OF_ROGGEN_SENSORS; ++i) {
		FeatureSet s;
		s.clear();
		sets.push_back(s);
	}
	for (int f=0; f<config->getStrings("classification names").size(); ++f) {
		if (config->getInt("verbosity") > 1) {
			cout << "Training classification name number " << f << endl;
		}
		// cout << "Gesture: " << f << endl;
		vector<float> varianceSums; // compute sums for every sensor within a gesture
		varianceSums.clear();
		for (int i=0; i<NUMBER_OF_ROGGEN_SENSORS; i++) {
			varianceSums.push_back(0); // inital value
		}
		int sizeSum = 0;
		// for (int i=1; i<=NUMBER_OF_TAKES; i++) {  // for each of the 3 takes
		for (int i=1; i<=config->getInt("number of takes"); ++i) {
			// cout << "Take " << i << endl;
			string fname = XML_SUBDIRECTORY+config->getStrings("classification names").at(f)+Helper::toString(i)+".xml";
			// cout << "Filename: " << fname << endl;
			if (!Helper::fileExists(fname.c_str())) {
				cerr << fname << " not yet recorded!" << endl;
				cerr << "No training possible" << endl;
				sets.clear();
				return sets;
			} else {
				vector<vector<int> > rd = convert(XmlFileHandling::readIntData(fname));
				for (int sensor=0; sensor<NUMBER_OF_ROGGEN_SENSORS; ++sensor) { // for every sensor
					// cout << "Sensor " << sensor << endl;
					buffers.at(sensor)->clear();
					buffers.at(sensor)->setUnlimited();
					buffers.at(sensor)->put(RoggenBuffer::filter(0,config->getInts("IDs").at(sensor),rd));
					maxGestureLength = Helper::getMax(maxGestureLength,buffers.at(sensor)->size());
					FeatureSample fs;
					fs.out = f;
					fs.in.clear();
					fs.in = extractFeatures(sensor);
					sets.at(sensor).push_back(fs);
					int size = buffers.at(sensor)->size();
					sizeSum += size;
				} // for every sensor
			} // if fileexists
		} // for every take
		sizeSum /= config->getInt("number of takes") * NUMBER_OF_ROGGEN_SENSORS; // compute average size of one gesture
		sizes.push_back(sizeSum); // store sizes (averages)
	}	// for every gesture
	return sets;
}
void DatabaseSubsystem::getAvailableFeatures(Session& session,
    const map<int, int>& clObjMap, FeatureSet& featureSet)
{
    int ddType;
    string featureName;
    double featureParam1, featureParam2, featureParam3;

    featureSet.clear();

    ostringstream clObjIDs;
    for (map<int, int>::const_iterator itr = clObjMap.begin();
         itr != clObjMap.end(); ++itr)
    {
        if (itr != clObjMap.begin()) {
            clObjIDs << ",";
        }
        clObjIDs << itr->first;
    }

    Statement stmt = (session <<
        "SELECT DISTINCT "
        "  data_descriptor.type, data_feature.feature_name, "
        "  data_feature.feature_param1, data_feature.feature_param2, "
        "  data_feature.feature_param3  "
        "FROM data_feature INNER JOIN data_descriptor "
        "ON (data_feature.descr_id = data_descriptor.descr_id) "
        "WHERE data_descriptor.descr_id IN ("
        "  SELECT descr_id FROM classification_object_data WHERE object_id IN ("
        << clObjIDs.str()
        << "))",
        range(0, 1),
        into(ddType), into(featureName), into(featureParam1), 
        into(featureParam2), into(featureParam3));

    while (!stmt.done()) {
        if (stmt.execute() == 1) {
            featureSet.add(FeatureDescriptor(featureName,
                (DataDescriptor::Type) ddType, featureParam1, featureParam2, 
                featureParam3));
        }
    }
}