/** * Specifies intrinsic camera parameters and the transform from world to camera. * @param distortion camera parameters * @param worldToCamera transform from world to camera */ public void configure(LensDistortionNarrowFOV distortion , Se3_F64 worldToCamera ) { this.worldToCamera = worldToCamera; normToPixel = distortion.distort_F64(false,true); }
/** * Specifies intrinsic camera parameters and the transform from world to camera. * @param distortion camera parameters * @param worldToCamera transform from world to camera */ public void configure(LensDistortionNarrowFOV distortion , Se3_F64 worldToCamera ) { this.worldToCamera = worldToCamera; normToPixel = distortion.distort_F64(false,true); }
/** * Specifies the intrinsic parameters. * @param distortion Intrinsic camera parameters */ public void setLensDistoriton(LensDistortionNarrowFOV distortion ) { pixelToNorm = distortion.undistort_F64(true,false); normToPixel = distortion.distort_F64(false, true); }
public static Point2D_F64 convertPixelToNorm(CameraModel param , Point2D_F64 pixel , Point2D_F64 norm ) { if( norm == null ) norm = new Point2D_F64(); Point2Transform2_F64 pixelToNorm = LensDistortionFactory.narrow(param).distort_F64(true, false); pixelToNorm.compute(pixel.x,pixel.y,norm); return norm; }
public static Point2D_F64 convertNormToPixel(CameraModel param , double x , double y , Point2D_F64 pixel ) { if( pixel == null ) pixel = new Point2D_F64(); Point2Transform2_F64 normToPixel = LensDistortionFactory.narrow(param).distort_F64(false,true); normToPixel.compute(x,y,pixel); return pixel; }
/** * <p> * Convenient function for converting from normalized image coordinates to the original image pixel coordinate. * If speed is a concern then {@link PinholeNtoP_F64} should be used instead. * </p> * * @param param Intrinsic camera parameters * @param x X-coordinate of normalized. * @param y Y-coordinate of normalized. * @param pixel Optional storage for output. If null a new instance will be declared. * @return pixel image coordinate */ public static Point2D_F64 convertNormToPixel(CameraPinholeRadial param , double x , double y , Point2D_F64 pixel ) { if( pixel == null ) pixel = new Point2D_F64(); Point2Transform2_F64 normToPixel = LensDistortionOps.transformPoint(param).distort_F64(false,true); normToPixel.compute(x,y,pixel); return pixel; }
/** * <p> * Convenient function for converting from original image pixel coordinate to normalized< image coordinates. * If speed is a concern then {@link PinholePtoN_F64} should be used instead. * </p> * * NOTE: norm and pixel can be the same instance. * * @param param Intrinsic camera parameters * @param pixel Pixel coordinate * @param norm Optional storage for output. If null a new instance will be declared. * @return normalized image coordinate */ public static Point2D_F64 convertPixelToNorm(CameraPinholeRadial param , Point2D_F64 pixel , Point2D_F64 norm ) { if( norm == null ) norm = new Point2D_F64(); Point2Transform2_F64 pixelToNorm = LensDistortionOps.transformPoint(param).distort_F64(true, false); pixelToNorm.compute(pixel.x,pixel.y,norm); return norm; }
public static Point2Transform2_F64 transformRectToPixel(CameraPinholeRadial param, DMatrixRMaj rectify) { Point2Transform2_F64 add_p_to_p = narrow(param).distort_F64(true, true); DMatrixRMaj rectifyInv = new DMatrixRMaj(3,3); CommonOps_DDRM.invert(rectify,rectifyInv); PointTransformHomography_F64 removeRect = new PointTransformHomography_F64(rectifyInv); return new SequencePoint2Transform2_F64(removeRect,add_p_to_p); }
@Override public void setLensDistortion(LensDistortionNarrowFOV distortion) { super.setLensDistortion(distortion); if( distortion == null ) { distToUndist = new DoNothing2Transform2_F64(); undistToDist = new DoNothing2Transform2_F64(); } else { poseEstimator.setLensDistoriton(distortion); distToUndist = distortion.undistort_F64(true, true); undistToDist = distortion.distort_F64(true, true); } }
/** * <p> * Creates a transform that goes from rectified to original distorted pixel coordinates. * Rectification includes removal of lens distortion. Used for rendering rectified images. * </p> * * @param param Intrinsic parameters. * @param rectify Transform for rectifying the image. * @return Transform from rectified to unrectified pixels */ public static Point2Transform2_F64 transformRectToPixel_F64(CameraPinholeRadial param, DenseMatrix64F rectify) { Point2Transform2_F64 add_p_to_p = transformPoint(param).distort_F64(true, true); DenseMatrix64F rectifyInv = new DenseMatrix64F(3,3); CommonOps.invert(rectify,rectifyInv); PointTransformHomography_F64 removeRect = new PointTransformHomography_F64(rectifyInv); return new SequencePoint2Transform2_F64(removeRect,add_p_to_p); }
/** * Given the lens distortion and the intrinsic adjustment matrix compute the new intrinsic parameters * and {@link Point2Transform2_F32} */ private static Point2Transform2_F64 adjustmentTransform_F64(CameraPinholeRadial param, CameraPinholeRadial paramAdj, boolean adjToDistorted, Point2Transform2_F64 remove_p_to_p, DenseMatrix64F A) { DenseMatrix64F A_inv = null; if( !adjToDistorted || paramAdj != null ) { A_inv = new DenseMatrix64F(3, 3); if (!CommonOps.invert(A, A_inv)) { throw new RuntimeException("Failed to invert adjustment matrix. Probably bad."); } } if( paramAdj != null ) { PerspectiveOps.adjustIntrinsic(param, A_inv, paramAdj); } if( adjToDistorted ) { Point2Transform2_F64 add_p_to_p = transformPoint(param).distort_F64(true, true); PointTransformHomography_F64 adjust = new PointTransformHomography_F64(A); return new SequencePoint2Transform2_F64(adjust,add_p_to_p); } else { PointTransformHomography_F64 adjust = new PointTransformHomography_F64(A_inv); return new SequencePoint2Transform2_F64(remove_p_to_p,adjust); } }
Point2Transform2_F64 add_p_to_p = LensDistortionFactory.narrow(intrinsic).distort_F64(true, true);
Point2Transform2_F64 des_n_to_p = desired.distort_F64(false, true); Point2Transform2_F64 ori_n_to_p = original.distort_F64(false, true); PointTransformHomography_F64 adjust = new PointTransformHomography_F64(A); return new SequencePoint2Transform2_F64(adjust,des_p_to_n,ori_n_to_p);
/** * Specifies the image's intrinsic parameters and target size * * @param distortion Lens distortion * @param width Image width * @param height Image height * @param cache If there's lens distortion should it cache the transforms? Speeds it up by about 12%. Ignored * if no lens distortion */ public void configure(LensDistortionNarrowFOV distortion, int width , int height , boolean cache ) { Point2Transform2_F32 pointSquareToInput; Point2Transform2_F32 pointDistToUndist = distortion.undistort_F32(true,true); Point2Transform2_F32 pointUndistToDist = distortion.distort_F32(true,true); PixelTransform2_F32 distToUndist = new PointToPixelTransform_F32(pointDistToUndist); PixelTransform2_F32 undistToDist = new PointToPixelTransform_F32(pointUndistToDist); if( cache ) { distToUndist = new PixelTransformCached_F32(width, height, distToUndist); undistToDist = new PixelTransformCached_F32(width, height, undistToDist); } squareDetector.setLensDistortion(width, height,distToUndist,undistToDist); pointSquareToInput = new SequencePoint2Transform2_F32(transformHomography,pointUndistToDist); // provide intrinsic camera parameters PixelTransform2_F32 squareToInput= new PointToPixelTransform_F32(pointSquareToInput); removePerspective.setModel(squareToInput); this.undistToDist = distortion.distort_F64(true,true); }