code
stringlengths
73
34.1k
label
stringclasses
1 value
protected void setAllowedBounds(KltFeature feature) { // compute the feature's width and temporary storage related to it widthFeature = feature.radius * 2 + 1; lengthFeature = widthFeature * widthFeature; allowedLeft = feature.radius; allowedTop = feature.radius; allowedRight = image.width - feature.radius...
java
protected int computeGandE_border(KltFeature feature, float cx, float cy) { computeSubImageBounds(feature, cx, cy); ImageMiscOps.fill(currDesc, Float.NaN); currDesc.subimage(dstX0, dstY0, dstX1, dstY1, subimage); interpInput.setImage(image); interpInput.region(srcX0, srcY0, subimage); int total = 0; G...
java
public boolean isDescriptionComplete( KltFeature feature ) { for( int i = 0; i < lengthFeature; i++ ) { if( Float.isNaN(feature.desc.data[i]) ) return false; } return true; }
java
public boolean isFullyInside(float x, float y) { if (x < allowedLeft || x > allowedRight) return false; if (y < allowedTop || y > allowedBottom) return false; return true; }
java
public boolean isFullyOutside(float x, float y) { if (x < outsideLeft || x > outsideRight) return true; if (y < outsideTop || y > outsideBottom) return true; return false; }
java
private boolean checkMax(T image, double adj, double bestScore, int c_x, int c_y) { sparseLaplace.setImage(image); boolean isMax = true; beginLoop: for (int i = c_y - 1; i <= c_y + 1; i++) { for (int j = c_x - 1; j <= c_x + 1; j++) { double value = adj*sparseLaplace.compute(j, i); if (value >= bestSc...
java
public void findPatterns(GrayF32 input) { found.reset(); detector.process(input); clusterFinder.process(detector.getCorners().toList()); FastQueue<ChessboardCornerGraph> clusters = clusterFinder.getOutputClusters(); for (int clusterIdx = 0; clusterIdx < clusters.size; clusterIdx++) { ChessboardCornerGraph...
java
public void configure( int width , int height , int gridRows , int gridCols ) { // need to maintain the same ratio of pixels in the grid as in the regular image for similarity and rigid // to work correctly int s = Math.max(width,height); scaleX = s/(float)(gridCols-1); scaleY = s/(float)(gridRows-1); if( ...
java
public int addControl( float x , float y ) { Control c = controls.grow(); c.q.set(x,y); setUndistorted(controls.size()-1,x,y); return controls.size()-1; }
java
public void setUndistorted(int which, float x, float y) { if( scaleX <= 0 || scaleY <= 0 ) throw new IllegalArgumentException("Must call configure first"); controls.get(which).p.set(x/scaleX,y/scaleY); }
java
public int add( float srcX , float srcY , float dstX , float dstY ) { int which = addControl(srcX,srcY); setUndistorted(which,dstX,dstY); return which; }
java
public void setDistorted( int which , float x , float y ) { controls.get(which).q.set(x,y); }
java
public void fixateUndistorted() { if( controls.size() < 2 ) throw new RuntimeException("Not enough control points specified. Found "+controls.size()); for (int row = 0; row < gridRows; row++) { for (int col = 0; col < gridCols; col++) { Cache cache = getGrid(row,col); cache.weights.resize(controls.si...
java
void computeAverageP(Cache cache) { float[] weights = cache.weights.data; cache.aveP.set(0,0); for (int i = 0; i < controls.size(); i++) { Control c = controls.get(i); float w = weights[i]; cache.aveP.x += c.p.x * w; cache.aveP.y += c.p.y * w; } cache.aveP.x /= cache.totalWeight; cache.aveP.y /...
java
void computeAverageQ(Cache cache) { float[] weights = cache.weights.data; cache.aveQ.set(0,0); for (int i = 0; i < controls.size(); i++) { Control c = controls.get(i); float w = weights[i]; cache.aveQ.x += c.q.x * w; cache.aveQ.y += c.q.y * w; } cache.aveQ.x /= cache.totalWeight; cache.aveQ.y /...
java
void interpolateDeformedPoint(float v_x , float v_y , Point2D_F32 deformed ) { // sample the closest point and x+1,y+1 int x0 = (int)v_x; int y0 = (int)v_y; int x1 = x0+1; int y1 = y0+1; // make sure the 4 sample points are in bounds if( x1 >= gridCols ) x1 = gridCols-1; if( y1 >= gridRows ) y1 ...
java
public void process( DMatrixRMaj cameraCalibration , List<DMatrixRMaj> homographies , List<CalibrationObservation> observations ) { init( observations ); setupA_and_B(cameraCalibration,homographies,observations); if( !solver.setA(A) ) throw new RuntimeException("Solver had problems"); solve...
java
private void init( List<CalibrationObservation> observations ) { int totalPoints = 0; for (int i = 0; i < observations.size(); i++) { totalPoints += observations.get(i).size(); } A.reshape(2*totalPoints,X.numRows,false); B.reshape(A.numRows,1,false); }
java
@Override public boolean process(double x, double y) { leftPixelToRect.compute(x,y,pixelRect); // round to the nearest pixel if( !disparity.process((int)(pixelRect.x+0.5),(int)(pixelRect.y+0.5)) ) return false; // Compute coordinate in camera frame this.w = disparity.getDisparity(); computeHomo3D(pix...
java
public void detachEdge(SquareEdge edge) { edge.a.edges[edge.sideA] = null; edge.b.edges[edge.sideB] = null; edge.distance = 0; edgeManager.recycleInstance(edge); }
java
public int findSideIntersect(SquareNode n , LineSegment2D_F64 line , Point2D_F64 intersection, LineSegment2D_F64 storage ) { for (int j = 0,i=3; j < 4; i=j,j++) { storage.a = n.square.get(i); storage.b = n.square.get(j); if( Intersection2D_F64.intersection(line,storage,intersection) != null ) { return i...
java
public void checkConnect( SquareNode a , int indexA , SquareNode b , int indexB , double distance ) { if( a.edges[indexA] != null && a.edges[indexA].distance > distance ) { detachEdge(a.edges[indexA]); } if( b.edges[indexB] != null && b.edges[indexB].distance > distance ) { detachEdge(b.edges[indexB]); }...
java
void connect( SquareNode a , int indexA , SquareNode b , int indexB , double distance ) { SquareEdge edge = edgeManager.requestInstance(); edge.reset(); edge.a = a; edge.sideA = indexA; edge.b = b; edge.sideB = indexB; edge.distance = distance; a.edges[indexA] = edge; b.edges[indexB] = edge; }
java
public boolean almostParallel(SquareNode a , int sideA , SquareNode b , int sideB ) { double selected = acuteAngle(a,sideA,b,sideB); if( selected > parallelThreshold ) return false; // see if the two sides are about parallel too // double left = acuteAngle(a,add(sideA,-1),b,add(sideB,1)); // double right =...
java
public void setImageGradient(Deriv derivX, Deriv derivY ) { this.derivX.wrap(derivX); this.derivY.wrap(derivY); }
java
void computeHistogram(int c_x, int c_y, double sigma) { int r = (int)Math.ceil(sigma * sigmaEnlarge); // specify the area being sampled bound.x0 = c_x - r; bound.y0 = c_y - r; bound.x1 = c_x + r + 1; bound.y1 = c_y + r + 1; ImageGray rawDX = derivX.getImage(); ImageGray rawDY = derivY.getImage(); /...
java
void findHistogramPeaks() { // reset data structures peaks.reset(); angles.reset(); peakAngle = 0; // identify peaks and find the highest peak double largest = 0; int largestIndex = -1; double before = histogramMag[ histogramMag.length-2 ]; double current = histogramMag[ histogramMag.length-1 ]; fo...
java
double computeAngle( int index1 ) { int index0 = CircularIndex.addOffset(index1,-1, histogramMag.length); int index2 = CircularIndex.addOffset(index1, 1, histogramMag.length); // compute the peak location using a second order polygon double v0 = histogramMag[index0]; double v1 = histogramMag[index1]; doub...
java
double interpolateAngle(int index0, int index1, int index2, double offset) { double angle1 = Math.atan2(histogramY[index1],histogramX[index1]); double deltaAngle; if( offset < 0 ) { double angle0 = Math.atan2(histogramY[index0],histogramX[index0]); deltaAngle = UtilAngle.dist(angle0,angle1); } else { ...
java
double computeWeight( double deltaX , double deltaY , double sigma ) { // the exact equation // return Math.exp(-0.5 * ((deltaX * deltaX + deltaY * deltaY) / (sigma * sigma))); // approximation below. when validating this approach it produced results that were within // floating point tolerance of the exact so...
java
@Override protected void onCameraResolutionChange( int width , int height, int sensorOrientation ) { super.onCameraResolutionChange(width, height,sensorOrientation); derivX.reshape(width, height); derivY.reshape(width, height); }
java
@Override protected void renderBitmapImage(BitmapMode mode, ImageBase image) { switch( mode ) { case UNSAFE: { // this application is configured to use double buffer and could ignore all other modes VisualizeImageData.colorizeGradient(derivX, derivY, -1, bitmap, bitmapTmp); } break; case DOUBLE_BUFFER:...
java
public void process( T image , GrayF32 intensity ) { int maxFeatures = (int)(maxFeaturesFraction*image.width*image.height); candidatesLow.reset(); candidatesHigh.reset(); this.image = image; if( stride != image.stride ) { stride = image.stride; offsets = DiscretizedCircle.imageOffsets(radius, image.str...
java
public static double selectZoomToShowAll(JComponent panel , int width , int height ) { int w = panel.getWidth(); int h = panel.getHeight(); if( w == 0 ) { w = panel.getPreferredSize().width; h = panel.getPreferredSize().height; } double scale = Math.max(width/(double)w,height/(double)h); if( scale > ...
java
public static double selectZoomToFitInDisplay( int width , int height ) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double w = screenSize.getWidth(); double h = screenSize.getHeight(); double scale = Math.max(width/w,height/h); if( scale > 1.0 ) { return 1.0/scale; } else { ...
java
public static void antialiasing( Graphics2D g2 ) { g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); }
java
public static boolean isImage( File file ){ try { String mimeType = Files.probeContentType(file.toPath()); if( mimeType == null ) { // In some OS there is a bug where it always returns null/ String extension = FilenameUtils.getExtension(file.getName()).toLowerCase(); String[] suffixes = ImageIO.getR...
java
public static void print( IntegralKernel kernel ) { int x0 = 0,x1=0,y0=0,y1=0; for( ImageRectangle k : kernel.blocks) { if( k.x0 < x0 ) x0 = k.x0; if( k.y0 < y0 ) y0 = k.y0; if( k.x1 > x1 ) x1 = k.x1; if( k.y1 > y1 ) y1 = k.y1; } int w = x1-x0; int h = y1-y0; int sum[] = new i...
java
public static boolean isInBounds( int x , int y , IntegralKernel kernel , int width , int height ) { for(ImageRectangle r : kernel.blocks ) { if( x+r.x0 < 0 || y+r.y0 < 0 ) return false; if( x+r.x1 >= width || y+r.y1 >= height ) return false; } return true; }
java
public void setScaleFactors( int ...scaleFactors ) { for( int i = 1; i < scaleFactors.length; i++ ){ if( scaleFactors[i] % scaleFactors[i-1] != 0 ) { throw new IllegalArgumentException("Layer "+i+" is not evenly divisible by its lower layer."); } } // set width/height to zero to force the image to be r...
java
public boolean process( List<Point2D_I32> list , GrowQueue_I32 vertexes ) { this.contour = list; this.minimumSideLengthPixel = minimumSideLength.computeI(contour.size()); splits.reset(); boolean result = _process(list); // remove reference so that it can be freed this.contour = null; vertexes.setTo(spli...
java
protected double splitThresholdSq( Point2D_I32 a , Point2D_I32 b ) { return Math.max(2,a.distance2(b)* toleranceFractionSq); }
java
@SuppressWarnings({"SuspiciousSystemArraycopy"}) @Override public void setTo(T orig) { if (orig.width != width || orig.height != height || orig.numBands != numBands ) reshape(orig.width,orig.height,orig.numBands); if (!orig.isSubimage() && !isSubimage()) { System.arraycopy(orig._getData(), orig.startIndex,...
java
public static void determinant(GrayF32 featureIntensity , GrayF32 hessianXX, GrayF32 hessianYY , GrayF32 hessianXY ) { InputSanityCheck.checkSameShape(featureIntensity,hessianXX,hessianYY,hessianXY); ImplHessianBlobIntensity.determinant(featureIntensity,hessianXX,hessianYY,hessianXY); }
java
public static void trace(GrayF32 featureIntensity , GrayF32 hessianXX, GrayF32 hessianYY ) { InputSanityCheck.checkSameShape(featureIntensity,hessianXX,hessianYY); ImplHessianBlobIntensity.trace(featureIntensity,hessianXX,hessianYY); }
java
public void reshape(int width , int height ) { if( padded == null ) { binary.reshape(width, height); } else { binary.reshape(width + 2, height + 2); binary.subimage(1, 1, width + 1, height + 1, subimage); } }
java
public boolean computeEdge(Polygon2D_F64 polygon , boolean ccw ) { averageInside = 0; averageOutside = 0; double tangentSign = ccw ? 1 : -1; int totalSides = 0; for (int i = polygon.size()-1,j=0; j < polygon.size(); i=j,j++) { Point2D_F64 a = polygon.get(i); Point2D_F64 b = polygon.get(j); double...
java
public boolean checkIntensity( boolean insideDark , double threshold ) { if( insideDark ) return averageOutside-averageInside >= threshold; else return averageInside-averageOutside >= threshold; }
java
public void setCamera( double skew , double cx , double cy , int width , int height ) { // Define normalization matrix // center points, remove skew, scale coordinates double d = Math.sqrt(width*width + height*height); V.zero(); V.set(0,0,d/2); V.set(0,1,skew); V.set(0,2,cx); V.set(1,1,d/2); V.set(1,2,cy);...
java
public void setSampling( double min , double max , int total ) { this.sampleMin = min; this.sampleMax = max; this.numSamples = total; this.scores = new double[numSamples]; }
java
boolean computeRectifyH( double f1 , double f2 , DMatrixRMaj P2, DMatrixRMaj H ) { estimatePlaneInf.setCamera1(f1,f1,0,0,0); estimatePlaneInf.setCamera2(f2,f2,0,0,0); if( !estimatePlaneInf.estimatePlaneAtInfinity(P2,planeInf) ) return false; // TODO add a cost for distance from nominal and scale other cos...
java
protected static List<NodeInfo> findLine(NodeInfo seed, NodeInfo next, int clusterSize, List<NodeInfo> line, boolean ccw ) { if( next == null ) return null; if( line == null ) line = new ArrayList<>(); else line.clear(); next.marked = true; double anglePrev = direction(next, seed); double prevDis...
java
protected static NodeInfo findClosestEdge( NodeInfo n , Point2D_F64 p ) { double bestDistance = Double.MAX_VALUE; NodeInfo best = null; for (int i = 0; i < n.edges.size(); i++) { Edge e = n.edges.get(i); if( e.target.marked ) continue; double d = e.target.ellipse.center.distance2(p); if( d < bes...
java
boolean checkDuplicates(List<List<NodeInfo>> grid ) { for (int i = 0; i < listInfo.size; i++) { listInfo.get(i).marked = false; } for (int i = 0; i < grid.size(); i++) { List<NodeInfo> list = grid.get(i); for (int j = 0; j < list.size(); j++) { NodeInfo n = list.get(j); if( n.marked ) retu...
java
void addEdgesToInfo(List<Node> cluster) { for (int i = 0; i < cluster.size(); i++) { Node n = cluster.get(i); NodeInfo infoA = listInfo.get(i); EllipseRotated_F64 a = infoA.ellipse; // create the edges and order them based on their direction for (int j = 0; j < n.connections.size(); j++) { NodeInf...
java
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 < Ut...
java
void findLargestAnglesForAllNodes() { for (int i = 0; i < listInfo.size(); i++) { NodeInfo info = listInfo.get(i); if( info.edges.size < 2 ) continue; for (int k = 0, j = info.edges.size-1; k < info.edges.size; j=k,k++) { double angleA = info.edges.get(j).angle; double angleB = info.edges.get(k...
java
boolean findContour( boolean mustHaveInner ) { // find the node with the largest angleBetween NodeInfo seed = listInfo.get(0); for (int i = 1; i < listInfo.size(); i++) { NodeInfo info = listInfo.get(i); if( info.angleBetween > seed.angleBetween ) { seed = info; } } // trace around the contour ...
java
public static int indexOf(List<Node> list , int value ) { for (int i = 0; i < list.size(); i++) { if( list.get(i).which == value ) return i; } return -1; }
java
NodeInfo selectSeedCorner() { NodeInfo best = null; double bestAngle = 0; for (int i = 0; i < contour.size; i++) { NodeInfo info = contour.get(i); if( info.angleBetween > bestAngle ) { bestAngle = info.angleBetween; best = info; } } best.marked = true; return best; }
java
public static void depthTo3D(CameraPinholeBrown param , GrayU16 depth , FastQueue<Point3D_F64> cloud ) { cloud.reset(); Point2Transform2_F64 p2n = LensDistortionFactory.narrow(param).undistort_F64(true,false); Point2D_F64 n = new Point2D_F64(); for( int y = 0; y < depth.height; y++ ) { int index = depth.s...
java
public static void depthTo3D(CameraPinholeBrown param , Planar<GrayU8> rgb , GrayU16 depth , FastQueue<Point3D_F64> cloud , FastQueueArray_I32 cloudColor ) { cloud.reset(); cloudColor.reset(); RemoveBrownPtoN_F64 p2n = new RemoveBrownPtoN_F64(); p2n.setK(param.fx,param.fy,param.skew,param.cx,param.cy)...
java
public boolean prune(List<Point2D_I32> contour, GrowQueue_I32 input, GrowQueue_I32 output) { this.contour = contour; output.setTo(input); removeDuplicates(output); // can't prune a corner and it will still be a polygon if( output.size() <= 3 ) return false; computeSegmentEnergy(output); double tota...
java
void removeDuplicates( GrowQueue_I32 corners ) { // remove duplicates for (int i = 0; i < corners.size(); i++) { Point2D_I32 a = contour.get(corners.get(i)); // start from the top so that removing a corner doesn't mess with the for loop for (int j = corners.size()-1; j > i; j--) { Point2D_I32 b = cont...
java
void computeSegmentEnergy( GrowQueue_I32 corners ) { if( energySegment.length < corners.size() ) { energySegment = new double[ corners.size() ]; } for (int i = 0,j=corners.size()-1; i < corners.size(); j=i,i++) { energySegment[j] = computeSegmentEnergy(corners, j, i); } }
java
protected double energyRemoveCorner( int removed , GrowQueue_I32 corners ) { double total = 0; int cornerA = CircularIndex.addOffset(removed, -1 , corners.size()); int cornerB = CircularIndex.addOffset(removed, 1 , corners.size()); total += computeSegmentEnergy(corners, cornerA, cornerB); if( cornerA > co...
java
protected double computeSegmentEnergy(GrowQueue_I32 corners, int cornerA, int cornerB) { int indexA = corners.get(cornerA); int indexB = corners.get(cornerB); if( indexA == indexB ) { return 100000.0; } Point2D_I32 a = contour.get(indexA); Point2D_I32 b = contour.get(indexB); line.p.x = a.x; line....
java
public void process( T image, GrayS32 pixelToRegion , GrowQueue_I32 regionMemberCount, FastQueue<float[]> regionColor ) { stopRequested = false; // iterate until no more regions need to be merged together while( !stopRequested ) { // Update the color of each region regionColor.resize(...
java
protected boolean setupPruneList(GrowQueue_I32 regionMemberCount) { segmentPruneFlag.resize(regionMemberCount.size); pruneGraph.reset(); segmentToPruneID.resize(regionMemberCount.size); for( int i = 0; i < regionMemberCount.size; i++ ) { if( regionMemberCount.get(i) < minimumSize ) { segmentToPruneID.set...
java
protected void findAdjacentRegions(GrayS32 pixelToRegion) { // -------- Do the inner pixels first if( connect.length == 4 ) adjacentInner4(pixelToRegion); else if( connect.length == 8 ) { adjacentInner8(pixelToRegion); } adjacentBorder(pixelToRegion); }
java
protected void selectMerge( int pruneId , FastQueue<float[]> regionColor ) { // Grab information on the region which is being pruned Node n = pruneGraph.get(pruneId); float[] targetColor = regionColor.get(n.segment); // segment ID and distance away from the most similar neighbor int bestId = -1; float best...
java
private void declareDerivativeImages(ImageGradient<T, D> gradient, ImageHessian<D> hessian, Class<D> derivType) { if( gradient != null || hessian != null ) { derivX = GeneralizedImageOps.createSingleBand(derivType, 1, 1); derivY = GeneralizedImageOps.createSingleBand(derivType,1,1); } if( hessian != null ) ...
java
public void detect(T input, QueueCorner exclude ) { initializeDerivatives(input); if (detector.getRequiresGradient() || detector.getRequiresHessian()) gradient.process(input, derivX, derivY); if (detector.getRequiresHessian()) hessian.process(derivX, derivY, derivXX, derivYY, derivXY); detector.setExcl...
java
private void initializeDerivatives(T input) { // reshape derivatives if the input image has changed size if (detector.getRequiresGradient() || detector.getRequiresHessian()) { derivX.reshape(input.width, input.height); derivY.reshape(input.width, input.height); } if (detector.getRequiresHessian()) { de...
java
public boolean checkFlip( SquareGrid grid ) { if( grid.columns == 1 || grid.rows == 1 ) return false; Point2D_F64 a = grid.get(0,0).center; Point2D_F64 b = grid.get(0,grid.columns-1).center; Point2D_F64 c = grid.get(grid.rows-1,0).center; double x0 = b.x-a.x; double y0 = b.y-a.y; double x1 = c.x-a.x...
java
protected void orderNodeGrid(SquareGrid grid, int row, int col) { SquareNode node = grid.get(row,col); if(grid.rows==1 && grid.columns==1 ) { for (int i = 0; i < 4; i++) { ordered[i] = node.square.get(i); } } else if( grid.columns==1 ) { if (row == grid.rows - 1) { orderNode(node, grid.get(row -...
java
private void rotateTwiceOrdered() { Point2D_F64 a = ordered[0]; Point2D_F64 b = ordered[1]; Point2D_F64 c = ordered[2]; Point2D_F64 d = ordered[3]; ordered[0] = c; ordered[1] = d; ordered[2] = a; ordered[3] = b; }
java
protected void orderNode(SquareNode target, SquareNode node, boolean pointingX) { int index0 = findIntersection(target,node); int index1 = (index0+1)%4; int index2 = (index0+2)%4; int index3 = (index0+3)%4; if( index0 < 0 ) throw new RuntimeException("Couldn't find intersection. Probable bug"); line...
java
protected int findIntersection( SquareNode target , SquareNode node ) { lineCenters.a = target.center; lineCenters.b = node.center; for (int i = 0; i < 4; i++) { int j = (i+1)%4; lineSide.a = target.square.get(i); lineSide.b = target.square.get(j); if(Intersection2D_F64.intersection(lineCenters,lin...
java
public boolean orderSquareCorners( SquareGrid grid ) { // the first pass interleaves every other row for (int row = 0; row < grid.rows; row++) { for (int col = 0; col < grid.columns; col++) { orderNodeGrid(grid, row, col); Polygon2D_F64 square = grid.get(row,col).square; for (int i = 0; i < 4; i++...
java
private static List<Match> findMatches(GrayF32 image, GrayF32 template, GrayF32 mask, int expectedMatches) { // create template matcher. TemplateMatching<GrayF32> matcher = FactoryTemplateMatching.createMatcher(TemplateScoreType.SUM_DIFF_SQ, GrayF32.class); // Find the points which match the tem...
java
public static void showMatchIntensity(GrayF32 image, GrayF32 template, GrayF32 mask) { // create algorithm for computing intensity image TemplateMatchingIntensity<GrayF32> matchIntensity = FactoryTemplateMatching.createIntensity(TemplateScoreType.SUM_DIFF_SQ, GrayF32.class); // apply the template to the ima...
java
private static void drawRectangles(Graphics2D g2, GrayF32 image, GrayF32 template, GrayF32 mask, int expectedMatches) { List<Match> found = findMatches(image, template, mask, expectedMatches); int r = 2; int w = template.width + 2 * r; int h = template.height + 2 * r; for (Match m : ...
java
@Override public void getCenter(int which, Point2D_F64 location) { Quadrilateral_F64 q = alg.getFound().get(which).distortedPixels; // compute intersection in undistorted pixels so that the intersection is the true // geometric center of the square. Since distorted pixels are being used this will only be approx...
java
public <T extends SquareNode>T destination(SquareNode src) { if( a == src ) return (T)b; else if( b == src ) return (T)a; else throw new IllegalArgumentException("BUG! src is not a or b"); }
java
public static String inlierPercent(VisualOdometry alg) { if( !(alg instanceof AccessPointTracks3D)) return ""; AccessPointTracks3D access = (AccessPointTracks3D)alg; int count = 0; int N = access.getAllTracks().size(); for( int i = 0; i < N; i++ ) { if( access.isInlier(i) ) count++; } return ...
java
public static void fitBinaryImage(GrayF32 input) { GrayU8 binary = new GrayU8(input.width,input.height); BufferedImage polygon = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB); // the mean pixel value is often a reasonable threshold when creating a binary image double mean = ImageStati...
java
public static void fitCannyEdges( GrayF32 input ) { BufferedImage displayImage = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB); // Finds edges inside the image CannyEdge<GrayF32,GrayF32> canny = FactoryEdgeDetectors.canny(2, true, true, GrayF32.class, GrayF32.class); canny.proces...
java
public static void fitCannyBinary( GrayF32 input ) { BufferedImage displayImage = new BufferedImage(input.width,input.height,BufferedImage.TYPE_INT_RGB); GrayU8 binary = new GrayU8(input.width,input.height); // Finds edges inside the image CannyEdge<GrayF32,GrayF32> canny = FactoryEdgeDetectors.canny(2, f...
java
protected Confusion evaluate( Map<String,List<String>> set ) { ClassificationHistogram histogram = new ClassificationHistogram(scenes.size()); int total = 0; for (int i = 0; i < scenes.size(); i++) { total += set.get(scenes.get(i)).size(); } System.out.println("total images "+total); for (int i = 0; i ...
java
public static Map<String,List<String>> findImages( File rootDir ) { File files[] = rootDir.listFiles(); if( files == null ) return null; List<File> imageDirectories = new ArrayList<>(); for( File f : files ) { if( f.isDirectory() ) { imageDirectories.add(f); } } Map<String,List<String>> out = ...
java
public synchronized void setImages(BufferedImage leftImage , BufferedImage rightImage ) { this.leftImage = leftImage; this.rightImage = rightImage; setPreferredSize(leftImage.getWidth(),leftImage.getHeight(),rightImage.getWidth(),rightImage.getHeight()); }
java
private void computeScales() { int width = getWidth(); int height = getHeight(); width = (width-borderSize)/2; // compute the scale factor for each image scaleLeft = scaleRight = 1; if( leftImage.getWidth() > width || leftImage.getHeight() > height ) { double scaleX = (double)width/(double)leftImage.ge...
java
public static void normalize(GrayF32 image , float mean , float stdev ) { for (int y = 0; y < image.height; y++) { int index = image.startIndex + y*image.stride; int end = index + image.width; while( index < end ) { image.data[index] = (image.data[index]-mean)/stdev; index++; } } }
java
public static Kernel1D_F32 create1D_F32( double[] kernel ) { Kernel1D_F32 k = new Kernel1D_F32(kernel.length,kernel.length/2); for (int i = 0; i < kernel.length; i++) { k.data[i] = (float)kernel[i]; } return k; }
java
public static void imageToTensor(Planar<GrayF32> input , Tensor_F32 output , int miniBatch) { if( input.isSubimage()) throw new RuntimeException("Subimages not accepted"); if( output.getDimension() != 4 ) throw new IllegalArgumentException("Output should be 4-DOF. batch + spatial (channel,height,width)"); ...
java
public void process( GrayU8 binary , int adjustX , int adjustY ) { // Initialize data structures this.adjustX = adjustX; this.adjustY = adjustY; storagePoints.reset(); ImageMiscOps.fillBorder(binary, 0, 1); tracer.setInputs(binary); final byte binaryData[] = binary.data; // Scan through the image one ...
java
static int findNotZero( byte[] data , int index , int end ) { while( index < end && data[index] == 0 ) { index++; } return index; }
java
static int findZero( byte[] data , int index , int end ) { while( index < end && data[index] != 0 ) { index++; } return index; }
java
public void addPatternImage(T pattern, double threshold, double lengthSide) { GrayU8 binary = new GrayU8(pattern.width,pattern.height); GThresholdImageOps.threshold(pattern,binary,threshold,false); alg.addPattern(binary, lengthSide); }
java