0

我已将一组图像的路径写入文本文件。我试图在 opencv 中连续读取图像。然后我需要从每个图像中找到一些特征。但是我的方法不会从文件中提到的路径中读取图像。这是我的代码:

#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include <vector>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{        
   FILE * fp;
   char * line = NULL;
   size_t len = 0;
   ssize_t read;

   fp = fopen("hmv.txt", "r");
   if (fp == NULL)
      exit(EXIT_FAILURE);

   while ((read = getline(&line, &len, fp)) != -1) 
   {
      printf("%s",line);
      Mat image = imread(line);
      Ptr<FeatureDetector> featureDetector = FeatureDetector::create("SIFT");
      vector<KeyPoint> keypoints;
      featureDetector->detect(image, keypoints);
      Ptr<DescriptorExtractor> featureExtractor = DescriptorExtractor::create("SIFT");
      Mat descriptors;
      featureExtractor->compute(image, keypoints, descriptors);

      //Mat  MyMat=cvCreateMat(descriptors.rows,descriptors.cols,CV_64FC1);
      Mat output;
      reduce(descriptors,output,0,CV_REDUCE_SUM,CV_64FC1);
      string filename="feature.txt";
      FILE *file;
      file=fopen(filename,"wb");
      fwrite(&output,
   }
   return 0;
}

求大神帮忙看看是什么问题?

4

1 回答 1

0

从 getline 手册页:

缓冲区以空值结尾并包括换行符(如果找到)。

所以,你在文件名中有一个换行符,imread 不会喜欢它......

于 2013-05-11T18:29:04.370 回答