Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8548689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:33:09+00:00 2026-06-11T13:33:09+00:00

I am using opencv 2.4 and below is the code I am trying to

  • 0

I am using opencv 2.4 and below is the code I am trying to compile. I compile my code using this command

g++ -o "match" -ggdb `pkg-config --cflags opencv` match.cpp `pkg-config --libs opencv` 

Why I am getting this error:

match.cpp: In function ‘int main(int, const char**)’:
match.cpp:18:37: error: expected type-specifier before ‘SurfFeatureDetector’
match.cpp:18:37: error: conversion from ‘int*’ to non-scalar type ‘cv::Ptr<cv::FeatureDetector>’ requested
match.cpp:18:37: error: expected ‘,’ or ‘;’ before ‘SurfFeatureDetector’
match.cpp:22:2: error: ‘SurfDescriptorExtractor’ was not declared in this scope
match.cpp:22:26: error: expected ‘;’ before ‘extractor’
match.cpp:26:2: error: ‘extractor’ was not declared in this scope
match.cpp:29:2: error: ‘BruteForceMatcher’ was not declared in this scope
match.cpp:29:30: error: expected primary-expression before ‘>’ token
match.cpp:29:32: error: ‘matcher’ was not declared in this scope

I think there is some issue with the version of opencv I am using because the same code runs fine on 2.2 version but I am not sure what it is. HELP !!

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <string.h>
#include <iostream>

using namespace std;
using namespace cv;


int main(int argc, const char* argv[])
{
    cout << argv[1] << endl << argv[2] << endl;
    Mat img1 = imread(argv[1] , CV_LOAD_IMAGE_GRAYSCALE );
    Mat img2 = imread(argv[2] , CV_LOAD_IMAGE_GRAYSCALE );

    vector<KeyPoint> keypoints1;
    vector<KeyPoint> keypoints2;
    Ptr<FeatureDetector> feature = new SurfFeatureDetector(2500);
    feature->detect(img1,keypoints1);
    feature->detect(img2,keypoints2);

    SurfDescriptorExtractor extractor;

    Mat desc1 , desc2;

    extractor.compute(img1,keypoints1,desc1);
    extractor.compute(img2,keypoints2,desc2);

    BruteForceMatcher<L2<float> > matcher;

    vector<vector<DMatch> > matches1;
    vector<vector<DMatch> > matches2;
    vector<DMatch> symMatches;
    vector<DMatch> outMatches;

    matcher.knnMatch(desc1,desc2,matches1,2);
    matcher.knnMatch(desc2,desc1,matches2,2);

    int count_inliers = 0 , count_matches = 0;

    for(vector<vector<DMatch> >::const_iterator matIt1 = matches1.begin(); matIt1 != matches1.end(); ++matIt1){
        count_matches++;
        if(matIt1->size() < 2)
            continue;
        for(vector<vector<DMatch> >::const_iterator matIt2 = matches2.begin(); matIt2 != matches2.end(); ++matIt2){
            if(matIt2->size() < 2)
                continue;
            if((*matIt1)[0].queryIdx == (*matIt2)[0].trainIdx && (*matIt2)[0].queryIdx == (*matIt1)[0].trainIdx){
                count_inliers++;
                symMatches.push_back(DMatch((*matIt1)[0].queryIdx,(*matIt1)[0].trainIdx,(*matIt1)[0].distance));
                break;
            }
        }
    }

    vector<Point2f> points1, points2;

    for(vector<DMatch>::const_iterator it = symMatches.begin(); it!=symMatches.end(); ++it){
        float x = keypoints1[it->queryIdx].pt.x;
        float y = keypoints1[it->queryIdx].pt.y;
        points1.push_back(Point2f(x,y));

        x = keypoints2[it->trainIdx].pt.x;
        y = keypoints2[it->trainIdx].pt.y;
        points2.push_back(Point2f(x,y));
    }

    vector<uchar> inliers(points1.size(),0);

    Mat fundamental;
    fundamental = findFundamentalMat(Mat(points2),Mat(points1),inliers,CV_FM_RANSAC,2,0.8);

    vector<uchar>::const_iterator itIn = inliers.begin();
    vector<DMatch>::const_iterator itM = symMatches.begin();
    for(;itIn!=inliers.end();++itIn,++itM){
        if(*itIn){
            outMatches.push_back(*itM);
        }
    }
    cout << count_inliers << endl;
    cout << count_matches << endl;
    cout << (float) count_inliers/(float) count_matches << endl;

    float diff = (float) count_inliers/(float) count_matches;
//  if(diff > 0.30){
//      cout << "Similar Images " << endl << "-----------------" << endl;
//      exit(1);
//  }

//  vector<uchar> inliers(points1.size(),0);
    Mat homography = findHomography(Mat(points2),Mat(points1),inliers,CV_RANSAC,1);

    vector<Point2f>::const_iterator itPts = points1.begin();
//  vector<uchar>::const_iterator itIn = inliers.begin();
/*  while(itPts != points1.end()){
        if(*itIn)
            circle(img1,*itPts,3,Scalar(255,255,255),2);
        ++itPts;
        ++itIn;
    }
    itPts = points2.begin();
    itIn = inliers.begin();
    while(itPts != points2.end()){
        if(*itIn)
            circle(img2,*itPts,3,Scalar(255,255,255),2);
        ++itPts;
        ++itIn;
    }
*/

    Mat result;

    warpPerspective(img2,result,homography,Size(2*img2.cols,img2.rows));
    Mat half(result,Rect(0,0,img1.cols,img1.rows));

    img1.copyTo(half);





    // Add results to image and save.
    char name[1000];

//    strcpy(name,"./surf/surf");
//    strcat(name,argv[1]);

    cv::Mat output1;
    cv::Mat output2;
    cv::drawKeypoints(img1, keypoints1, output1);
    cv::drawKeypoints(img2, keypoints2, output2);
    cv::imwrite("./surf/img11.png", img1);
    cv::imwrite("./surf/img21.png", img2);
    cv::imwrite("./surf/img31.png", result);
    cv::imwrite("./surf/tt.png", result);
    cv::imwrite("./surf/img41.png", half);
    cv::imwrite("./surf/img51.png", output1);
    cv::imwrite("./surf/img61.png", output2);

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:33:10+00:00Added an answer on June 11, 2026 at 1:33 pm

    The BruteForceMatcher is now called

    cv::BFMatcher
    

    See the documentation.

    You can define a matcher like this:

    DescriptorMatcher* hammingMatcher = new BFMatcher(NORM_HAMMING,false);
    //or
    DescriptorMatcher* hammingMatcher = new BFMatcher(NORM_L2,false);
    

    EDIT

    Also in this sample code you can see how to use the old-version matcher by including the header

    #include "hammingseg.h"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using OpenCV v2.4.1 And this is the code I'm using #include opencv2/opencv.hpp #include
I'm trying to compile a small OpenCV program using Eclipse. I'm limited in library
I am trying to parallelize some Image Matching code written in OpenCV using TBB.
I wish to display image using c++ OpenCV code. Below are the code fragment:
I am trying to find the difference between 2 images using Opencv. The code
I'm trying to display an image using OpenCV. I have the following very basic
I'm trying to threshold red pixels in a video stream using OpenCV. I have
I'm making simple webcam program using OpenCV 2.3 and got stuck by the compile
I am porting some code that is using OpenCV just to fit an ellipse.
I am trying to do some image matching using OpenCV and am using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.