use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class CommonDetectCalibrationApp method drawNumbers.
public static void drawNumbers(Graphics2D g2, List<Point2D_F64> foundTarget, Point2Transform2_F32 transform, double scale) {
Font regular = new Font("Serif", Font.PLAIN, 16);
g2.setFont(regular);
g2.setStroke(new BasicStroke(2));
FontRenderContext frc = g2.getFontRenderContext();
Point2D_F32 adj = new Point2D_F32();
AffineTransform at = new AffineTransform();
AffineTransform origTran = g2.getTransform();
for (int i = 0; i < foundTarget.size(); i++) {
Point2D_F64 p = foundTarget.get(i);
if (transform != null) {
transform.compute((float) p.x, (float) p.y, adj);
} else {
adj.set((float) p.x, (float) p.y);
}
String text = String.format("%2d", i);
GlyphVector gv = regular.createGlyphVector(frc, text);
at.setToTranslation(adj.x * scale, adj.y * scale);
at.concatenate(origTran);
g2.setTransform(at);
for (int j = 0; j < gv.getNumGlyphs(); j++) {
g2.setColor(Color.BLACK);
g2.draw(gv.getGlyphOutline(j));
g2.setColor(Color.GREEN);
g2.fill(gv.getGlyphOutline(j));
}
}
g2.setTransform(origTran);
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class GeneralDetectLineTests method obviousLine.
private <T extends ImageGray<T>> void obviousLine(Class<T> imageType) {
T input = GeneralizedImageOps.createSingleBand(imageType, width, height);
GImageMiscOps.fillRectangle(input, 30, 0, 0, lineLocation, height);
DetectLine<T> alg = createAlg(imageType);
List<LineParametric2D_F32> found = alg.detect(input);
assertTrue(found.size() >= 1);
// see if at least one of the lines is within tolerance
boolean foundMatch = false;
for (LineParametric2D_F32 l : found) {
Point2D_F32 p = l.getPoint();
double angle = l.getAngle();
if (Math.abs(p.x - lineLocation) < toleranceLocation && ((UtilAngle.dist(Math.PI / 2, angle) <= toleranceAngle) || (UtilAngle.dist(-Math.PI / 2, angle) <= toleranceAngle))) {
foundMatch = true;
break;
}
}
assertTrue(foundMatch);
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class TestShapeFittingOps method createEllipse_F32.
public static List<Point2D_F32> createEllipse_F32(EllipseRotated_F32 ellipse, int numPoints) {
List<Point2D_F32> sequence = new ArrayList<>();
for (int i = 0; i < numPoints; i++) {
double theta = 2.0 * Math.PI * i / numPoints;
Point2D_F32 p = new Point2D_F32();
UtilEllipse_F32.computePoint((float) theta, ellipse, p);
sequence.add(p);
}
return sequence;
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class LocalWeightedHistogramRotRect method computeHistogramBorder.
/**
* Computes the histogram and skips pixels which are outside the image border
*/
protected void computeHistogramBorder(T image, RectangleRotate_F32 region) {
for (int i = 0; i < samplePts.size(); i++) {
Point2D_F32 p = samplePts.get(i);
squareToImageSample(p.x, p.y, region);
// make sure its inside the image
if (!BoofMiscOps.checkInside(image, imageX, imageY)) {
sampleHistIndex[i] = -1;
} else {
// use the slower interpolation which can handle the border
interpolate.get(imageX, imageY, value);
int indexHistogram = computeHistogramBin(value);
sampleHistIndex[i] = indexHistogram;
histogram[indexHistogram] += weights[i];
}
}
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class TrackerMeanShiftComaniciu2003 method updateLocation.
/**
* Updates the region's location using the standard mean-shift algorithm
*/
protected void updateLocation(T image, RectangleRotate_F32 region) {
double bestHistScore = Double.MAX_VALUE;
float bestX = -1, bestY = -1;
for (int i = 0; i < maxIterations; i++) {
calcHistogram.computeHistogram(image, region);
float[] histogram = calcHistogram.getHistogram();
updateWeights(histogram);
// the histogram fit doesn't always improve with each mean-shift iteration
// save the best one and use it later on
double histScore = distanceHistogram(keyHistogram, histogram);
if (histScore < bestHistScore) {
bestHistScore = histScore;
bestX = region.cx;
bestY = region.cy;
}
List<Point2D_F32> samples = calcHistogram.getSamplePts();
int[] sampleHistIndex = calcHistogram.getSampleHistIndex();
// Compute equation 13
float meanX = 0;
float meanY = 0;
float totalWeight = 0;
for (int j = 0; j < samples.size(); j++) {
Point2D_F32 samplePt = samples.get(j);
int histIndex = sampleHistIndex[j];
if (histIndex < 0)
continue;
// compute the weight derived from the Bhattacharyya coefficient. Equation 10.
float w = weightHistogram[histIndex];
meanX += w * samplePt.x;
meanY += w * samplePt.y;
totalWeight += w;
}
meanX /= totalWeight;
meanY /= totalWeight;
// convert to image pixels
calcHistogram.squareToImageSample(meanX, meanY, region);
meanX = calcHistogram.imageX;
meanY = calcHistogram.imageY;
// see if the change is below the threshold
boolean done = Math.abs(meanX - region.cx) <= minimumChange && Math.abs(meanY - region.cy) <= minimumChange;
region.cx = meanX;
region.cy = meanY;
if (done) {
break;
}
}
// use the best location found
region.cx = bestX;
region.cy = bestY;
}
Aggregations