Implement image comparison using openCV in android [closed]

asked 2013-08-01 07:41:26 -0500

newBee gravatar image

Hi, I had downloaded the openCV for android from here, and was able to compile and run the OpenCV Sample - face-detection, And in the

private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this)

I have added these code

 FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
                    DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);;
                    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);

                    //first image
                    Mat img1 = Highgui.imread("/mnt/sdcard/gta1.jpg");
                    Mat descriptors1 = new Mat();
                    MatOfKeyPoint keypoints1 = new MatOfKeyPoint();


                    detector.detect(img1, keypoints1);
                    descriptor.compute(img1, keypoints1, descriptors1);

                    //second image
                    Mat img2 = Highgui.imread("/mnt/sdcard/gta1.jpg");
                    Mat descriptors2 = new Mat();
                    MatOfKeyPoint keypoints2 = new MatOfKeyPoint();

                    detector.detect(img2, keypoints2);
                    descriptor.compute(img2, keypoints2, descriptors2);

                    //matcher should include 2 different image's descriptors
                     MatOfDMatch  matches = new MatOfDMatch();             
                     matcher.match(descriptors1,descriptors2,matches);
                     Log.d(TAG, "size " + matches.size());

                     //feature and connection colors
                     Scalar RED = new Scalar(255,0,0);
                     Scalar GREEN = new Scalar(0,255,0);
                     //output image
                     Mat outputImg = new Mat();
                     MatOfByte drawnMatches = new MatOfByte();
                     //this will draw all matches, works fine
                     Features2d.drawMatches(img1, keypoints1, img2, keypoints2, matches, 
                     outputImg, GREEN, RED,  drawnMatches, Features2d.NOT_DRAW_SINGLE_POINTS);

                    Bitmap imageMatched = Bitmap.createBitmap(outputImg.cols(), outputImg.rows(), Bitmap.Config.RGB_565);//need to save bitmap
                    Utils.matToBitmap(outputImg, imageMatched);
                    Log.d(TAG, "Match " + imageMatched);

after the line of code

mNativeDetector = new DetectionBasedTracker(mCascadeFile.getAbsolutePath(), 0);

But i get exception of

java.lang.IllegalArgumentException: width and height must be > 0

and if i hard-code the height and width insread of using outputImg.cols(), outputImg.rows() i get a cv::error of

OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97

What i want is, I have two images and i need to check if these images match or not, because later part of my project i want to integrate it with camera so that the camera image is compared to the local stored image and I get a result . I dont want to use SURF or SIFT because they are patented ? Can anyone Please HELP!!!!!!

edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by SR
close date 2013-08-01 08:45:07.422281