use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class TestPointToPixelTransform_F32 method manual.
@Test
public void manual() {
Dummy p = new Dummy();
PointToPixelTransform_F32 alg = new PointToPixelTransform_F32(p);
alg.compute(1, 2);
Point2D_F32 expected = new Point2D_F32();
p.compute(1, 2, expected);
assertEquals(expected.x, alg.distX, 1e-6);
assertEquals(expected.y, alg.distY, 1e-6);
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class SegmentMeanShiftSearchGray 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;
}
float meanColor = interpolate.get(x, y);
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
modeColor.grow()[0] = meanGray;
// 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;
}
}
}
}
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class TestLensDistortionOps method transformChangeModel_F32_EXPAND_modified.
/**
* Sees if the adjusted intrinsic parameters is correct but computing normalized image coordinates first
* with the original distorted image and then with the adjusted undistorted image.
*/
@Test
public void transformChangeModel_F32_EXPAND_modified() {
// distorted pixel in original image
float pixelX = 12.5f, pixelY = height - 3;
CameraPinholeRadial orig = new CameraPinholeRadial().fsetK(300, 320, 0, 150, 130, width, height).fsetRadial(0.1, 0.05);
CameraPinhole desired = new CameraPinhole(orig);
Point2Transform2_F32 distToNorm = LensDistortionOps.narrow(orig).undistort_F32(true, false);
Point2D_F32 norm = new Point2D_F32();
distToNorm.compute(pixelX, pixelY, norm);
CameraPinholeRadial adjusted = new CameraPinholeRadial();
Point2Transform2_F32 distToAdj = LensDistortionOps.transformChangeModel_F32(AdjustmentType.EXPAND, orig, desired, false, adjusted);
Point2D_F32 adjPixel = new Point2D_F32();
Point2D_F32 normFound = new Point2D_F32();
distToAdj.compute(pixelX, pixelY, adjPixel);
PerspectiveOps.convertPixelToNorm(adjusted, adjPixel, normFound);
// see if the normalized image coordinates are the same
assertEquals(norm.x, normFound.x, 1e-3);
assertEquals(norm.y, normFound.y, 1e-3);
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class TestNarrowToWidePtoP_F32 method rotateCamera.
/**
* Rotate the camera and see if the point moves in the expected way
*/
@Test
public void rotateCamera() {
NarrowToWidePtoP_F32 alg = createAlg();
Point2D_F32 found = new Point2D_F32();
FMatrixRMaj R = ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0.1f, 0, 0, null);
alg.setRotationWideToNarrow(R);
alg.compute(250, 250, found);
assertTrue(480 < found.x - 5);
R = ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, -0.1f, 0, 0, null);
alg.setRotationWideToNarrow(R);
alg.compute(250, 250, found);
assertTrue(480 > found.x + 5);
R = ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0, -0.1f, 0, null);
alg.setRotationWideToNarrow(R);
alg.compute(250, 250, found);
assertTrue(480 < found.y - 5);
R = ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0, 0.1f, 0, null);
alg.setRotationWideToNarrow(R);
alg.compute(250, 250, found);
assertTrue(480 > found.y + 5);
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class TestNarrowToWidePtoP_F32 method centerIsCenter.
/**
* With no translation request a point in the center. Should appear to be in the center in both views.
*/
@Test
public void centerIsCenter() {
NarrowToWidePtoP_F32 alg = createAlg();
Point2D_F32 found = new Point2D_F32();
alg.compute(250, 250, found);
assertEquals(480, found.x, GrlConstants.TEST_SQ_F32);
assertEquals(480, found.y, GrlConstants.TEST_SQ_F32);
}
Aggregations