Example usage for org.opencv.core MatOfKeyPoint rows

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

Introduction

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

Prototype

public int rows() 

Source Link

Usage

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;//from  w  ww.  j  a va2 s.  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();
            }
        }

    }
}