Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Hi. I managed to read an image from directory and compare it with number of images from txt file.How to convert it as reading number of images from txt file instead reading an image from directory

$
0
0
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; }

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>