Ask Your Question

feature extraction and matching multiple images within a for loop

asked 2017-10-12 06:35:43 -0500

AbdulWahab gravatar image

I am extracting features of multiple images using surf features. The problem is this that I want to save keypoints which I do not understant how to do it. The reason to save this keypoints to use it in matching process. Below I provide the code

#include < stdio.h >  
#include < opencv2\opencv.hpp >  
#include < opencv2\stitching\stitcher.hpp >

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/legacy/legacy.hpp>

using namespace std;
using namespace cv;
/* @function main */
int main( int argc, char** argv )
    vector< Mat > vImg;
    int minHessian = 400;
    std::vector<KeyPoint> keypoints;
    Mat img_keypoints;
        vector< Mat > img_keypoints_save;

    vImg.push_back( imread("E:/A wahab/Masters Work/Camera Array/sample images/stitching_img/S1.jpg") );
    vImg.push_back( imread("E:/A wahab/Masters Work/Camera Array/sample images/stitching_img/S2.jpg") );
    vImg.push_back( imread("E:/A wahab/Masters Work/Camera Array/sample images/stitching_img/S3.jpg") );
    vImg.push_back( imread("E:/A wahab/Masters Work/Camera Array/sample images/stitching_img/S4.jpg") );
    for (int i=0; i<4; i++)
        if (vImg[i].empty()) //check whether the image is loaded or not
            cout << "Error : Image cannot be loaded..!!" << endl;
            system("pause"); //wait for a key press
            return -1;
   // step 1 : Extract features using surf features
    SurfFeatureDetector detector( minHessian );
    detector.detect( vImg[i], keypoints );
    drawKeypoints(vImg[i], keypoints, img_keypoints, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
    namedWindow("win%d" , CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
    imshow("Keypoints", img_keypoints );

To compute descriptors I need keypoints, thats why I want to save it. So please tell me how to solve this problem. I am really thankful to you

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-10-12 07:07:02 -0500

Since keypoints are stored in a vector<KeyPoint>, you can simply make a vector of those elements and push back the data each iteration.

// outside loop
vector< vector<KeyPoint> > container;

// in the loop you do
vector<KeyPoint> keypoints;
detector.detect( vImg[i], keypoints );
edit flag offensive delete link more



Thank you so much

AbdulWahab gravatar imageAbdulWahab ( 2017-10-12 07:26:48 -0500 )edit

You are welcome

StevenPuttemans gravatar imageStevenPuttemans ( 2017-10-12 07:39:08 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-10-12 06:35:43 -0500

Seen: 54 times

Last updated: Oct 12