List of usage examples for org.opencv.core MatOfKeyPoint release
public void release()
From source file:com.oetermann.imageclassifier.DescriptorExtractorWrapper.java
License:Open Source License
public Mat detectAndCompute(Mat image) { MatOfKeyPoint keypoint = new MatOfKeyPoint(); featureDetector.detect(image, keypoint); Mat descriptor = new Mat(); descriptorExtractor.compute(image, keypoint, descriptor); keypoint.release(); return descriptor; }
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 w w .j a v a2s . c o 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(); } } } }
From source file:samples.GripVision.java
License:Open Source License
private Rect getTargetRect(GripPipeline pipeline, Mat image) { Rect targetRect = null;//w w w . j ava2 s. c om MatOfKeyPoint detectedTargets; pipeline.process(image); detectedTargets = pipeline.findBlobsOutput(); if (detectedTargets != null) { KeyPoint[] targets = detectedTargets.toArray(); if (targets.length > 1) { HalDashboard.getInstance().displayPrintf(15, "%s: %s", pipeline, targets[0]); double radius = targets[0].size / 2; targetRect = new Rect((int) (targets[0].pt.x - radius), (int) (targets[0].pt.y - radius), (int) targets[0].size, (int) targets[0].size); } detectedTargets.release(); } return targetRect; }