Search in sources :

Example 6 with DogArray_F32

use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.

the class ImplMedianSortNaive method process.

/**
 * Performs a median filter.
 *
 * @param input Raw input image.
 * @param output Filtered image.
 * @param radiusX Size of the filter region. x-axis
 * @param radiusY Size of the filter region. Y-axis
 * @param workArrays (Optional) Storage for internal workspace. Nullable.
 */
public static void process(GrayF32 input, GrayF32 output, int radiusX, int radiusY, @Nullable GrowArray<DogArray_F32> workArrays) {
    final int w = 2 * radiusX + 1;
    final int h = 2 * radiusY + 1;
    workArrays = BoofMiscOps.checkDeclare(workArrays, DogArray_F32::new);
    // CONCURRENT_REMOVE_BELOW
    DogArray_F32 workspace = workArrays.grow();
    // CONCURRENT_BELOW BoofConcurrency.loopBlocks(0, input.height, h, workArrays, (workspace,y0,y1)->{
    final int y0 = 0, y1 = input.height;
    float[] workArray = BoofMiscOps.checkDeclare(workspace, w * h, false);
    for (int y = y0; y < y1; y++) {
        int minI = y - radiusY;
        int maxI = y + radiusY + 1;
        // bound the y-axis inside the image
        if (minI < 0)
            minI = 0;
        if (maxI > input.height)
            maxI = input.height;
        for (int x = 0; x < input.width; x++) {
            int minJ = x - radiusX;
            int maxJ = x + radiusX + 1;
            // bound the x-axis to be inside the image
            if (minJ < 0)
                minJ = 0;
            if (maxJ > input.width)
                maxJ = input.width;
            int index = 0;
            for (int i = minI; i < maxI; i++) {
                for (int j = minJ; j < maxJ; j++) {
                    workArray[index++] = input.unsafe_get(j, i);
                }
            }
            // use quick select to avoid sorting the whole list
            float median = QuickSelect.select(workArray, index / 2, index);
            output.set(x, y, median);
        }
    }
// CONCURRENT_ABOVE }});
}
Also used : DogArray_F32(org.ddogleg.struct.DogArray_F32)

Example 7 with DogArray_F32

use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.

the class PointCloudViewerFX method addCloud.

@Override
public void addCloud(List<Point3D_F64> cloud) {
    DogArray_F32 fcloud = new DogArray_F32();
    fcloud.resize(cloud.size() * 3);
    int fidx = 0;
    for (int i = 0; i < cloud.size(); i++) {
        Point3D_F64 p = cloud.get(i);
        fcloud.data[fidx++] = (float) p.x;
        fcloud.data[fidx++] = (float) p.y;
        fcloud.data[fidx++] = (float) p.z;
    }
    Platform.runLater(() -> panel.addCloud(fcloud));
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) DogArray_F32(org.ddogleg.struct.DogArray_F32)

Example 8 with DogArray_F32

use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.

the class PointCloudViewerApp method openFile.

public void openFile() {
    File selected = BoofSwingUtil.fileChooser("PointCloudViewer", frame, true, ".", null, BoofSwingUtil.FileTypes.FILES);
    if (selected == null)
        return;
    // Make it so open file can't be called twice
    BoofSwingUtil.recursiveEnable(menuBar, false);
    // Load it in a thread as to not lock the GUI
    new Thread(() -> {
        PointCloudWriter.CloudArraysF32 cloud = new PointCloudWriter.CloudArraysF32();
        try {
            InputStream input = new FileInputStream(selected);
            PointCloudIO.load(PointCloudIO.Format.PLY, input, cloud);
        } catch (IOException e) {
            BoofSwingUtil.warningDialog(frame, e);
            BoofSwingUtil.recursiveEnable(menuBar, true);
            return;
        }
        // Select an initial view location based on the point cloud
        final int N = cloud.cloudXyz.size / 3;
        float x = 0, y = 0, z = 0;
        for (int i = 0; i < N; i++) {
            x += cloud.cloudXyz.data[i * 3];
            y += cloud.cloudXyz.data[i * 3 + 1];
            z += cloud.cloudXyz.data[i * 3 + 2];
        }
        x /= N;
        y /= N;
        z /= N;
        DogArray_F32 distances = new DogArray_F32();
        distances.resize(N);
        for (int i = 0; i < N; i++) {
            float X = cloud.cloudXyz.data[i * 3];
            float Y = cloud.cloudXyz.data[i * 3 + 1];
            float Z = cloud.cloudXyz.data[i * 3 + 2];
            distances.data[i] = UtilPoint3D_F32.distance(x, y, z, X, Y, Z);
        }
        Se3_F64 worldToCamera = new Se3_F64();
        worldToCamera.T.setTo(x, y, z);
        // TODO pick a better method for selecting the initial step size
        distances.sort();
        double baseline = distances.getFraction(0.001);
        System.out.println("baseline = " + baseline);
        viewer.periodBaseline = baseline * 10;
        viewer.translateBaseline = baseline;
        viewer.getViewer().setCameraHFov(UtilAngle.radian(100));
        SwingUtilities.invokeLater(() -> {
            viewer.handleControlChange();
            viewer.clearPoints();
            viewer.getViewer().addCloud(cloud.cloudXyz, cloud.cloudRgb);
            viewer.getViewer().setCameraToWorld(worldToCamera);
            viewer.repaint();
            BoofSwingUtil.recursiveEnable(menuBar, true);
        });
    }).start();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) PointCloudWriter(boofcv.alg.cloud.PointCloudWriter) File(java.io.File) FileInputStream(java.io.FileInputStream) DogArray_F32(org.ddogleg.struct.DogArray_F32) Se3_F64(georegression.struct.se.Se3_F64)

