public static Point2D_F32 convertNormToPixel(CameraModel param , float x , float y , Point2D_F32 pixel ) { if( pixel == null ) pixel = new Point2D_F32(); Point2Transform2_F32 normToPixel = LensDistortionFactory.narrow(param).distort_F32(false,true); normToPixel.compute(x,y,pixel); return pixel; }
public static Point2D_F32 convertPixelToNorm(CameraModel param , Point2D_F32 pixel , Point2D_F32 norm ) { if( norm == null ) norm = new Point2D_F32(); Point2Transform2_F32 pixelToNorm = LensDistortionFactory.narrow(param).distort_F32(true, false); pixelToNorm.compute(pixel.x,pixel.y,norm); return norm; }
/** * <p> * Convenient function for converting from normalized image coordinates to the original image pixel coordinate. * If speed is a concern then {@link PinholeNtoP_F32} 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_F32 convertNormToPixel(CameraPinholeRadial param , float x , float y , Point2D_F32 pixel ) { if( pixel == null ) pixel = new Point2D_F32(); Point2Transform2_F32 normToPixel = LensDistortionOps.transformPoint(param).distort_F32(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_F32} 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_F32 convertPixelToNorm(CameraPinholeRadial param , Point2D_F32 pixel , Point2D_F32 norm ) { if( norm == null ) norm = new Point2D_F32(); Point2Transform2_F32 pixelToNorm = LensDistortionOps.transformPoint(param).distort_F32(true, false); pixelToNorm.compute(pixel.x,pixel.y,norm); return norm; }
public static Point2Transform2_F32 transformRectToPixel(CameraPinholeRadial param, FMatrixRMaj rectify) { Point2Transform2_F32 add_p_to_p = narrow(param).distort_F32(true, true); FMatrixRMaj rectifyInv = new FMatrixRMaj(3,3); CommonOps_FDRM.invert(rectify,rectifyInv); PointTransformHomography_F32 removeRect = new PointTransformHomography_F32(rectifyInv); return new SequencePoint2Transform2_F32(removeRect,add_p_to_p); }
/** * <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_F32 transformRectToPixel_F32(CameraPinholeRadial param, DenseMatrix64F rectify) { Point2Transform2_F32 add_p_to_p = transformPoint(param).distort_F32(true, true); DenseMatrix64F rectifyInv = new DenseMatrix64F(3,3); CommonOps.invert(rectify,rectifyInv); PointTransformHomography_F32 removeRect = new PointTransformHomography_F32(rectifyInv); return new SequencePoint2Transform2_F32(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_F32 adjustmentTransform_F32(CameraPinholeRadial param, CameraPinholeRadial paramAdj, boolean undistToDist, Point2Transform2_F32 remove_p_to_p, DenseMatrix64F A) { DenseMatrix64F A_inv = null; if( !undistToDist || 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( undistToDist ) { Point2Transform2_F32 add_p_to_p = transformPoint(param).distort_F32(true, true); PointTransformHomography_F32 adjust = new PointTransformHomography_F32(A); return new SequencePoint2Transform2_F32(adjust,add_p_to_p); } else { PointTransformHomography_F32 adjust = new PointTransformHomography_F32(A_inv); return new SequencePoint2Transform2_F32(remove_p_to_p,adjust); } }
Point2Transform2_F32 des_n_to_p = desired.distort_F32(false, true); Point2Transform2_F32 ori_n_to_p = original.distort_F32(false, true); PointTransformHomography_F32 adjust = new PointTransformHomography_F32(A); return new SequencePoint2Transform2_F32(adjust,des_p_to_n,ori_n_to_p);
undistToDist = transformPoint(param).distort_F32(true, true); break;
/** * 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); }