Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Android - Object detect

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 .

click to hide/show revision 2
retagged

Android - Object detect

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 .

Android - Object detect

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 .