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));
}
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();
}
}
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();
}
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;
}
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));
}
}
Aggregations