Search in sources :

Example 76 with AssociatedPair

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

the class ExampleFundamentalMatrix method computeMatches.

/**
 * Use the associate point feature example to create a list of {@link AssociatedPair} for use in computing the
 * fundamental matrix.
 */
public static List<AssociatedPair> computeMatches(BufferedImage left, BufferedImage right) {
    DetectDescribePoint detDesc = FactoryDetectDescribe.surfStable(new ConfigFastHessian(1, 2, 200, 1, 9, 4, 4), null, null, GrayF32.class);
    // DetectDescribePoint detDesc = FactoryDetectDescribe.sift(null,new ConfigSiftDetector(2,0,200,5),null,null);
    ScoreAssociation<BrightFeature> scorer = FactoryAssociation.scoreEuclidean(BrightFeature.class, true);
    AssociateDescription<BrightFeature> associate = FactoryAssociation.greedy(scorer, 1, true);
    ExampleAssociatePoints<GrayF32, BrightFeature> findMatches = new ExampleAssociatePoints<>(detDesc, associate, GrayF32.class);
    findMatches.associate(left, right);
    List<AssociatedPair> matches = new ArrayList<>();
    FastQueue<AssociatedIndex> matchIndexes = associate.getMatches();
    for (int i = 0; i < matchIndexes.size; i++) {
        AssociatedIndex a = matchIndexes.get(i);
        AssociatedPair p = new AssociatedPair(findMatches.pointsA.get(a.src), findMatches.pointsB.get(a.dst));
        matches.add(p);
    }
    return matches;
}
Also used : DetectDescribePoint(boofcv.abst.feature.detdesc.DetectDescribePoint) AssociatedPair(boofcv.struct.geo.AssociatedPair) ConfigFastHessian(boofcv.abst.feature.detect.interest.ConfigFastHessian) ArrayList(java.util.ArrayList) DetectDescribePoint(boofcv.abst.feature.detdesc.DetectDescribePoint) BrightFeature(boofcv.struct.feature.BrightFeature) GrayF32(boofcv.struct.image.GrayF32) ExampleAssociatePoints(boofcv.examples.features.ExampleAssociatePoints) AssociatedIndex(boofcv.struct.feature.AssociatedIndex)

Example 77 with AssociatedPair

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

the class ExampleRectifyUncalibratedStereo method main.

public static void main(String[] args) {
    // Load images with lens distortion removed.  If lens distortion has not been
    // removed then the results will be approximate
    String dir = UtilIO.pathExample("stereo/");
    BufferedImage imageA = UtilImageIO.loadImage(dir, "mono_wall_01_undist.jpg");
    BufferedImage imageB = UtilImageIO.loadImage(dir, "mono_wall_03_undist.jpg");
    // Find a set of point feature matches
    List<AssociatedPair> matches = ExampleFundamentalMatrix.computeMatches(imageA, imageB);
    // Prune matches using the epipolar constraint
    List<AssociatedPair> inliers = new ArrayList<>();
    DMatrixRMaj F = ExampleFundamentalMatrix.robustFundamental(matches, inliers);
    // display the inlier matches found using the robust estimator
    AssociationPanel panel = new AssociationPanel(20);
    panel.setAssociation(inliers);
    panel.setImages(imageA, imageB);
    ShowImages.showWindow(panel, "Inlier Pairs");
    rectify(F, inliers, imageA, imageB);
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) ArrayList(java.util.ArrayList) DMatrixRMaj(org.ejml.data.DMatrixRMaj) AssociationPanel(boofcv.gui.feature.AssociationPanel) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 78 with AssociatedPair

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

the class ExampleStereoTwoViewsOneCamera method drawInliers.

/**
 * Draw inliers for debugging purposes.  Need to convert from normalized to pixel coordinates.
 */
public static void drawInliers(BufferedImage left, BufferedImage right, CameraPinholeRadial intrinsic, List<AssociatedPair> normalized) {
    Point2Transform2_F64 n_to_p = LensDistortionOps.narrow(intrinsic).distort_F64(false, true);
    List<AssociatedPair> pixels = new ArrayList<>();
    for (AssociatedPair n : normalized) {
        AssociatedPair p = new AssociatedPair();
        n_to_p.compute(n.p1.x, n.p1.y, p.p1);
        n_to_p.compute(n.p2.x, n.p2.y, p.p2);
        pixels.add(p);
    }
    // display the results
    AssociationPanel panel = new AssociationPanel(20);
    panel.setAssociation(pixels);
    panel.setImages(left, right);
    ShowImages.showWindow(panel, "Inlier Features");
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) ArrayList(java.util.ArrayList) AssociationPanel(boofcv.gui.feature.AssociationPanel)

Example 79 with AssociatedPair

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

the class ExampleStereoTwoViewsOneCamera method main.

