Search in sources :

Example 1 with PointIndex4D_F64

use of boofcv.struct.geo.PointIndex4D_F64 in project BoofCV by lessthanoptimal.

the class ColorizeCloudFromImage method process4.

/**
 * Colorizes all the points in the specified range using the specified image.
 *
 * @param image (Input) Which image is being considered
 * @param cloud (Input) The point cloud in homogenous coordinates
 * @param idx0 (Input) The first point in the point cloud that's inside this image. Inclusive.
 * @param idx1 (Input) The last point in the point cloud that's inside this image. Exclusive.
 * @param world_to_view (Input) Transform from world (cloud) into this image/view.
 * @param norm_to_pixel (Input) Normalized image coordinates into pixel coordinates.
 * @param colorizer (Output) As the color of each point becomes known this function is invoked.
 */
public void process4(T image, List<Point4D_F64> cloud, int idx0, int idx1, Se3_F64 world_to_view, Point2Transform2_F64 norm_to_pixel, BoofLambdas.IndexRgbConsumer colorizer) {
    var iterator = new PointToIndexIterator<>(cloud, idx0, idx1, new PointIndex4D_F64());
    process4(image, iterator, world_to_view, norm_to_pixel, colorizer);
}
Also used : PointIndex4D_F64(boofcv.struct.geo.PointIndex4D_F64)

Example 2 with PointIndex4D_F64

use of boofcv.struct.geo.PointIndex4D_F64 in project BoofCV by lessthanoptimal.

the class ColorizeMultiViewStereoResults method processScenePoints.

/**
 * Looks up the colors for all the points in the scene by reprojecting them back onto their original images.
 *
 * @param scene (Input) Scene's structure
 * @param indexToId (Input) Convert view index to view ID
 * @param indexColor (Output) RGB values are passed through to this function.
 */
public void processScenePoints(SceneStructureMetric scene, BoofLambdas.IndexToString indexToId, BoofLambdas.IndexRgbConsumer indexColor) {
    // Loading images is expensive so when we get the color of each pixel we want to process all features
    // inside the same image at once. Unfortunately there is no fast way to look up all features by image.
    // So a lookup table is constructed below
    List<DogArray_I32> lookupPointsByView = new ArrayList<>();
    for (int i = 0; i < scene.views.size; i++) {
        lookupPointsByView.add(new DogArray_I32());
    }
    // Add the first view each point was seen in to the list
    for (int pointIdx = 0; pointIdx < scene.points.size; pointIdx++) {
        SceneStructureCommon.Point p = scene.points.get(pointIdx);
        lookupPointsByView.get(p.views.get(0)).add(pointIdx);
    }
    // TODO in the future generalize this for 3D and 4D points
    var iterator = new ScenePointsSetIterator<>(new PointIndex4D_F64());
    var world_to_view = new Se3_F64();
    for (int viewIdx = 0; viewIdx < lookupPointsByView.size(); viewIdx++) {
        // Load the image
        checkTrue(lookupImages.loadImage(indexToId.process(viewIdx), image), "Failed to load image");
        // Set up the iterator for this image
        iterator.initialize(scene, lookupPointsByView.get(viewIdx));
        // Get the view that is being processed
        SceneStructureMetric.View v = scene.views.get(viewIdx);
        // Setup the camera projection model using bundle adjustment model directly
        BundleAdjustmentOps.convert(scene.getViewCamera(v).model, image.width, image.height, intrinsic);
        Point2Transform2_F64 norm_to_pixel = new LensDistortionBrown(intrinsic).distort_F64(false, true);
        // Get the transform from world/cloud to this view
        scene.getWorldToView(v, world_to_view, tmp);
        // Grab the colorized points from this view
        colorizer.process4(image, iterator, world_to_view, norm_to_pixel, indexColor);
    }
}
Also used : LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) ArrayList(java.util.ArrayList) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) DogArray_I32(org.ddogleg.struct.DogArray_I32) SceneStructureCommon(boofcv.abst.geo.bundle.SceneStructureCommon) SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) PointIndex4D_F64(boofcv.struct.geo.PointIndex4D_F64) Se3_F64(georegression.struct.se.Se3_F64)

Example 3 with PointIndex4D_F64

use of boofcv.struct.geo.PointIndex4D_F64 in project BoofCV by lessthanoptimal.

the class TestScenePointsSetIterator method basic.

@Test
void basic() {
    var scene = new SceneStructureMetric(true);
    scene.initialize(1, 1, 5);
    for (int i = 0; i < 5; i++) {
        scene.setPoint(i, 1, i + 2, 3, 4);
    }
    var indexes = DogArray_I32.array(1, 3);
    var alg = new ScenePointsSetIterator<>(scene, indexes, new PointIndex4D_F64());
    for (int i = 0; i < indexes.size; i++) {
        assertTrue(alg.hasNext());
        PointIndex4D_F64 found = alg.next();
        assertEquals(i * 2 + 1, found.index);
        assertEquals(0.0, found.p.distance(1, (i * 2 + 3), 3, 4), UtilEjml.TEST_F64);
    }
    assertFalse(alg.hasNext());
}
Also used : SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) PointIndex4D_F64(boofcv.struct.geo.PointIndex4D_F64) Test(org.junit.jupiter.api.Test)

Example 4 with PointIndex4D_F64

use of boofcv.struct.geo.PointIndex4D_F64 in project BoofCV by lessthanoptimal.

the class ColorizeCloudFromImage method process4.

public void process4(T image, Iterator<PointIndex4D_F64> cloud, Se3_F64 world_to_view, Point2Transform2_F64 norm_to_pixel, BoofLambdas.IndexRgbConsumer colorizer) {
    colorLookup.setImage(image);
    while (cloud.hasNext()) {
        PointIndex4D_F64 pidx = cloud.next();
        SePointOps_F64.transform(world_to_view, pidx.p, viewPt4);
        // See if the point is behind the camera
        if (Math.signum(viewPt4.z) * Math.signum(viewPt4.w) < 0)
            continue;
        // w component is ignored. x = [I(3) 0]*X
        norm_to_pixel.compute(viewPt4.x / viewPt4.z, viewPt4.y / viewPt4.z, pixel);
        if (pixel.x < 0.0 || pixel.y < 0.0)
            continue;
        int xx = (int) (pixel.x + 0.5);
        int yy = (int) (pixel.y + 0.5);
        if (xx >= image.width || yy >= image.height)
            continue;
        int rgb = colorLookup.lookupRgb(xx, yy);
        colorizer.setRgb(pidx.index, (rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF);
    }
}
Also used : PointIndex4D_F64(boofcv.struct.geo.PointIndex4D_F64)

Aggregations

PointIndex4D_F64 (boofcv.struct.geo.PointIndex4D_F64)4 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)2 SceneStructureCommon (boofcv.abst.geo.bundle.SceneStructureCommon)1 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)1 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 ArrayList (java.util.ArrayList)1 DogArray_I32 (org.ddogleg.struct.DogArray_I32)1 Test (org.junit.jupiter.api.Test)1