good matcher for AR

asked 2015-03-16 12:24:29 -0600

Hello i have a lot of issue here with opencv 3

i follow this actually: http://docs.opencv.org/trunk/doc/tuto...

but i modify like this to try create a AR, my goal is intruduced to unreal engine 4, so i have a far way in front, i actually track things inside UE but is not AR yet

this is my code in simple vs2013 but i have a serius issue trying to match descriptors from webcam this is with BRISK based on oficial BRISK opencv 3 example, but i try with FAST + ORB and on my see is the better and faster option, anywhy i try with SURF but is very slow.

my crash always happen with this: cv::Ptr<cv::descriptormatcher> matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");

matcher.match(objectDescriptors,sceneDescriptors,matches); BOOM all crash!

but as i say in the official BRISK example works comparising 2 images, anyone can explain me why in webcam crash?

is another matcher i can use? how flannMatcher with binarydescriptors?

my code:

#include <opencv\cv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/opencv.hpp>
#include <vector>    

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

int main()
{
Mat objectImg = imread("C:/pattern3.png", cv::IMREAD_GRAYSCALE);
Mat sceneImg;
Mat frame;
VideoCapture cap(1);

if (!objectImg.data || !cap.isOpened())
{
    printf(" No image data \n ");
    return -1337;
}

resize(objectImg, objectImg, Size(512, 512));

std::vector<cv::KeyPoint> objectKeypoints;

cv::Mat objectDescriptors;
cv::Mat sceneDescriptors;

//////////////////////////////////////
// Object: keypoint descriptors computing

cv::Ptr<cv::BRISK> ptrBrisk = cv::BRISK::create();
ptrBrisk->detect(objectImg, objectKeypoints);
ptrBrisk->compute(objectImg, objectKeypoints, objectDescriptors);
cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");

while (1)
{
    cap >> frame;
    cvtColor(frame, sceneImg, CV_BGR2GRAY);
    std::vector<cv::KeyPoint> sceneKeypoints;
    ptrBrisk->detect(sceneImg, sceneKeypoints);
    ptrBrisk->compute(sceneImg, sceneKeypoints, sceneDescriptors);
    std::vector< DMatch > matches;

    matcher->match(objectDescriptors, sceneDescriptors, matches); // BOOM DESCTRUCTION CRASH

    double max_dist = 0; double min_dist = 100;

    //-- Quick calculation of max and min distances between keypoints
    for (int i = 0; i < objectDescriptors.rows; i++)
    {
        double dist = matches[i].distance;
        if (dist < min_dist) min_dist = dist;
        if (dist > max_dist) max_dist = dist;
    }

    std::vector<cv::DMatch> good_matches;

    for (int i = 0; i < objectDescriptors.rows; i++)
    {
        if (matches[i].distance <= max(2 * min_dist, 0.02)) {
            good_matches.push_back(matches[i]);
        }

    }
    Mat allmatchs;
    drawMatches(objectImg, objectKeypoints, sceneImg, sceneKeypoints, good_matches, allmatchs, Scalar::all(-1), Scalar::all(-1), vector<char>(), 0);
    imshow("Matchs", allmatchs);

    imshow("AR", allmatchs);
    waitKey(33);
}

return 0;

}

edit retag flag offensive close merge delete