3

我正在尝试从文件夹中的图像列表中检测关键点,并将它们存储在使用 opencv 文件存储的文件中。如何使用文件存储将图像文件名本身作为每个图像的标签。我能够将文件名打印到控制台但不能在文件中。它给了我 opencv 错误:icvXMLWriteTag 中的错误参数。

我的图像文件名类似于 shot000_0001_0.jpg 等。

任何帮助都深表感谢。谢谢

#include "stdafx.h"
#include <opencv2\core\core.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\nonfree\features2d.hpp>
#include <tchar.h>
#include <io.h>
#include <iostream>
#include <fstream>

using namespace std;
using namespace cv;


int _tmain(int argc, _TCHAR* argv[])
{

    struct _finddata_t c_file;

    long hFile;


    char imageDirectory[] = "C:\\Users\\RadhaRani\\Documents\\visual studio 2013\\Projects\\Example_Match_SURF\\Example_Match_SURF\\test1";

    char imageFileType[] = "jpg";

    char fullImagePath[500];

    char buffer[500];

    char imageFileName[500];

    vector<KeyPoint> keypoints;

    FileStorage fs("Concept_multipleImages_png.xml", FileStorage::WRITE);


    sprintf(buffer, "%s\\*.%s", imageDirectory, imageFileType);
    hFile = _findfirst(buffer, &c_file);

    // Check to make sure that there are files in directory
    if (hFile == -1L)
    {
        printf("No %s files in current directory!\n", imageFileType);
    }
    else
    {
        // List all files in directory
        printf("Listing of files:\n");

        // Loop through all images of imageFileType
        do
        {
            // Show file name
            printf("Opening File: %s \n", c_file.name);

            //cout << c_file.name << endl;

            sprintf(fullImagePath, "%s\\%s", imageDirectory, c_file.name);




            Mat image = imread(fullImagePath);


            SurfFeatureDetector surf;


             surf.detect(image, keypoints);



            sprintf(imageFileName,"%s",  c_file.name);


            fs << imageFileName << keypoints;



            // keep finding files until no more found, i.e. until there is an error code
        } while (_findnext(hFile, &c_file) == 0);

        // Close file finder object
        _findclose(hFile);
    }


    fs.release();
    return 0;
}
4

0 回答 0