Search in sources :

Example 1 with Rectangle2D_F64

use of georegression.struct.shapes.Rectangle2D_F64 in project BoofCV by lessthanoptimal.

the class TestEdgeIntensityPolygon method checkIntensity.

@Test
void checkIntensity() {
    GrayU8 image = new GrayU8(400, 500);
    int value = 200;
    ImageMiscOps.fillRectangle(image, value, 20, 30, 40, 40);
    EdgeIntensityPolygon<GrayU8> alg = new EdgeIntensityPolygon<>(2, 2, 10, GrayU8.class);
    Polygon2D_F64 polygon = new Polygon2D_F64(4);
    UtilPolygons2D_F64.convert(new Rectangle2D_F64(20, 30, 60, 70), polygon);
    alg.setImage(image);
    assertTrue(alg.computeEdge(polygon, polygon.isCCW()));
    assertTrue(alg.checkIntensity(false, 50));
    assertFalse(alg.checkIntensity(true, 50));
}
Also used : Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64) GrayU8(boofcv.struct.image.GrayU8) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.jupiter.api.Test)

Example 2 with Rectangle2D_F64

use of georegression.struct.shapes.Rectangle2D_F64 in project BoofCV by lessthanoptimal.

the class ExampleWebcamObjectTracking method process.

/**
 * Invoke to start the main processing loop.
 */
public void process() {
    Webcam webcam = UtilWebcamCapture.openDefault(desiredWidth, desiredHeight);
    // adjust the window size and let the GUI know it has changed
    Dimension actualSize = webcam.getViewSize();
    setPreferredSize(actualSize);
    setMinimumSize(actualSize);
    window.setMinimumSize(actualSize);
    window.setPreferredSize(actualSize);
    window.setVisible(true);
    // create
    T input = tracker.getImageType().createImage(actualSize.width, actualSize.height);
    workImage = new BufferedImage(input.getWidth(), input.getHeight(), BufferedImage.TYPE_INT_RGB);
    while (true) {
        BufferedImage buffered = webcam.getImage();
        if (buffered == null)
            break;
        ConvertBufferedImage.convertFrom(webcam.getImage(), input, true);
        // mode is read/written to by the GUI also
        int mode = this.mode;
        boolean success = false;
        if (mode == 2) {
            Rectangle2D_F64 rect = new Rectangle2D_F64();
            rect.setTo(point0.x, point0.y, point1.x, point1.y);
            UtilPolygons2D_F64.convert(rect, target);
            success = tracker.initialize(input, target);
            this.mode = success ? 3 : 0;
        } else if (mode == 3) {
            success = tracker.process(input, target);
        }
        synchronized (lockGUI) {
            // copy the latest image into the work buffered
            Graphics2D g2 = workImage.createGraphics();
            g2.drawImage(buffered, 0, 0, null);
            // visualize the current results
            if (mode == 1) {
                drawSelected(g2);
            } else if (mode == 3) {
                if (success) {
                    drawTrack(g2);
                }
            }
        }
        repaint();
    }
}
Also used : Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64) Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 3 with Rectangle2D_F64

use of georegression.struct.shapes.Rectangle2D_F64 in project BoofCV by lessthanoptimal.

the class TldVisualizationPanel method update.

public synchronized void update(final TldTracker tracker, boolean hasSelected) {
    this.hasSelected = hasSelected;
    if (hasSelected) {
        Rectangle2D_F64 r = tracker.getTargetRegion();
        TldHelperFunctions.convertRegion(r, this.selected);
        addDetections(tracker.getDetection().getLocalMaximums());
        positivePanel.update(tracker.getTemplateMatching().getTemplatePositive(), false);
        negativePanel.update(tracker.getTemplateMatching().getTemplateNegative(), false);
    } else {
        detections.reset();
    }
    repaint();
}
Also used : Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64)

Example 4 with Rectangle2D_F64

use of georegression.struct.shapes.Rectangle2D_F64 in project BoofCV by lessthanoptimal.

the class CommonFitPolygonChecks method findMatchesOriginal.

/**
 * Compare found rectangle against rectangles in the original undistorted image
 */
protected int findMatchesOriginal(Polygon2D_F64 found, double tol) {
    int match = 0;
    for (int i = 0; i < rectangles.size(); i++) {
        Rectangle2D_I32 ri = rectangles.get(i);
        Rectangle2D_F64 r = new Rectangle2D_F64(ri.x0, ri.y0, ri.x1, ri.y1);
        Polygon2D_F64 p = new Polygon2D_F64(4);
        UtilPolygons2D_F64.convert(r, p);
        if (p.isCCW())
            p.flip();
        if (UtilPolygons2D_F64.isEquivalent(found, p, tol))
            match++;
    }
    return match;
}
Also used : Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64) Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 5 with Rectangle2D_F64

use of georegression.struct.shapes.Rectangle2D_F64 in project BoofCV by lessthanoptimal.

the class TestECoCheckUtils method selectPixelsToSample.

/**
 * Have it compute all the sample points then make sure the points it expects are inside one of the squares
 */
@Test
void selectPixelsToSample() {
    var alg = new ECoCheckUtils();
    alg.addMarker(4, 3);
    alg.fixate();
    // Set it to identity so that the pixels and bit-units are the same
    CommonOps_DDRM.setIdentity(alg.squareToPixel);
    int row = 1;
    int col = 2;
    Rectangle2D_F64 bitRect = new Rectangle2D_F64();
    alg.bitRect(row, col, bitRect);
    var pixels = new DogArray<>(Point2D_F64::new);
    // add an element to make sure it resets
    pixels.grow();
    alg.selectPixelsToSample(pixels);
    int w = alg.codec.gridBitLength;
    assertEquals(alg.bitSampleCount * w * w, pixels.size);
    // find the block if pixels for this bit
    int index = (row * w + col) * alg.bitSampleCount;
    // Every pixel should be inside the rect
    for (int i = 0; i < alg.bitSampleCount; i++) {
        Point2D_F64 p = pixels.get(index + i);
        assertTrue(Intersection2D_F64.contains(bitRect, p.x, p.y));
    }
}
Also used : Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Aggregations

Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)19 Test (org.junit.jupiter.api.Test)13 GrayU8 (boofcv.struct.image.GrayU8)3 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)3 Rectangle2D_I32 (georegression.struct.shapes.Rectangle2D_I32)3 DogArray (org.ddogleg.struct.DogArray)3 ScaleTranslate2D (boofcv.struct.geo.ScaleTranslate2D)2 Webcam (com.github.sarxos.webcam.Webcam)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 BufferedImage (java.awt.image.BufferedImage)2 ConvertBufferedImage (boofcv.core.image.ConvertBufferedImage)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 ImageRectangle (boofcv.struct.ImageRectangle)1 AssociatedPair (boofcv.struct.geo.AssociatedPair)1 UtilPoint2D_F64 (georegression.geometry.UtilPoint2D_F64)1