Search in sources :

Example 6 with Point2D_F32

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);
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32) Test(org.junit.Test)

Example 7 with Point2D_F32

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;
                }
            }
        }
    }
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32)

Example 8 with Point2D_F32

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);
}
Also used : CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.Test)

Example 9 with Point2D_F32

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);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) Point2D_F32(georegression.struct.point.Point2D_F32) Test(org.junit.Test)

Example 10 with Point2D_F32

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);
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32) Test(org.junit.Test)

Aggregations

Point2D_F32 (georegression.struct.point.Point2D_F32)98 Test (org.junit.Test)36 Point3D_F32 (georegression.struct.point.Point3D_F32)10 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)9 LineSegment2D_F32 (georegression.struct.line.LineSegment2D_F32)8 ArrayList (java.util.ArrayList)8 Point2D_F64 (georegression.struct.point.Point2D_F64)7 FMatrixRMaj (org.ejml.data.FMatrixRMaj)7 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)5 LineParametric2D_F32 (georegression.struct.line.LineParametric2D_F32)5 Point2Transform3_F32 (boofcv.struct.distort.Point2Transform3_F32)4 Point3Transform2_F32 (boofcv.struct.distort.Point3Transform2_F32)4 GrayF32 (boofcv.struct.image.GrayF32)4 ClosestPoint2D_F32 (georegression.metric.ClosestPoint2D_F32)4 PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 GrayU8 (boofcv.struct.image.GrayU8)3 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)2 PinholePtoN_F32 (boofcv.alg.distort.pinhole.PinholePtoN_F32)2 CalibrationObservation (boofcv.alg.geo.calibration.CalibrationObservation)2