Ask Your Question
0

Android - Object detect

asked 2013-12-20 06:56:25 -0600

TonySJH gravatar image

updated 2013-12-21 02:44:21 -0600

I'm trying to implement object tracking in with features detect , but I got the following error:image description It no need to show the object on screen but I need mark the object what I want to track , and here is my 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;
}

Sorry about my English , I hope you understand what I'm asking . Thanks for any suggestion .

EDIT

Thanks Moster's suggestion , I add the code Imgproc.resize(mView, mView, mGray.size()); after Features2d.drawMatches(mGray, keypoints, mObject, objectkeypoints, matches, mView);

, and it can work .

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-12-20 12:58:12 -0600

Moster gravatar image

updated 2013-12-20 13:08:49 -0600

Hmm, I am not 100% sure, but the issue seems to be related to what you do to the Mat mView. First, you make it a copy of the gray image, but then you reuse mView in drawMatches. drawMatches concatenates the 2 images mGray and mObject and puts them together with the matches in mView. So mView is bigger than mGray obviously. Then you return mView to draw it on the screen. This will fail since the function that receives mView expects an image of the same size as the inputFrame (mGray for example). So, in simple words, you cannot return mView like that.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-12-20 06:56:25 -0600

Seen: 548 times

Last updated: Dec 21 '13