/** * Returns the top n lines from the accumulator space. * The end points of the lines will have x coordinates at -2000 and 2000. * * @param n The number of lines to return * @return A list of lines */ public List<Line2d> getBestLines( int n ) { return getBestLines( n, accum, 0 ); }
/** * Calculates a projection across the accumulator space. * Returns an image that has width {@link #getNumberOfSegments()} * and height of 1. Effectively sums across the distances from origin * in the space such that you end up with a representation that gives you * the strength of the angles in the image irrespective of where those * lines occur. * * @return A horizontal projection on the accumulator space as an * FImage with dimensions {@link #getNumberOfSegments()} x 1 */ public FImage calculateHorizontalProjection() { return calculateHorizontalProjection( accum ); }
/** * Returns the most frequent angle that occurs within the accumulator * space by calculating a horizontal projection over the accumulator * space and returning the angle with the most votes. The prevailing * angle is given in degrees. If it is less than zero, then no angle * could be extracted (there was no local maxima in the accumulator). * * @return The prevailing angle (degrees) in the accumulator space; or * Double.MIN_VALUE if the value cannot be calculated */ public double calculatePrevailingAngle() { return calculatePrevailingAngle( accum, 0, 360 ); }
/** * {@inheritDoc} * @see java.lang.Iterable#iterator() */ @Override public Iterator<Line2d> iterator() { clearIterator(); checkIteratorSetup(); return this; }
final HoughLines hl = new HoughLines(360 * this.accuracy); edgeImage.analyseWith(hl); this.debugLines(edgeImage, Matrix.identity(3, 3), "Detection of Horizontal Lines", hl.getBestLines(2)); double rotationAngle = hl.calculatePrevailingAngle(); hl.getBestLines(2, -shearAngleRange, shearAngleRange)); double shearAngle = hl.calculatePrevailingAngle(-shearAngleRange, shearAngleRange);
final FImage chessboard = ImageUtilities.readF(new URL("http://www.ugcs.caltech.edu/~rajan/REPORT/camera.jpg")); final HoughLines hlines = new HoughLines(1.f); chessboard.process(new CannyEdgeDetector()).analyseWith(hlines); final List<Line2d> lines = hlines.getBestLines(50); final List<Point2d> intersections = new ArrayList<Point2d>(); for (final Line2d inner : lines) {
int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage f = accum.extractROI( mt, 0, xt-mt, accum.getHeight() ); return getBestLines( n, f, mt ); int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage a = accum.shiftRight( -mt ).extractROI(0,0,(xt-mt),accum.getHeight()); return getBestLines( n, a, mt );
int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage f = accum.extractROI( mt, 0, xt-mt, accum.getHeight() ); return getBestLine( f, mt ); int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage a = accum.shiftRight( -mt ).extractROI(0,0,(xt-mt),accum.getHeight()); return getBestLine( a, mt );
int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage f = accum.extractROI( mt, 0, xt-mt, accum.getHeight() ); return calculatePrevailingAngle( f, mt, (xt-mt)*(360d/getNumberOfSegments()) ); int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage a = accum.shiftRight( -mt ).extractROI(0,0,(xt-mt),accum.getHeight()); return calculatePrevailingAngle( a, mt, (xt-mt)*(360d/getNumberOfSegments()) );
/** * Returns the top line in the accumulator space. * The end points of the line will have x coordinates at -2000 and 2000. * * @return The strongest line in the accumulator space */ public Line2d getBestLine() { return getBestLine( accum, 0 ); }
/** * Returns the top line in the given accumulator space. * The end points of the line will have x coordinates at -2000 and 2000. * * @param accumulatorSpace The accumulator space to look within * @param offset The number of bins offset from zero degrees * @return The strongest line in the accumulator space */ public Line2d getBestLine( FImage accumulatorSpace, int offset ) { FValuePixel p = accumulatorSpace.maxPixel(); // Remember accumulator space is r,theta int theta = p.x + offset; int dist = p.y; return getLineFromParams( theta, dist, -2000, 2000 ); }
accum.width != getNumberOfSegments() ) accum = new FImage( getNumberOfSegments(), amax ); else accum.zero(); for( int m = 0; m < getNumberOfSegments(); m++ ) double mm = ((double)m / (double)getNumberOfSegments()) * (2 * PI); int a = (int) round( x * cos(mm) + y * sin(mm) ); if( a < amax && a >= 0)
/** * Constructor that creates an accumulator space for the given number * of segments. * * @param nSegments The number of segments. * @param onValue value of pixels considered on */ public HoughLines( int nSegments , float onValue) { this.setNumberOfSegments( nSegments ); this.onValue = onValue; }
final HoughLines hl = new HoughLines(360 * this.accuracy); edgeImage.analyseWith(hl); this.debugLines(edgeImage, Matrix.identity(3, 3), "Detection of Horizontal Lines", hl.getBestLines(2)); double rotationAngle = hl.calculatePrevailingAngle(); hl.getBestLines(2, -shearAngleRange, shearAngleRange)); double shearAngle = hl.calculatePrevailingAngle(-shearAngleRange, shearAngleRange);
int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage f = accum.extractROI( mt, 0, xt-mt, accum.getHeight() ); return getBestLines( n, f, mt ); int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage a = accum.shiftRight( -mt ).extractROI(0,0,(xt-mt),accum.getHeight()); return getBestLines( n, a, mt );
/** * {@inheritDoc} * @see java.lang.Iterable#iterator() */ @Override public Iterator<Line2d> iterator() { clearIterator(); checkIteratorSetup(); return this; }
int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage f = accum.extractROI( mt, 0, xt-mt, accum.getHeight() ); return getBestLine( f, mt ); int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage a = accum.shiftRight( -mt ).extractROI(0,0,(xt-mt),accum.getHeight()); return getBestLine( a, mt );
int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage f = accum.extractROI( mt, 0, xt-mt, accum.getHeight() ); return calculatePrevailingAngle( f, mt, (xt-mt)*(360d/getNumberOfSegments()) ); int mt = (int)(minTheta / (360d/getNumberOfSegments())); int xt = (int)(maxTheta / (360d/getNumberOfSegments())); FImage a = accum.shiftRight( -mt ).extractROI(0,0,(xt-mt),accum.getHeight()); return calculatePrevailingAngle( a, mt, (xt-mt)*(360d/getNumberOfSegments()) );
/** * Returns the top line in the accumulator space. * The end points of the line will have x coordinates at -2000 and 2000. * * @return The strongest line in the accumulator space */ public Line2d getBestLine() { return getBestLine( accum, 0 ); }
/** * Returns the top line in the given accumulator space. * The end points of the line will have x coordinates at -2000 and 2000. * * @param accumulatorSpace The accumulator space to look within * @param offset The number of bins offset from zero degrees * @return The strongest line in the accumulator space */ public Line2d getBestLine( FImage accumulatorSpace, int offset ) { FValuePixel p = accumulatorSpace.maxPixel(); // Remember accumulator space is r,theta int theta = p.x + offset; int dist = p.y; return getLineFromParams( theta, dist, -2000, 2000 ); }