Ask Your Question

vinllen's profile - activity

2018-12-02 17:08:02 -0600 received badge  Notable Question (source)
2018-01-12 01:57:20 -0600 received badge  Popular Question (source)
2016-02-13 08:26:05 -0600 commented question opencv 3.1 drawKeypoints throw errors

Thanks berak, i made a stupid mistake that the image not exist in the current directory. But the errors throwd by opencv is not accurate enough

2016-02-13 08:01:52 -0600 commented question opencv 3.1 drawKeypoints throw errors

It looks like the the error occured at drawKeypoints(img_1, keypoints_1, out0); and drawMatches(img_1,keypoints_1,img_2,keypoints_2,matches,img_matches); when i cut the imwrite and imshow

2016-02-13 07:46:28 -0600 commented question opencv 3.1 drawKeypoints throw errors

Hi, berak, it's really my code. To be honest, it's my first time to run SIFT in opencv, i have tried several ways to run SIFT but always failed. So sad :(

2016-02-13 06:27:47 -0600 asked a question opencv 3.1 drawKeypoints throw errors

I use the follow code to run SIFT in opencv3.1:

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>
#include <opencv2/xfeatures2d.hpp>

#include <vector>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{        
    //cv::initModule_nonfree();
    //initModule_features2d();
    Mat img_1 = imread("11.bmp", 1);
    Mat img_2 = imread("22.bmp", 1);

    cv::Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();

    //-- Step 1: Detect the keypoints:
    std::vector<KeyPoint> keypoints_1, keypoints_2;    
    f2d->detect( img_1, keypoints_1 );
    f2d->detect( img_2, keypoints_2 );

    //-- Step 2: Calculate descriptors (feature vectors)    
    Mat descriptors_1, descriptors_2;    
    f2d->compute( img_1, keypoints_1, descriptors_1 );
    f2d->compute( img_2, keypoints_2, descriptors_2 );

    Mat out0;
    drawKeypoints(img_1, keypoints_1, out0);
    imshow("KeyPoint0.jpg", out0);
    imwrite("KeyPoint0", out0);

    //-- Step 3: Matching descriptor vectors using BFMatcher :
    BFMatcher matcher;
    std::vector< DMatch > matches;
    matcher.match( descriptors_1, descriptors_2, matches );

    /*
    Mat img_matches;
    drawMatches(img_1,keypoints_1,img_2,keypoints_2,matches,img_matches);
    imshow("matches",img_matches);
    imwrite("matches.jpg",img_matches);
    */
    char c = ' ';
    while ((c = waitKey(0)) != 'q');  // Keep window there until user presses 'q' to quit.

    return 0;

}

But the code drawKeypoints and drawMatches will throw an error:

OpenCV Error: Assertion failed (!outImage.empty()) in drawKeypoints, file /Users/vinllen/opt/opencv-3.1.0/modules/features2d/src/draw.cpp, line 113
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/vinllen/opt/opencv-3.1.0/modules/features2d/src/draw.cpp:113: error: (-215) !outImage.empty() in function drawKeypoints

Abort trap: 6
2016-02-09 00:58:50 -0600 asked a question cv2 'module' object has no attribute 'drawMatchesKnn'

My python version is 2.7, and i also install pyopencv, but the code cv2.drawMatches throws an error:

Traceback (most recent call last):
  File "x.py", line 26, in <module>
    img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2)
AttributeError: 'module' object has no attribute 'drawMatchesKnn'

I also install python-3.4, and when i switch python version to 3.4, and install opencv-3.1, it looks like cv2 module cannot work in my computer:

Python 3.4.0 (default, Feb  5 2016, 19:51:52)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'cv2'
>>>

Could anyone help me ? Thanks very much!