Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

feature extraction and matching multiple images within a for loop

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 );
    img_keypoints_save.push_back(img_keypoints);
    namedWindow("win%d" , CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
    imshow("Keypoints", img_keypoints );
    waitKey(1000);
}

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