Issue while doing simple Template based feature detection

asked 2013-02-12 06:11:40 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Thank you reading me,

In my dev setup, I'm using Android + OpenCV, where Android layer(Java) calls C++ code via JNI layer. So all of this code is written and getting executed in C++ called via JNI.

Mat object = imread("Template.png", CV_LOAD_IMAGE_GRAYSCALE);  *// load template*

OrbFeatureDetector detector( 500 );
std::vector<KeyPoint> kp_object;
detector.detect( object, kp_object );

OrbDescriptorExtractor extractor;
Mat des_object;
extractor.compute( object, kp_object, des_object );

BFMatcher matcher(cv::NORM_HAMMING2);

Mat frame = cam; *// I've tested, so please assume cam holds correct value*
cvtColor(frame, frame, CV_RGB2GRAY);

detector.detect( image, kp_image );
extractor.compute( image, kp_image, des_image );

*// Few checks to make sure, inputs are correct*
assertCheck(des_object.type() == des_image.type()); *// returns true*
assertCheck(images.cols == object.cols); *// returns true*

**matcher.knnMatch(des_object, des_image, matches, 2); // gives following error:

cv::error()(4826): OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in void cv::batchDistance(cv::InputArray, cv::InputArray, cv::OutputArray, int, cv::OutputArray, int, int, cv::InputArray, int, bool), file /home/reports/ci/slave/opencv/modules/core/src/stat.cpp, line 1803

libc(4826): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 4880 (Thread-6390)

Further, I've tested same code on OSx machine and it works fine...so please help me to understand what's cooking wrong with Android. Someone also have asked this problem earlier: http://answers.opencv.org/question/4454/matching-causes-assertion-error-features2d/ but no replies, so I'm reposting it with a positive hope. :)

edit retag flag offensive close merge delete

Comments

Hi, have you figured it out by now? I have the same problem!

wowoo gravatar imagewowoo ( 2013-02-16 23:47:44 -0600 )edit

Sorry but I can't recall, what I fixed...but yeah, the issue was because both 'cam' & 'object' were different types of images...so you need to fix there types by first making empty Mat image and than copy data to that empty-mat.

This is hack, I discovered, so please don't follow this as righteous way of doing things. Update me, if you find any findings on your side. :)

Abhinav gravatar imageAbhinav ( 2013-02-26 02:42:36 -0600 )edit

Hi Abhinav, I am sorry to disturb you again. I am still working on this problem and it almost drove me crazy... Could you please show part of your code about how you deal with the Mat? Thank you so much. I am new in Android CV and I have been working on this for about a month....

wowoo gravatar imagewowoo ( 2013-03-02 23:50:29 -0600 )edit