Example usage for org.opencv.core MatOfKeyPoint get

List of usage examples for org.opencv.core MatOfKeyPoint get

Introduction

In this page you can find the example usage for org.opencv.core MatOfKeyPoint get.

Prototype

public double[] get(int row, int col) 

Source Link

Usage

From source file:OCV_FeatureDetection.java

License:Open Source License

private MatOfDMatch showData(MatOfKeyPoint key_query, MatOfKeyPoint key_train, MatOfDMatch dmatch) {
    MatOfDMatch output = new MatOfDMatch();
    int num = dmatch.rows();
    float[] ele_dmatch = new float[4];

    ResultsTable rt = OCV__LoadLibrary.GetResultsTable(true);

    for (int i = 0; i < num; i++) {
        dmatch.get(i, 0, ele_dmatch);/*from w ww  .j  a v a 2s .c o m*/

        if (ele_dmatch[3] <= max_distance) {
            output.push_back(dmatch.row(i));

            int queryidx = (int) ele_dmatch[0];
            int trainidx = (int) ele_dmatch[1];
            float distance = ele_dmatch[3];

            double x_query = key_query.get(queryidx, 0)[0];
            double y_query = key_query.get(queryidx, 0)[1];
            double x_train = key_train.get(trainidx, 0)[0];
            double y_train = key_train.get(trainidx, 0)[1];

            rt.incrementCounter();
            rt.addValue("x_query", x_query);
            rt.addValue("y_query", y_query);
            rt.addValue("x_train", x_train);
            rt.addValue("y_train", y_train);
            rt.addValue("distance", distance);
            rt.show("Results");
        }
    }

    return output;
}

From source file:fi.conf.tabare.ARDataProvider.java

private void track() {
    while (running) {

        //Process blobs
        while (params.blobTracking && !blobData.isEmpty()) {

            MatOfKeyPoint r = blobData.poll();
            for (int i = 0; i < r.rows(); i++) {
                double[] c = r.get(i, 0);
                TrackableBlob blob = null;
                for (TrackableBlob cb : trackedBlobs) {
                    if (cb.getProximity(c[0], c[1], 0) <= OBJECT_MERGE_PROXIMITY) {
                        blob = cb;//  w w w  .  j  a  va 2s.  co m
                        cb.update(c[0], c[1], 0, c[2]);
                        break;
                    }
                }
                if (blob == null) {
                    blob = new TrackableBlob(c[0], c[1], 0, c[2]);
                    trackedBlobs.add(blob);
                }
                calibrator.applyCalibration(blob);
            }
            r.release();

        }

        //Process tripcodes
        if (params.tripTracking) {
            lblFound.setText(tripcodeData.size() + "/" + trackedTripcodes.size() + " fiducials found");
        }
        while (params.tripTracking && !tripcodeData.isEmpty()) {
            TripcodeCandidateSample t = tripcodeData.poll();

            TrackableTripcode trip = null;
            boolean newCode = true;

            //Search if fiducial is close/overlapping with previously detected fiducials
            for (TrackableTripcode tb : trackedTripcodes.values()) {
                //System.out.println("old: " + tb.getRawX() + " " + tb.getRawY() + ", new: " + t.x + " " + t.y + ", d: " + tb.getProximity(t.x, t.y));
                if (tb.getProximity(t.x, t.y) <= params.tripCenterDist) {
                    trip = tb;
                    trip.update(t);
                    newCode = false;
                    break;
                }
            }

            if (trip == null) {
                trip = new TrackableTripcode(t);
            }

            trip.crunch();

            int id = trip.getID();

            if (trackedTripcodes.contains(id)) {
                trackedTripcodes.get(id).release();
                newCode = false;
            }

            trackedTripcodes.put((int) trip.getID(), trip);

            calibrator.applyCalibration(trip);

            if (newCode) {
                informListenersAppeared(trip);
            } else {
                informListenersChanged(trip);
            }

        }

        //Visualization and cleanup
        Graphics2D g = camPreviewPanel.getOverlayGraphics();
        if (g == null)
            continue;

        calibrator.drawGrid(g);

        for (TrackableBlob blob : trackedBlobs) {
            if (blob.getDecay() > 1) {
                trackedBlobs.remove(blob);
                continue;
            }
            g.setColor(Color.MAGENTA);
            g.drawString("" + blob.getID(), (int) blob.getRawX(), (int) blob.getRawY());
            g.fillOval((int) blob.getRawX() - 2, (int) blob.getRawY() - 2, 4, 4);
        }

        for (TrackableTripcode trip : trackedTripcodes.values()) {

            if (trip.getDecay() > 1) {
                continue;
            }

            trip.debugDraw(g, true);
        }

        camPreviewPanel.swapOverlay();

        //FPS calculations
        if (camPreviewPanel != null) {
            long t = System.currentTimeMillis();
            trackTime = (t - lastFrameTrackTime);
            lastFrameTrackTime = t;
            camPreviewPanel.updateTrackTime(trackTime);
        }

        //Slowdown if not enough work, so we don't consume time for nothing.
        if (trackTime < 100) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}