static void read_imgList(const string& filename, vector& images) {
std::ifstream file(filename.c_str(), ifstream::in);
if (!file) {
string error_message = "No valid input file was given, please check the given filename.";
CV_Error(CV_StsBadArg, error_message);
}
string line;
while (getline(file, line)) {
images.push_back(imread(line, 0));
}
}
int main(int argc, char** argv)
{
if (argc != 3)
{
readme(); return -1;
}
string imgList = string(argv[1]);
vector images;
try {
read_imgList(imgList, images);
}
catch (cv::Exception& e) {
cerr << "Error opening file \"" << imgList << "\". Reason: " << e.msg << endl;
exit(1);
}
Mat img_2 = imread(imgList[1], CV_LOAD_IMAGE_GRAYSCALE);
if (!img_2.data)
{ std::cout << " --(!) Error reading images " << std::endl; return -1;
}
//-- Step 1: detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
SurfDescriptorExtractor extractor;
//-- Test img, detect the keypoints
std::vector keypoints_2;
detector.detect(img_2, keypoints_2);
//-- Step 2: calculate descriptors (feature vectors)
Mat descriptors_2;
extractor.compute(img_2, keypoints_2, descriptors_2);
double mindist = 100;
int matchInd = -1;
for (unsigned int i = 0; i < images.size(); i++)
{
Mat img_1;
img_1 = images[i];
if (!img_1.data)
{
std::cout << " --(!) Error reading images " << std::endl; return -1;
}
↧