public static void main(String[] args) {
    // specify location of images and calibration
    String calibDir = UtilIO.pathExample("calibration/mono/Sony_DSC-HX5V_Chess/");
    String imageDir = UtilIO.pathExample("stereo/");
    // Camera parameters
    CameraPinholeRadial intrinsic = CalibrationIO.load(new File(calibDir, "intrinsic.yaml"));
    // Input images from the camera moving left to right
    BufferedImage origLeft = UtilImageIO.loadImage(imageDir, "mono_wall_01.jpg");
    BufferedImage origRight = UtilImageIO.loadImage(imageDir, "mono_wall_02.jpg");
    // Input images with lens distortion
    GrayU8 distortedLeft = ConvertBufferedImage.convertFrom(origLeft, (GrayU8) null);
    GrayU8 distortedRight = ConvertBufferedImage.convertFrom(origRight, (GrayU8) null);
    // matched features between the two images
    List<AssociatedPair> matchedFeatures = ExampleFundamentalMatrix.computeMatches(origLeft, origRight);
    // convert from pixel coordinates into normalized image coordinates
    List<AssociatedPair> matchedCalibrated = convertToNormalizedCoordinates(matchedFeatures, intrinsic);
    // Robustly estimate camera motion
    List<AssociatedPair> inliers = new ArrayList<>();
    Se3_F64 leftToRight = estimateCameraMotion(intrinsic, matchedCalibrated, inliers);
    drawInliers(origLeft, origRight, intrinsic, inliers);
    // Rectify and remove lens distortion for stereo processing
    DMatrixRMaj rectifiedK = new DMatrixRMaj(3, 3);
    GrayU8 rectifiedLeft = distortedLeft.createSameShape();
    GrayU8 rectifiedRight = distortedRight.createSameShape();
    rectifyImages(distortedLeft, distortedRight, leftToRight, intrinsic, rectifiedLeft, rectifiedRight, rectifiedK);
    // compute disparity
    StereoDisparity<GrayS16, GrayF32> disparityAlg = FactoryStereoDisparity.regionSubpixelWta(DisparityAlgorithms.RECT_FIVE, minDisparity, maxDisparity, 5, 5, 20, 1, 0.1, GrayS16.class);
    // Apply the Laplacian across the image to add extra resistance to changes in lighting or camera gain
    GrayS16 derivLeft = new GrayS16(rectifiedLeft.width, rectifiedLeft.height);
    GrayS16 derivRight = new GrayS16(rectifiedLeft.width, rectifiedLeft.height);
    LaplacianEdge.process(rectifiedLeft, derivLeft);
    LaplacianEdge.process(rectifiedRight, derivRight);
    // process and return the results
    disparityAlg.process(derivLeft, derivRight);
    GrayF32 disparity = disparityAlg.getDisparity();
    // show results
    BufferedImage visualized = VisualizeImageData.disparity(disparity, null, minDisparity, maxDisparity, 0);
    BufferedImage outLeft = ConvertBufferedImage.convertTo(rectifiedLeft, null);
    BufferedImage outRight = ConvertBufferedImage.convertTo(rectifiedRight, null);
    ShowImages.showWindow(new RectifiedPairPanel(true, outLeft, outRight), "Rectification");
    ShowImages.showWindow(visualized, "Disparity");
    showPointCloud(disparity, outLeft, leftToRight, rectifiedK, minDisparity, maxDisparity);
    System.out.println("Total found " + matchedCalibrated.size());
    System.out.println("Total Inliers " + inliers.size());
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) GrayS16(boofcv.struct.image.GrayS16) ArrayList(java.util.ArrayList) DMatrixRMaj(org.ejml.data.DMatrixRMaj) RectifiedPairPanel(boofcv.gui.stereo.RectifiedPairPanel) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) GrayU8(boofcv.struct.image.GrayU8) File(java.io.File) Se3_F64(georegression.struct.se.Se3_F64)

Example 80 with AssociatedPair

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

the class TestDistanceHomographySq method createRandomData.

@Override
public AssociatedPair createRandomData() {
    Point2D_F64 p1 = new Point2D_F64(rand.nextGaussian(), rand.nextGaussian());
    Point2D_F64 p2 = new Point2D_F64(rand.nextGaussian(), rand.nextGaussian());
    return new AssociatedPair(p1, p2, false);
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point2D_F64(georegression.struct.point.Point2D_F64)

Aggregations

AssociatedPair (boofcv.struct.geo.AssociatedPair)110 Test (org.junit.Test)32 Point2D_F64 (georegression.struct.point.Point2D_F64)28 ArrayList (java.util.ArrayList)27 DMatrixRMaj (org.ejml.data.DMatrixRMaj)22 Se3_F64 (georegression.struct.se.Se3_F64)17 Point3D_F64 (georegression.struct.point.Point3D_F64)12 ScaleTranslate2D (boofcv.struct.sfm.ScaleTranslate2D)7 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)6 Estimate1ofEpipolar (boofcv.abst.geo.Estimate1ofEpipolar)5 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)4 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)4 ScaleTranslateRotate2D (boofcv.struct.sfm.ScaleTranslateRotate2D)4 ClosestPoint3D_F64 (georegression.metric.ClosestPoint3D_F64)4 ConfigFastHessian (boofcv.abst.feature.detect.interest.ConfigFastHessian)3 TriangulateTwoViewsCalibrated (boofcv.abst.geo.TriangulateTwoViewsCalibrated)3 AssociationPanel (boofcv.gui.feature.AssociationPanel)3 BrightFeature (boofcv.struct.feature.BrightFeature)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Ransac (org.ddogleg.fitting.modelset.ransac.Ransac)3