我已将一组图像的路径写入文本文件中......我正试图在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;
}
请帮忙,有什么缺陷?
答案 0 :(得分:0)
:
缓冲区以空值终止,并包含换行符(如果找到)。
所以,你的文件名中有换行符,imread会不喜欢它...