image tracking with android and openCv

asked 2015-06-28 01:35:51 -0600

updated 2018-09-03 10:43:26 -0600

i am new android devloper , i want to tracking special object in android and replaced by another image ... for example find a book and replace bood by a special image I find bottom code , but it dosen't work . plz help me :( how i can do this project

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
     Mat novo = new Mat();
        Mat resp = new Mat();
        Mat homer = new Mat();

       // resp = inputFrame.gray();
        novo = inputFrame.gray();

        Mat lido = new Mat();
        try {
            lido = Utils.loadResource(this, R.drawable.first);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Imgproc.cvtColor(lido, homer, Imgproc.COLOR_RGB2GRAY);

        FeatureDetector surf = FeatureDetector.create(FeatureDetector.FAST);

        MatOfKeyPoint keypointsHomer = new MatOfKeyPoint();
        MatOfKeyPoint keypoints = new MatOfKeyPoint();

        surf.detect(homer, keypointsHomer);
        surf.detect(novo, keypoints);

        DescriptorExtractor SurfExtractor = DescriptorExtractor.create(FeatureDetector.SURF);

        Mat descriptors = new Mat();
        Mat homerDescriptors = new Mat();

        SurfExtractor.compute(novo, keypoints, descriptors);
        SurfExtractor.compute(homer, keypointsHomer, homerDescriptors);

        DescriptorMatcher m = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
        MatOfDMatch matches = new MatOfDMatch();

        m.match(descriptors, homerDescriptors, matches);

        Features2d.drawMatches(novo, keypoints, homer, keypointsHomer, matches, resp);
       // Features2d.drawKeypoints(novo, keypoints, resp);
        //Features2d.drawKeypoints(homer, keypointsHomer, resp);
        return resp;

    //return inputFrame.rgba();

}

}

edit retag flag offensive close merge delete