Ask Your Question
0

Detection of planar objects

asked 2015-05-21 01:30:36 -0600

shruti.arya gravatar image

updated 2015-05-21 01:39:18 -0600

I am trying to do feature extraction using C++ API. For this, I am using http://docs.opencv.org/ref/master/dd/... as reference.

The code I have written is :

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/calib3d.hpp>
using namespace cv;

#include <iostream>
#include <stdio.h>
using namespace std;

Mat img; Mat templ;
int main(int, char** argv)
{
    templ = cv::imread("C:/Users/.../workspace/FeatureDetectionCPP/src/temp.jpg", IMREAD_GRAYSCALE);
    img = cv::imread("C:/Users/.../workspace/FeatureDetectionCPP/src/image.jpg", IMREAD_GRAYSCALE);

    if(templ.empty())
    {
        cout<<"Empty template";
    }

    if(img.empty())
    {
        cout<<"Empty image";
    }

    Ptr<Feature2D> surf = SURF::create();
    vector<KeyPoint> keypoints1;
    Mat descriptors1;
    surf->detectAndCompute(img, Mat(), keypoints1, descriptors1);

    Ptr<Feature2D> surf1 = SURF::create();
    vector<KeyPoint> keypoints2;
    Mat descriptors2;
    surf1->detectAndCompute(templ, Mat(), keypoints2, descriptors2);

    // matching descriptors
    BruteForceMatcher<L2<float> > matcher;
    vector<DMatch> matches;
    matcher.match(descriptors1, descriptors2, matches);

    // drawing the results
    namedWindow("matches", 1);
    Mat img_matches;
    drawMatches(templ, keypoints1, img, keypoints2, matches, img_matches);
    imshow("matches", img_matches);
    waitKey(0);

    return 0;
}

During compilation, I got this:

error: 'SURF' has not been declared Ptr<feature2d> surf1 = SURF::create();

error: 'BruteForceMatcher' was not declared in this scope BruteForceMatcher<l2<float> > matcher;

error: expected primary-expression before '>' token BruteForceMatcher<l2<float> > matcher;

error: 'matcher' was not declared in this scope BruteForceMatcher<l2<float> > matcher;

On searching, I found that #include "opencv2/nonfree/features2d.hpp" should be added. However, I don't have any folder nonfree or misc in the opencv2 folder. I am using opencv 3.0.0. And, have compiled it using mingw.

Can anyone help in telling as if why this error is appearing. And, how can I resolve it.

I have looked at http://answers.opencv.org/question/52...

but don't understand that on donloading zip file, where shall I place it. How shall it be compiled to add to the existing build of opencv.

@berak , can you help me wih this ?

edit retag flag offensive close merge delete

Comments

1

to use SURF or SIFT in 3.0, you need the opencv_contrib repo, also they are in another namespace, try to add:

using namespace cv::xfeatures2d;

there's also plan B: use another keypointdetector/featureextractor pair, e.g. AKAZE instead of SURF should do pretty well.

berak gravatar imageberak ( 2015-05-21 01:48:26 -0600 )edit
1
  • "...where shall I place it" - make an opencv_contrib folder next to your opencv one, put it there ?
  • "How shall it be compiled " - add the path to the opencv_contrib/modules to your main cmake options like cmake -DOPENCV_EXTRA_MODULES_PATH=/your/opencv_contrib/modules . again, please see the readme here.
berak gravatar imageberak ( 2015-05-21 02:30:37 -0600 )edit

I am using cmake-gui. I just entered path for contrib/modules. On executing mingw32-make install, the issues coming are :

  1. warning: ignoring #pragma warning [-Wunknown-pragmas]

    pragma warning( disable : 4267 )

  2. In file included from C:/opencv1/opencv_contrib-master/opencv_contrib-master/mod ules/line_descriptor/src/precomp.hpp:72:0, from C:\opencv1\build\x86\mingw\modules\line_descriptor\opencv_ line_descriptor_pch_dephelp.cxx:1: C:/opencv1/opencv_contrib-master/opencv_contrib-master/modules/line_descriptor/s rc/bitops.hpp:49:21: fatal error: intrin.h: No such file or directory

    include <intrin.h>

How to get rid of them ?

shruti.arya gravatar imageshruti.arya ( 2015-05-21 03:33:58 -0600 )edit

oh, the line_descriptor again. did not compile for me, either ;(

you might disable it by ticking BUILD_opencv_line_descriptor=OFF in cmake-gui.

there might be more modules, which do not compile (saliency ?), just disable them in the same way.

berak gravatar imageberak ( 2015-05-21 03:38:27 -0600 )edit

Okay, so now on compilation, 3 errors are still left : error: 'BruteForceMatcher' was not declared in this scope BruteForceMatcher<l2<float> > matcher;

error: expected primary-expression before '>' token BruteForceMatcher<l2<float> > matcher;

error: 'matcher' was not declared in this scope BruteForceMatcher<l2<float> > matcher;

What shall I do for BruteForceMatcher ?

shruti.arya gravatar imageshruti.arya ( 2015-05-21 04:50:14 -0600 )edit

BFMatcher

your original code seems rather outdated. see e.g. here for a recent demo using AKAZE

berak gravatar imageberak ( 2015-05-21 04:57:19 -0600 )edit
1

@berak, And by the way...saliency compiled w/o giving errors :) However, datasets threw an error.

shruti.arya gravatar imageshruti.arya ( 2015-05-21 04:59:12 -0600 )edit

This time, when I am using AKAZE, issues I am facing are : 1. It's dealing with images of 32-bit depth & for others, its giving error : Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in gemm, file C:\opencv\opencv-master\opencv-master\modules\core\src\matmul.cpp, line 893 2. Even when I crop a part of image, it isn't finding any matches :/

I am using the image - http://nullcandy.com/wp-content/uploa...

shruti.arya gravatar imageshruti.arya ( 2015-05-21 05:32:58 -0600 )edit

And BFMatcher gives the error : Assertion failed ((type == CV_8U && dtype == CV_32S) || dtype == CV_32F) in batchDistance, file C:\opencv\opencv-master\opencv-master\modules\core\src\stat.cpp, line 3662 for images not having 32-bit depth.

Even for some images, it works. And for some, it gives this error.

Does it require any special kind of image ? Or there is something else...

I have also tried with images graf1.png and graf3.png. But, the error is same...

Can you please help me with this @berak ?

shruti.arya gravatar imageshruti.arya ( 2015-05-21 05:51:50 -0600 )edit
1

Since I have faced a lot of problems in setting up OpenCV for Windows 7, I ended up writing a blog describing the process. You may find it at http://techieshruti.blogspot.in/2015/... and help others too. Thanks, Shruti

shruti.arya gravatar imageshruti.arya ( 2015-05-22 03:29:28 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-05-25 04:47:02 -0600

shruti.arya gravatar image

Hey @berak, Can you tell me if opencv requires some particular kind of image ?

I cannot find the reason behind the errors :-

  1. Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2))
  2. Assertion failed ((type == CV_8U && dtype == CV_32S) || dtype == CV_32F)

Please help me with this too...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-05-21 01:30:36 -0600

Seen: 945 times

Last updated: May 25 '15