int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	HMODULE hModule = ::GetModuleHandle(NULL);

	if (hModule != NULL)
	{
		// initialize MFC and print and error on failure
		if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
		{
			// TODO: change error code to suit your needs
			_tprintf(_T("Fatal Error: MFC initialization failed\n"));
			nRetCode = 1;
		}
		else
		{
			// TODO: code your application's behavior here.
			try {
				// Number of clusters for building BOW vocabulary from SURF features
				if(argc == 4) {
					Mat out, aligned, face, flandmark, in = imread(argv[2]);
					Rect face_rect;
					if(!FindFace(in,face_rect,face)) 
						cout << "Error couldn't find face";
					else {
						PerformanceTimer time;
						resize(face,face,Size(86,86));
						/*time.Start();
						AlignFace(face,aligned);
						time.Stop();
						cout << "My Alignment: " << time.Duration() << endl;*/
						
						time.Start();
						int ret1 = AlignFLandmark(in,face_rect,flandmark);
						time.Stop();
						cout << "Landmark Alignment: " << time.Duration() << endl;
						
						/*time.Start();
						AlignImage(flandmark,out);
						time.Stop();
						cout << "LFW Alignment: " << time.Duration() << endl;
						imshow("out",out);*/

						imshow("in",in);
						imshow("face",face);
						//imshow("features",aligned);
						imshow("landmarks",flandmark);
						waitKey();
						categorizer c(argv[1]);
						if(atoi(argv[3]) == 0) {
							c.train_classifiers();
							c.save_vocab();
						} else {
							cout << "loading vocab" << endl;
							c.load_vocab();
							cout << "vocab loaded" << endl;
						}
						cout << "fast method" << endl;
						c.categorize(flandmark);
						/*cout << "slow method" << endl;
						c.categorize(out);*/
					}
				} else {
					categorizer c(argv[1]);
					if(atoi(argv[2]) == 0) {
						c.train_classifiers();
						c.save_vocab();
					} else {
						cout << "loading vocab" << endl;
						c.load_vocab();
						cout << "vocab loaded" << endl;
					}

					c.categorize();
				}
			} catch(cv::Exception &e) {
				printf("Error: %s\n", e.what());
			}
			cin.get();
		}
	}
	else
	{
		// TODO: change error code to suit your needs
		_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
		nRetCode = 1;
	}

	return nRetCode;
}