Ask Your Question
0

feature extraction and matching multiple images within a for loop

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

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 );
    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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

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

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 );
container.push_back(keypoints);
edit flag offensive delete link more

Comments

1

Thank you so much

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

You are welcome

StevenPuttemans gravatar imageStevenPuttemans ( 2017-10-12 07:39:08 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 2,030 times

Last updated: Oct 12 '17