/** * Remove grids which cannot possible match the expected shape */ static void pruneIncorrectShape(FastQueue<Grid> grids , int numRows, int numCols ) { // prune clusters which can't be a member calibration target for (int i = grids.size()-1; i >= 0; i--) { Grid g = grids.get(i); if ((g.rows != numRows || g.columns != numCols) && (g.rows != numCols || g.columns != numRows)) { grids.remove(i); } } }
/** * If there is a nearly perfect line a node farther down the line can come before. This just selects the closest */ void pruneNearlyIdenticalAngles() { for (int i = 0; i < listInfo.size(); i++) { NodeInfo infoN = listInfo.get(i); for (int j = 0; j < infoN.edges.size(); ) { int k = (j+1)%infoN.edges.size; double angularDiff = UtilAngle.dist(infoN.edges.get(j).angle,infoN.edges.get(k).angle); if( angularDiff < UtilAngle.radian(5)) { NodeInfo infoJ = infoN.edges.get(j).target; NodeInfo infoK = infoN.edges.get(k).target; double distJ = infoN.ellipse.center.distance(infoJ.ellipse.center); double distK = infoN.ellipse.center.distance(infoK.ellipse.center); if( distJ < distK ) { infoN.edges.remove(k); } else { infoN.edges.remove(j); } } else { j++; } } } }
/** * Searches for the fiducial inside the image. * If at least a partial match is found true is returned. * * @param input Input image * @return true if at least one of the component fiducials is detected. False otherwise */ public boolean detect( T input ) { detections.reset(); detector.process(input); FastQueue<FoundFiducial> found = detector.getFound(); for (int i = 0; i < found.size(); i++) { FoundFiducial fid = found.get(i); int gridIndex = isExpected(fid.id); if( gridIndex >= 0 ) { Detection d = lookupDetection(fid.id,gridIndex); d.location.set(fid.distortedPixels); d.numDetected++; } } for (int i = detections.size-1; i >= 0; i--) { if( detections.get(i).numDetected != 1 ) { detections.remove(i); } } return detections.size > 0; }
@Test public void remove() { FastQueue<DummyData> alg = new FastQueue<DummyData>(10,DummyData.class,true); List<DummyData> l = alg.toList(); assertEquals(0,l.size()); alg.grow().value = 1; alg.grow().value = 2; alg.grow().value = 3; alg.remove(1); assertEquals(2,alg.size()); assertEquals(1,alg.get(0).value); assertEquals(3,alg.get(1).value); // make sure the data was shifted to the end assertEquals(2,alg.data[2].value); alg.remove(1); assertEquals(1,alg.size()); assertEquals(1,alg.get(0).value); assertEquals(3,alg.data[1].value); assertEquals(2,alg.data[2].value); alg.remove(0); assertEquals(0,alg.size()); assertEquals(1,alg.data[0].value); assertEquals(3,alg.data[1].value); assertEquals(2,alg.data[2].value); }