int main(int argc, char * argv[]) {

	io::DataIO data(io::StanfordEval);
	std::string dir;
	if (argc > 1) {
		std::string dir = argv[1];
		std::cout << "Saving to " << dir << std::endl;

		// Creating directory structure
		boost::filesystem::path training_data_path_head(dir);
		boost::filesystem::create_directory(dir);

		std::ofstream ofile((dir + "/labels.txt").c_str());

		annotate(ofile, data);

		ofile.close();
	} else {
		std::cout << "Extracting training data" << std::endl;
		data.extract_data();
		std::cout << "Done" << std::endl;
	}

	return 0;
}
Exemplo n.º 2
0
void DataIOStanford::extract_parts() {
	/* initialize random seed: */
	srand (time(NULL));

	// Creating directory structure
	const std::string kTrainingDataPathHead = kPath + "/training";

	boost::filesystem::path training_data_path_head(kTrainingDataPathHead);
	boost::filesystem::create_directory(training_data_path_head);

	std::ofstream data((kTrainingDataPathHead + "/data.txt").c_str());

	if (!data.is_open()) {
		std::cerr << "Unable to create training data files!" << std::endl;
	}

	int head_idx, hand_idx, leg_idx;
	head_idx = hand_idx = leg_idx = 1;
	cv::Mat frame, frame_dummy;
	while (read_next_frame(frame_dummy, frame)) {
		//if(!) {  stanford_eval::next_file(); };
		stanford_eval::Frame f = stanford_eval::frame;

//		cv::Mat frame(cv::Size(f.C, f.R), CV_32F);
//
//		for (int i = 0; i < f.N; ++i) {
//			frame.at<float>(i % f.R, i/f.R) = -(static_cast<float>(f.points[i][2]) + 2.f);
//		}
//
//		cv::normalize(frame, frame, 0, 1.f, cv::NORM_MINMAX);
		std::vector<int> positive_centres;

		// Head
		if (f.markers[3].cond > 0 && f.markers[1].cond > 0) {
			extract_positive_part(frame, data,
									f.markers[3].x, f.markers[3].y + 0.1,
									f.markers[1].x, f.markers[1].y + 0.1,
									classifier::HEAD, true);

			extract_positive_part(frame, data,
									f.markers[3].x, f.markers[3].y + 0.1,
									f.markers[3].x, f.markers[1].y + 0.1,
									classifier::HEAD, true);

			positive_centres.push_back(to_x(f.markers[1].x));
			positive_centres.push_back(to_y(f.markers[1].y + 0.1));
			positive_centres.push_back(to_x(f.markers[3].x));
			positive_centres.push_back(to_y(f.markers[3].y + 0.1));
		}

		// Left hand
		if (f.markers[28].cond > 0 && f.markers[24].cond > 0) {
			extract_positive_part(frame, data,
									f.markers[28].x, f.markers[28].y,
									f.markers[24].x, f.markers[24].y,
									classifier::LEFT_HAND, true);

			positive_centres.push_back(to_x(f.markers[24].x));
			positive_centres.push_back(to_y(f.markers[24].y));
		}

		// Right hand
		if (f.markers[19].cond > 0 && f.markers[16].cond > 0) {
			extract_positive_part(frame, data,
									f.markers[19].x, f.markers[19].y,
									f.markers[16].x, f.markers[16].y,
									classifier::RIGHT_HAND, true);

			positive_centres.push_back(to_x(f.markers[16].x));
			positive_centres.push_back(to_y(f.markers[16].y));
		}

		// Left foot
		if (f.markers[35].cond > 0 && f.markers[37].cond > 0) {
			extract_positive_part(frame, data,
									f.markers[37].x, f.markers[37].y - 0.2,
									f.markers[35].x, f.markers[35].y - 0.2,
									classifier::LEFT_FOOT, true);

			positive_centres.push_back(to_x(f.markers[35].x));
			positive_centres.push_back(to_y(f.markers[35].y - 0.2));
		}

		// Right foot
		if (f.markers[43].cond > 0 && f.markers[41].cond > 0) {
			extract_positive_part(frame, data,
									f.markers[41].x, f.markers[41].y - 0.2,
									f.markers[43].x, f.markers[43].y - 0.2,
									classifier::RIGHT_FOOT, true);

			positive_centres.push_back(to_x(f.markers[43].x));
			positive_centres.push_back(to_y(f.markers[43].y - 0.2));
		}

		for (int j = 0; j < 12; j++) {
			extract_negative_part(frame, data, positive_centres);
		}
	}
}