2

I'm implement object tracking with features detect , and I got the following error:

12-19 20:59:16.943: E/cv::error()(31858): 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 12-19 20:59:16.943: E/org.opencv.android.Utils(31858): nMatToBitmap catched cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean) 12-19 20:59:16.943: E/CameraBridge(31858): Mat type: Mat [ 820*2672*CV_8UC3, isCont=true, isSubmat=false, nativeObj=0x55650380, dataAddr=0x5ec20010 ] 12-19 20:59:16.943: E/CameraBridge(31858): Bitmap type: 960*720 12-19 20:59:16.943: E/CameraBridge(31858): Utils.matToBitmap() throws an exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

and here is the code :

    public void onCameraViewStarted(int width, int height) {
    mRgba = new Mat();
    mGray = new Mat();
    mView = new Mat();
    mObject = new Mat();
}

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {    
    mRgba = inputFrame.rgba();

    switch (viewMode) {
    case VIEW_MODE_RGBA:

        return mRgba;

    case VIEW_MODE_FeatureDetect:
        try {
        mGray = inputFrame.gray();
        mObject = new Mat();
        mObject = Highgui.imread(Environment.getExternalStorageDirectory()+ "/Android/data/" + getApplicationContext().getPackageName() + "/Files/Object.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE);
        mView = mGray.clone();          

        FeatureDetector myFeatureDetector = FeatureDetector.create(FeatureDetector.ORB);

        MatOfKeyPoint keypoints = new MatOfKeyPoint();
        myFeatureDetector.detect(mGray, keypoints);

        MatOfKeyPoint objectkeypoints = new MatOfKeyPoint();
        myFeatureDetector.detect(mObject, objectkeypoints);

        DescriptorExtractor Extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
        Mat sourceDescriptors = new Mat();
        Mat objectDescriptors = new Mat();
        Extractor.compute(mGray, keypoints, sourceDescriptors);
        Extractor.compute(mGray, objectkeypoints, objectDescriptors);
        DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

        MatOfDMatch matches = new MatOfDMatch();
        matcher.match(sourceDescriptors, objectDescriptors, matches);

        Features2d.drawMatches(mGray, keypoints, mObject, objectkeypoints, matches, mView);

        return mView;
        } catch (Exception e) {
            Log.d("Exception",e.getMessage());
        }

    }

    return mRgba;
}

It can not show the object on screen , but I need some information that I can put rectangle or something I can mark the object what I want to track . Sorry about my English , I hope you understand what I'm asking , Thanks for any suggestion .

1
  • Apparently, Features2d.drawMatches does not work in android when you apply it for live camera feeds. You can proceed further to draw homography and then find the results. You can print LOG informations in intermediate steps just to see how may matches you get Commented Dec 20, 2013 at 14:12

1 Answer 1

1

Thank for Darshan's suggestion , I solve the problem , it need to resize the image , add this code below Features2d.drawMatches(mGray, keypoints, mObject, objectkeypoints, matches, mView); like this Imgproc.resize(mView, mView, mGray.size()); and then it can work .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.