use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class GeneralDetectLineTests method subImages.
private <T extends ImageGray<T>> void subImages(Class<T> imageType) {
T input = GeneralizedImageOps.createSingleBand(imageType, width, height);
GImageMiscOps.fillRectangle(input, 30, 0, 0, lineLocation, height);
T sub = BoofTesting.createSubImageOf(input);
List<LineParametric2D_F32> foundA = createAlg(imageType).detect(input);
List<LineParametric2D_F32> foundB = createAlg(imageType).detect(sub);
// the output should be exactly identical
assertEquals(foundA.size(), foundB.size());
for (int i = 0; i < foundA.size(); i++) {
LineParametric2D_F32 a = foundA.get(i);
LineParametric2D_F32 b = foundB.get(i);
assertTrue(a.slope.x == b.slope.x);
assertTrue(a.slope.y == b.slope.y);
assertTrue(a.p.x == b.p.x);
assertTrue(a.p.y == b.p.y);
}
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class DetectLineHoughFootSubimage method processSubimage.
private void processSubimage(int x0, int y0, int x1, int y1, List<LineParametric2D_F32> found) {
D derivX = (D) this.derivX.subimage(x0, y0, x1, y1);
D derivY = (D) this.derivY.subimage(x0, y0, x1, y1);
GrayU8 binary = this.binary.subimage(x0, y0, x1, y1);
alg.transform(derivX, derivY, binary);
FastQueue<LineParametric2D_F32> lines = alg.extractLines();
float[] intensity = alg.getFoundIntensity();
for (int i = 0; i < lines.size; i++) {
// convert from the sub-image coordinate system to original image coordinate system
LineParametric2D_F32 l = lines.get(i).copy();
l.p.x += x0;
l.p.y += y0;
found.add(l);
post.add(l, intensity[i]);
}
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class DetectLineHoughPolar method detect.
@Override
public List<LineParametric2D_F32> detect(I input) {
// see if the input image shape has changed.
if (derivX.width != input.width || derivY.height != input.height) {
double r = Math.sqrt(input.width * input.width + input.height * input.height);
int numBinsRange = (int) Math.ceil(r / resolutionRange);
int numBinsAngle = (int) Math.ceil(Math.PI / resolutionAngle);
alg = new HoughTransformLinePolar(extractor, numBinsRange, numBinsAngle);
derivX.reshape(input.width, input.height);
derivY.reshape(input.width, input.height);
intensity.reshape(input.width, input.height);
binary.reshape(input.width, input.height);
// angle.reshape(input.width, input.height);
// direction.reshape(input.width, input.height);
suppressed.reshape(input.width, input.height);
}
gradient.process(input, derivX, derivY);
GGradientToEdgeFeatures.intensityAbs(derivX, derivY, intensity);
// non-max suppression reduces the number of line pixels, reducing the number of false positives
// When too many pixels are flagged, then more curves randomly cross over in transform space causing
// false positives
// GGradientToEdgeFeatures.direction(derivX, derivY, angle);
// GradientToEdgeFeatures.discretizeDirection4(angle, direction);
// GradientToEdgeFeatures.nonMaxSuppression4(intensity,direction, suppressed);
GGradientToEdgeFeatures.nonMaxSuppressionCrude4(intensity, derivX, derivY, suppressed);
ThresholdImageOps.threshold(suppressed, binary, thresholdEdge, false);
alg.transform(binary);
FastQueue<LineParametric2D_F32> lines = alg.extractLines();
List<LineParametric2D_F32> ret = new ArrayList<>();
for (int i = 0; i < lines.size; i++) ret.add(lines.get(i));
ret = pruneLines(input, ret);
return ret;
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class VisualizeHoughPolar method process.
public void process(BufferedImage image) {
I input = GeneralizedImageOps.createSingleBand(imageType, image.getWidth(), image.getHeight());
I blur = GeneralizedImageOps.createSingleBand(imageType, image.getWidth(), image.getHeight());
ConvertBufferedImage.convertFromSingle(image, input, imageType);
GBlurImageOps.gaussian(input, blur, -1, 2, null);
DetectLineHoughPolar<I, D> alg = FactoryDetectLineAlgs.houghPolar(new ConfigHoughPolar(5, 10, 2, Math.PI / 180, 25, 10), imageType, derivType);
List<LineParametric2D_F32> lines = alg.detect(blur);
ImageLinePanel gui = new ImageLinePanel();
gui.setBackground(image);
gui.setLines(lines);
gui.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
BufferedImage renderedTran = VisualizeImageData.grayMagnitude(alg.getTransform().getTransform(), null, -1);
BufferedImage renderedBinary = VisualizeBinaryData.renderBinary(alg.getBinary(), false, null);
// Draw the location of lines onto the magnitude image
Graphics2D g2 = renderedTran.createGraphics();
g2.setColor(Color.RED);
Point2D_F64 location = new Point2D_F64();
for (LineParametric2D_F32 l : lines) {
alg.getTransform().lineToCoordinate(l, location);
int r = 6;
int w = r * 2 + 1;
int x = (int) (location.x + 0.5);
int y = (int) (location.y + 0.5);
// System.out.println(x+" "+y+" "+renderedTran.getWidth()+" "+renderedTran.getHeight());
g2.drawOval(x - r, y - r, w, w);
}
ShowImages.showWindow(renderedBinary, "Detected Edges");
ShowImages.showWindow(renderedTran, "Parameter Space");
ShowImages.showWindow(gui, "Detected Lines");
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class GridRansacLineDetector method convertToLineSegment.
/**
* Lines are found in polar form and this coverts them into line segments by finding
* the extreme points of points on the line.
*
* @param matchSet Set of points belonging to the line.
* @param model Detected line.
* @return Line segement.
*/
private LineSegment2D_F32 convertToLineSegment(List<Edgel> matchSet, LinePolar2D_F32 model) {
float minT = Float.MAX_VALUE;
float maxT = -Float.MAX_VALUE;
LineParametric2D_F32 line = UtilLine2D_F32.convert(model, (LineParametric2D_F32) null);
Point2D_F32 p = new Point2D_F32();
for (Edgel e : matchSet) {
p.set(e.x, e.y);
float t = ClosestPoint2D_F32.closestPointT(line, e);
if (minT > t)
minT = t;
if (maxT < t)
maxT = t;
}
LineSegment2D_F32 segment = new LineSegment2D_F32();
segment.a.x = line.p.x + line.slope.x * minT;
segment.a.y = line.p.y + line.slope.y * minT;
segment.b.x = line.p.x + line.slope.x * maxT;
segment.b.y = line.p.y + line.slope.y * maxT;
return segment;
}
Aggregations