use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class TldFernClassifier method computeFernValue.
/**
* Computes the value of the specified fern at the specified location in the image.
*/
protected int computeFernValue(float c_x, float c_y, float rectWidth, float rectHeight, TldFernDescription fern) {
rectWidth -= 1;
rectHeight -= 1;
int desc = 0;
for (int i = 0; i < fern.pairs.length; i++) {
Point2D_F32 p_a = fern.pairs[i].a;
Point2D_F32 p_b = fern.pairs[i].b;
float valA = interpolate.get_fast(c_x + p_a.x * rectWidth, c_y + p_a.y * rectHeight);
float valB = interpolate.get_fast(c_x + p_b.x * rectWidth, c_y + p_b.y * rectHeight);
desc *= 2;
if (valA < valB) {
desc += 1;
}
}
return desc;
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class DisplayFisheyeCalibrationPanel method drawFeatures.
private void drawFeatures(Graphics2D g2, double scale) {
if (results == null)
return;
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
CalibrationObservation set = features;
Point2D_F32 adj = new Point2D_F32();
if (showOrder) {
renderOrder(g2, scale, (List) set.points);
}
if (showPoints) {
g2.setColor(Color.BLACK);
g2.setStroke(new BasicStroke(3));
for (PointIndex2D_F64 p : set.points) {
adj.set((float) p.x, (float) p.y);
VisualizeFeatures.drawCross(g2, adj.x * scale, adj.y * scale, 4);
}
g2.setStroke(new BasicStroke(1));
g2.setColor(Color.RED);
for (PointIndex2D_F64 p : set.points) {
adj.set((float) p.x, (float) p.y);
VisualizeFeatures.drawCross(g2, adj.x * scale, adj.y * scale, 4);
}
}
if (showAll) {
for (CalibrationObservation l : allFeatures) {
for (PointIndex2D_F64 p : l.points) {
adj.set((float) p.x, (float) p.y);
VisualizeFeatures.drawPoint(g2, adj.x * scale, adj.y * scale, 2, Color.BLUE, false);
}
}
}
if (showNumbers) {
drawNumbers(g2, set, null, scale);
}
if (showErrors) {
g2.setStroke(new BasicStroke(4));
g2.setColor(Color.BLACK);
for (int i = 0; i < set.size(); i++) {
PointIndex2D_F64 p = set.get(i);
adj.set((float) p.x, (float) p.y);
double r = errorScale * results.pointError[i];
if (r < 1)
continue;
VisualizeFeatures.drawCircle(g2, adj.x * scale, adj.y * scale, r);
}
g2.setStroke(new BasicStroke(2.5f));
g2.setColor(Color.ORANGE);
for (int i = 0; i < set.size(); i++) {
PointIndex2D_F64 p = set.get(i);
adj.set((float) p.x, (float) p.y);
double r = errorScale * results.pointError[i];
if (r < 1)
continue;
VisualizeFeatures.drawCircle(g2, adj.x * scale, adj.y * scale, r);
}
}
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class DisplayPinholeCalibrationPanel method drawNumbers.
public static void drawNumbers(Graphics2D g2, CalibrationObservation foundTarget, Point2Transform2_F32 transform, double scale) {
Font regular = new Font("Serif", Font.PLAIN, 16);
g2.setFont(regular);
Point2D_F32 adj = new Point2D_F32();
AffineTransform origTran = g2.getTransform();
for (int i = 0; i < foundTarget.size(); i++) {
Point2D_F64 p = foundTarget.get(i);
int gridIndex = foundTarget.get(i).index;
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", gridIndex);
int x = (int) (adj.x * scale);
int y = (int) (adj.y * scale);
g2.setColor(Color.BLACK);
g2.drawString(text, x - 1, y);
g2.drawString(text, x + 1, y);
g2.drawString(text, x, y - 1);
g2.drawString(text, x, y + 1);
g2.setTransform(origTran);
g2.setColor(Color.GREEN);
g2.drawString(text, x, y);
}
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class ShapeFittingOps method convert_I32_F32.
public static List<Point2D_F32> convert_I32_F32(List<Point2D_I32> points) {
List<Point2D_F32> pointsF = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {
Point2D_I32 p = points.get(i);
pointsF.add(new Point2D_F32(p.x, p.y));
}
return pointsF;
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class SegmentMeanShiftSearchColor method process.
/**
* Performs mean-shift clustering on the input image
*
* @param image Input image
*/
@Override
public void process(T image) {
// initialize data structures
this.image = image;
modeLocation.reset();
modeColor.reset();
modeMemberCount.reset();
interpolate.setImage(image);
pixelToMode.reshape(image.width, image.height);
quickMode.reshape(image.width, image.height);
// mark as -1 so it knows which pixels have been assigned a mode already and can skip them
ImageMiscOps.fill(pixelToMode, -1);
// mark all pixels are not being a mode
ImageMiscOps.fill(quickMode, -1);
// use mean shift to find the peak of each pixel in the image
int indexImg = 0;
for (int y = 0; y < image.height; y++) {
for (int x = 0; x < image.width; x++, indexImg++) {
if (pixelToMode.data[indexImg] != -1) {
int peakIndex = pixelToMode.data[indexImg];
modeMemberCount.data[peakIndex]++;
continue;
}
interpolate.get(x, y, meanColor);
findPeak(x, y, meanColor);
// convert mean-shift location into pixel index
int modeX = (int) (this.modeX + 0.5f);
int modeY = (int) (this.modeY + 0.5f);
int modePixelIndex = modeY * image.width + modeX;
// get index in the list of peaks
int modeIndex = quickMode.data[modePixelIndex];
// If the mode is new add it to the list
if (modeIndex < 0) {
modeIndex = this.modeLocation.size();
this.modeLocation.grow().set(modeX, modeY);
// Save the peak's color
savePeakColor(meanColor);
// Mark the mode in the segment image
quickMode.data[modePixelIndex] = modeIndex;
// Set the initial count to zero. This will be incremented when it is traversed later on
modeMemberCount.add(0);
}
// add this pixel to the membership list
modeMemberCount.data[modeIndex]++;
// This is an approximate of mean-shift
for (int i = 0; i < history.size; i++) {
Point2D_F32 p = history.get(i);
int px = (int) (p.x + 0.5f);
int py = (int) (p.y + 0.5f);
int index = pixelToMode.getIndex(px, py);
if (pixelToMode.data[index] == -1) {
pixelToMode.data[index] = modeIndex;
}
}
}
}
}
Aggregations