Example 9 with DogArray_F32

use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.

the class MultiBaselineDisparityMedian method computeFused.

/**
 * Computes the fused output image. The median value is used if a pixel has more than 2 values. Otherwise the
 * mean will be used.
 *
 * @return true if the disparity image is not entirely empty
 */
boolean computeFused(GrayF32 disparity) {
    // If there's one pixel with a valid value this will pass
    boolean singleValidPixel = false;
    for (int y = 0; y < fused.height; y++) {
        int indexOut = disparity.startIndex + y * disparity.stride;
        for (int x = 0; x < fused.width; x++) {
            DogArray_F32 values = fused.get(x, y);
            float outputValue;
            if (values.size == 0) {
                // mark this pixel as invalid. The disparity will be rescaled later on and the max value at this
                // time isn't known
                outputValue = Float.MAX_VALUE;
            } else if (values.size == 1) {
                singleValidPixel = true;
                outputValue = values.data[0];
            } else if (values.size == 2) {
                singleValidPixel = true;
                outputValue = 0.5f * (values.data[0] + values.data[1]);
            } else {
                // median value
                outputValue = QuickSelect.select(values.data, values.size / 2, values.size);
                singleValidPixel = true;
            }
            disparity.data[indexOut++] = outputValue;
        }
    }
    return singleValidPixel;
}
Also used : VerbosePrint(org.ddogleg.struct.VerbosePrint) DogArray_F32(org.ddogleg.struct.DogArray_F32)

Example 10 with DogArray_F32

use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.

the class TestQrCodeBinaryGridReader method readBitIntensity_count.

/**
 * Checks to see if the expected number of points was read
 */
@Test
void readBitIntensity_count() {
    DogArray_F32 intensity = new DogArray_F32();
    // add a value to it to make sure it's not cleared
    intensity.add(5);
    QrCodeDistortedChecks helper = createDistortionCheck();
    QrCodeBinaryGridReader<GrayF32> reader = new QrCodeBinaryGridReader<>(GrayF32.class);
    reader.setImage(helper.image);
    reader.setMarker(helper.qr);
    reader.readBitIntensity(10, 11, intensity);
    // Make sure the expected number of points was read
    // If that changes you need to hunt down places '5' was hard coded. Sorry for that.
    assertEquals(1 + QrCodeBinaryGridReader.BIT_INTENSITY_SAMPLES, intensity.size);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) DogArray_F32(org.ddogleg.struct.DogArray_F32) Test(org.junit.jupiter.api.Test)

Aggregations

DogArray_F32 (org.ddogleg.struct.DogArray_F32)13 Test (org.junit.jupiter.api.Test)7 GrayF32 (boofcv.struct.image.GrayF32)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 ArrayList (java.util.ArrayList)2 PointCloudWriter (boofcv.alg.cloud.PointCloudWriter)1 DoNothingPixelTransform_F64 (boofcv.alg.distort.DoNothingPixelTransform_F64)1 Point3D_F64 (georegression.struct.point.Point3D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DogArray_I32 (org.ddogleg.struct.DogArray_I32)1 VerbosePrint (org.ddogleg.struct.VerbosePrint)1