void CreateTestSet(int numTestFile, string categoryName = "")
{
	string pathRaw = "Data/Raws/" + categoryName + "/";
	vector<string> _listRawName = ReadFileList(pathRaw.c_str());

	string pathTest = "Data/Test_images/" + categoryName + "/";
	if (CreateDirectoryA(pathTest.c_str() , NULL) || ERROR_ALREADY_EXISTS == GetLastError())
	{
		int numFilePerVideo = numTestFile / _listRawName.size();
		for (int i = 0; i < _listRawName.size(); i++)
		{
			string rawVideoPath = pathRaw + _listRawName[i];
			string videoName = _listRawName[i].substr(0, _listRawName[i].size() - 4);
			string testVideoPath = pathTest + videoName;

			cout << "Extract test frame from video " << videoName << endl;
			if (CreateDirectoryA(testVideoPath.c_str(), NULL) || ERROR_ALREADY_EXISTS == GetLastError())
			{
				RandomizeFrameTest(rawVideoPath, categoryName, videoName, numFilePerVideo);
			}
			else
			{
				cout << "Cannot find and create " << testVideoPath << " directory" << endl;
			}
		}
	}
	else
	{
		cout << "Something is wrong..." << endl;
	}
}
Пример #2
0
// create data package --------------------------------------------------------
//
PRIVATE
int CreatePackage( const char* packname, const char *listname )
{
	ASSERT( packname != NULL );
	ASSERT( listname != NULL );

	#define MAX_DATA_FILES 4096

	list_item_s *listitems = (list_item_s *) ALLOCMEM( MAX_DATA_FILES * sizeof( list_item_s ) );
	if ( listitems == NULL ) {
		return FALSE;
	}

	int numitems = ReadFileList( listname, listitems, MAX_DATA_FILES );
	if ( numitems == -1 ) {
		FREEMEM( listitems );
		MakepackError();
	}

	if ( !WritePackageFile( packname, listitems, numitems ) ) {
		FREEMEM( listitems );
		MakepackError();
	}

	FREEMEM( listitems );
	return TRUE;
}
vector<string> SetupModel(string categoryName, vector<Mat> &trainData, vector<Mat> &trainLabels, 
						  vector<float> &videoFPS, int database_type)
{
	cout << "Loading training data..." << endl << endl;

	//Get data stored in database
	string path;
	if (database_type == 1)
		path = "Data/Training_Data/" + categoryName + "/BOW/";
	else
		path = "Data/Training_Data/" + categoryName + "/MPEG7/";

	vector<string> _listTrainingData = ReadFileList(path);

	for (int i = 0; i < (int)_listTrainingData.size(); i++)
	{
		string pathData = path + _listTrainingData[i];
		Mat trainingData, trainingLabel;
		float fps;
		LoadDataFromFile(pathData, trainingData, trainingLabel, fps);

		trainData.push_back(trainingData);
		trainLabels.push_back(trainingLabel);
		videoFPS.push_back(fps);
	}

	return _listTrainingData;
}
Пример #4
0
Interface::Interface(int argc, const char* argv[]){
        
    if (argc>1){
    
        const char* modestr = argv[1];
        if (strcmp(modestr,"Eval")){
            mode = 1;
        } else {
            mode = 0;
        }
        filelist = argv[2];
        varlist = argv[3];
        setlist = argv[4];
    } else {
        
        mode=0;
        
        std::string pPath = getenv ("HOME");
        std::string basename = pPath+"/Dropbox/CubeClassifier";

        
        filelist=basename+"/DefaultFileList.txt";
        varlist=basename+"/DefaultVarList.txt";
        setlist=basename+"/DefaultSettings.txt";

    }

        
    ReadFileList();
    ReadSettingsList();
    ReadVariableList();
    
}
void ExtractAndSaveKeyFrame(string videoName)
{
	//Extract key frames from a list of shots
	string filepath = "Data/Video shots/" + videoName + "/";
	string destPath = "Data/Key frames/" + videoName + "/";
	vector<string> listFileName = ReadFileList(filepath);

	int j = 0;
	int i = 0;
	int n = (int)listFileName.size();
	int numFrame = 0;
	int count = 0;

//	#pragma omp parallel shared(n) private(i,j,numFrame,count)
	{
//		#pragma omp for
		for (j = 0; j < n; j++)
		{
			string filename = filepath + listFileName[j];

			VideoCapture cap(filename);

			//vector<int> keyFrames = KeyframeMomentExtractor(cap);
			vector<int> keyFrames = KeyframeCurvatureExtractor(cap);

			//RemoveRedundantKeyframes(cap, keyFrames);

			count = 0;
			numFrame = (int)keyFrames.size();

			for (i = 0; i < numFrame; i++)
			{
				if (keyFrames[i] != -1)
				{
					string resultPath = destPath;

					string name = listFileName[j].substr(0, listFileName[j].size() - 4);
					resultPath.append(name);
					resultPath.append("_");

					char *buffer = new char[255];
					resultPath.append(_itoa(keyFrames[i], buffer, 10));
					resultPath.append(".jpg");
					delete buffer;

					Mat frame = ExtractFrameFromVideo(cap, keyFrames[i]);
					if (!frame.empty())
						imwrite(resultPath, frame);
					else
						cout << "Cannot extract keyframe " << i << endl;

					count++;
				}
			}
			cout << "There're " << count << " key frames in " << listFileName[j] << endl;
			cout << endl;
		}
	}
}
Пример #6
0
void DoFileList(const char *filelist, const char *environment)
{
	// read config files

	if (!ReadFileList(filelist)) {
		printf("No Files to test!\r\n");
		return;
	}

	ReadGlobalEnvironment(environment);

	DoThreads();
}
Пример #7
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	char szPath[MAX_PATH];
	CmyStringArray astrFileList;

	GetModuleFilePath (szPath, sizeof (szPath));

	QuitModule ("スクラップブックオンライン ランチャー");
	ReadFileList (astrFileList);
	CopyFileList (astrFileList);
	ExecuteLauncher ();

	return 0;
}
Пример #8
0
InstData *ReadOldInstData(HANDLE fin, char *product, char *installdir)
{
  InstData *idata;

  idata = bmalloc(sizeof(InstData));

  idata->product = product;
  idata->installdir = installdir;
  idata->startmenudir = read_line0(fin);

  idata->instfiles = ReadFileList(fin);
  idata->extrafiles = ReadFileList(fin);
  idata->keepfiles = NULL;

  idata->startmenu = ReadLinkList(fin);
  idata->desktop = ReadLinkList(fin);

  idata->service = ReadServiceDetails(fin);

  idata->flags = ReadInstFlags(fin);

  return idata;
}
Пример #9
0
/**************************************************************************************************
函数用途:main函数,程序入口;读取txt列表,并分割选中的文件
输入参数:无
返回参数:无
*/
void main(void)
{
	FILE *fpSrc,*fpDec;
	unsigned char* buff;
	int i,j,select,FileNum = 0,singleFileSize;
	long size;
	char fileName_Suffix[100],fileName[100],fileNameTmp[100];

	Show();//显示一些无关紧要的信息
	FileNum = ReadFileList();//读取txt文件列表
	PrintFileList(FileNum);//打印txt文件列表

	printf("\n如果列表显示无误,请输入需要分割的文本文档(txt文件)前的序号: ");  //菜单显示
	select = ReScanf(1,FileNum);//输入序号

	/* 下面五行内容,用于分别去除字符串中最后一个回车和后缀名 */
	strcpy(fileName_Suffix,List[select].Name);
	j = strlen(fileName_Suffix)-1;
	fileName_Suffix[j] = '\0';//字符用单引号,去掉最后一个回车
	strcpy(fileName,fileName_Suffix);
	fileName[j-4] = '\0';//将文件名去除后缀

	printf("\n你选择的是:“%s”,",fileName_Suffix);
	if( ( fpSrc = fopen(fileName_Suffix,"r" ) ) == 0 )//判断是否有文件
	{
		printf("\n\n对不起,文件木有找到或打不开啊!程序退出!\n");
		system("pause");//任意键继续
		exit(1);
	}

	fseek(fpSrc, 0L,SEEK_END);//将指针移动到末位
	size = ftell(fpSrc);//计算文件长度,目前指针的位置既是文件的长度
	if( size < 10000)
	{
		printf("这个文件长度为:“%ld”字节。\n连10000字节都不到,分个毛线啊,自己手动分割去。程序退出!\n",size);
		system("pause");//任意键继续
		exit(0);
	}
	printf("这个文件长度为:%ld字节。\n期望平均分割成几个文件?请输入小于99的数值:",size);
	select = ReScanf(2,99);//输入分割成几段的数值

	singleFileSize = size/select;//计算每个小文件大小
	printf("\n下面将会把“%s”分割成%d个大小为:%d字节(%dKB)的文件。\n\n",fileName_Suffix,select,singleFileSize,singleFileSize/1024);
	system("pause");//任意键继续

	fseek(fpSrc, 0L,SEEK_SET);//将指针移动到首位
	for(i = 1 ; i<=select ; i++ )
	{
		buff = (unsigned char*)malloc(singleFileSize);//动态申请单个小文件大小所需的内存
		sprintf(fileNameTmp,"%s - 第%02d段.txt",fileName,i);//文件名拼接
		fread(buff,singleFileSize,1,fpSrc);//从fpSrc中读取数据到buff
		fpDec = fopen(fileNameTmp,"w");//新建小文件
		fwrite(buff,singleFileSize,1,fpDec);//将buff数据写入到fpDec
		free(buff);//释放内存
		fclose(fpDec);//关闭目标文件
		printf("\n“%s”已成功生成!",fileNameTmp);
	}
	fclose(fpSrc);//关闭源文件

	printf("\n分割完毕!程序退出!");
	system("pause");//任意键继续
	exit(0);
}
Пример #10
0
int main(int argc, char **argv) {
    char *list_in;
    char *file_out;
    double ratio;

    if (argc != 3 && argc != 4) {
        printf("Usage: %s <list.txt> <outfile> [window_radius]\n", argv[0]);
        return EXIT_FAILURE;
    }

    list_in = argv[1];
    ratio = 0.6;
    file_out = argv[2];

    int window_radius = -1;
    if (argc == 4) {
        window_radius = atoi(argv[3]);
    }

    clock_t start = clock();

    /* Read the list of files */
    std::vector<std::string> key_files;
    if (ReadFileList(list_in, key_files) != 0) return EXIT_FAILURE;

    FILE *f;
    if ((f = fopen(file_out, "w")) == NULL) {
        printf("Could not open %s for writing.\n", file_out);
        return EXIT_FAILURE;
    }

    int num_images = (int) key_files.size();

    std::vector<unsigned char*> keys(num_images);
    std::vector<int> num_keys(num_images);

    /* Read all keys */
    for (int i = 0; i < num_images; i++) {
        keys[i] = NULL;
        num_keys[i] = ReadKeyFile(key_files[i].c_str(), &keys[i]);
    }

    clock_t end = clock();
    printf("[KeyMatchFull] Reading keys took %0.3fs\n", 
           (end - start) / ((double) CLOCKS_PER_SEC));

    for (int i = 0; i < num_images; i++) {
        if (num_keys[i] == 0)
            continue;

        printf("[KeyMatchFull] Matching to image %d\n", i);

        start = clock();

        /* Create a tree from the keys */
        ANNkd_tree *tree = CreateSearchTree(num_keys[i], keys[i]);

        /* Compute the start index */
        int start_idx = 0;
        if (window_radius > 0) 
            start_idx = std::max(i - window_radius, 0);

        for (int j = start_idx; j < i; j++) {
            if (num_keys[j] == 0)
                continue;

            /* Compute likely matches between two sets of keypoints */
            std::vector<KeypointMatch> matches = 
                MatchKeys(num_keys[j], keys[j], tree, ratio);

            int num_matches = (int) matches.size();

            if (num_matches >= 16) {
                /* Write the pair */
                fprintf(f, "%d %d\n", j, i);

                /* Write the number of matches */
                fprintf(f, "%d\n", (int) matches.size());

                for (int i = 0; i < num_matches; i++) {
                    fprintf(f, "%d %d\n", 
                            matches[i].m_idx1, matches[i].m_idx2);
                }
            }
        }

        end = clock();
        printf("[KeyMatchFull] Matching took %0.3fs\n", 
               (end - start) / ((double) CLOCKS_PER_SEC));
        fflush(stdout);

        delete tree;
    }

    /* Free keypoints */
    for (int i = 0; i < num_images; i++) {
        if (keys[i] != NULL)
            delete [] keys[i];
    }

    fclose(f);
    return EXIT_SUCCESS;
}
void TestShotRetrieval(string categoryName, int database_type, int num_retrieve)
{
	string resultFile = "Data/Result_" + categoryName + "_ShotRetrieval.txt";
	ofstream out(resultFile);

	//Load database
	vector<Mat> trainData, trainLabels;
	vector<float> videoFPS;
	vector<string> _listDataName = SetupModel(categoryName, trainData, trainLabels, videoFPS, database_type);
	
	//Load dictionary for BOW model
	if (database_type == 1)
		bowDE.setVocabulary(LoadBOWDictionaryFromFile("Data/Training_Data/" + categoryName + "_BOW_dictionary.xml"));

	//Get list of test frames
	string pathTest = "Data/Test_images/" + categoryName + "/";
	vector<string> _listTestClass = ReadFileList(pathTest);


	vector<vector<float>> _listWeightScore;
	for (int index = 0; index < _listTestClass.size(); index++)
	{
		vector<float> avgWeigthScore;
		avgWeigthScore.resize(num_retrieve);

		string pathClass = pathTest + _listTestClass[index] + "/";
		vector<string> _listTestImage = ReadFileList(pathClass);
		for (int i = 0; i < _listTestImage.size(); i++)
		{
			string testpath = pathClass + _listTestImage[i];
			Mat testImage = imread(testpath);

			//---Extract feature based on database_type
			Mat queryFeature;
			if (database_type == 1)
				queryFeature = ExtractBOWFeature(bowDE, detector, testImage);
			else
				queryFeature = ExtractMPEGFeature(testImage);

			//For each test image, retrieve list of shot and check if there's any correct shot in candidate list
			int trueShotID = IdentifyShotFromKeyFrame(_listTestImage[i]);

			cout << "Retrieve shot in video " << GetName(_listDataName[index]) << " using " << _listTestImage[i] << endl;
			vector<int> _listShotID = RetrieveShot(videoFPS[index], trainData[index], trainLabels[index], queryFeature);

			//Calculate precision and recall
			for (int numRetrieve = 0; numRetrieve < num_retrieve; numRetrieve++)
			{
				float weightScore = ShotRetrievalPerformance(_listShotID, trueShotID, numRetrieve+1);
				avgWeigthScore[numRetrieve] += weightScore;
			}

			cout << endl;
		}

		for (int i = 0; i < num_retrieve; i++)
		{
			avgWeigthScore[i] /= _listTestImage.size();
		}

		_listWeightScore.push_back(avgWeigthScore);
	}

	vector<float> avgWeightScorePerNumRetrieval;
	avgWeightScorePerNumRetrieval.resize(num_retrieve);
	for (int i = 0; i < _listWeightScore.size(); i++)
	{
		float avgPrecision = 0.0f;
		out << _listTestClass[i].c_str() << endl;
		for (int j = 0; j < num_retrieve; j++)
		{
			out << j+1 << ". " << _listWeightScore[i][j] << endl;
			avgWeightScorePerNumRetrieval[j] += _listWeightScore[i][j];
		}
		out << endl;
	}

	out << endl << "Average weight score: " << endl;
	for (int i = 0; i < num_retrieve; i++)
	{ 
		avgWeightScorePerNumRetrieval[i] /= (float)_listWeightScore.size();
		out << i + 1 << ". " << avgWeightScorePerNumRetrieval[i] << endl;
	}

	out.close();
}
void TestVideoRetrieval(string categoryName, int database_type)
{
	//Load database
	vector<Mat> trainData, trainLabels;
	vector<float> videoFPS;
	vector<string> _listDataName = SetupModel(categoryName, trainData, trainLabels, videoFPS, database_type);

	//Load dictionary for BOW model
	if (database_type == 1)
		bowDE.setVocabulary(LoadBOWDictionaryFromFile("Data/Training_Data/" + categoryName + "_BOW_dictionary.xml"));

	float avgReciprocalRank = 0.0f;
	float avgPrecision = 0.0f;
	float avgRecall = 0.0f;
	string pathTest = "Data/Test_images/" + categoryName + "/";
	vector<string> _listTestClass = ReadFileList(pathTest);

	int countTotal = 0;
	for (int index = 0; index < _listTestClass.size(); index++)
	{
		float avgClassRR = 0.0f;

		string pathClass = pathTest + _listTestClass[index] + "/";
		vector<string> _listTestImage = ReadFileList(pathClass);
		for (int i = 0; i < _listTestImage.size(); i++)
		{
			string testpath = pathClass + _listTestImage[i];
			Mat testImage = imread(testpath);

			//---Extract feature based on database_type
			Mat queryFeature;
			if (database_type == 1)
				queryFeature = ExtractBOWFeature(bowDE, detector, testImage);
			else
				queryFeature = ExtractMPEGFeature(testImage);

			//For each test image, retrieve list of video and check if there's any correct video in candidate list
			int countMatch = 0;
			int countMatchRank = 0;
			int countRetrievedMatch = 0;
			int numMatchRetrieve = 3;
			vector<int> predictLabels = RetrieveVideo(_listTestClass.size(), queryFeature, trainData);

			//Calculate precision and recall from retrieved list
			if (predictLabels.size() > 0)
			{
				cout << _listTestImage[i] << " in video " << _listTestClass[index] << " can belong to: " << endl;
				for (int j = 0; j < predictLabels.size(); j++)
				{
					int predictLabel = predictLabels[j];
					cout << _listTestClass[predictLabel] << endl;

					countMatchRank++;
					if (predictLabel == index)
					{
						if (j < numMatchRetrieve)
						{
							countRetrievedMatch++;
						}
						countMatch++;
						break;
					}
				}
				cout << endl;
			}
			else
			{
				cout << "No video match the query image" << endl << endl;
			}

			float reciprocalrank = 0.0f;
			float precision = 0.0f;
			float recall = 0.0f;
			if (predictLabels.size() > 0)
			{
				reciprocalrank = (float)countMatch / (float)countMatchRank;
				precision = (float)countRetrievedMatch / (float)numMatchRetrieve;
				recall = countRetrievedMatch;
			}
				
			avgClassRR += reciprocalrank;
			avgPrecision += precision;
			avgRecall += recall;
		}

		countTotal += _listTestImage.size();

		avgReciprocalRank += avgClassRR;
	}

	avgReciprocalRank = avgReciprocalRank / countTotal * 100.0f;
	avgPrecision = avgPrecision / countTotal * 100.0f;
	avgRecall = avgRecall / countTotal * 100.0f;

	cout << "MAP = " << avgReciprocalRank << endl;
	cout << "Average Precision = " << avgPrecision << endl;
	cout << "Average Recall = " << avgRecall << endl;
}