public static void fullViewLeft(int imageWidth,int imageHeight, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight ) { Point2Transform2_F32 tranLeft = new PointTransformHomography_F32(rectifyLeft); RectangleLength2D_F32 bound = DistortImageOps.boundBox_F32(imageWidth, imageHeight, new PointToPixelTransform_F32(tranLeft)); float scaleX = imageWidth/bound.width; float scaleY = imageHeight/bound.height; float scale = (float)Math.min(scaleX,scaleY); adjustUncalibrated(rectifyLeft, rectifyRight, bound, scale); }
public static void allInsideLeft( int imageWidth,int imageHeight, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight ) { PointTransformHomography_F32 tranLeft = new PointTransformHomography_F32(rectifyLeft); RectangleLength2D_F32 bound = LensDistortionOps_F32.boundBoxInside(imageWidth, imageHeight, new PointToPixelTransform_F32(tranLeft)); float scaleX = imageWidth/(float)bound.width; float scaleY = imageHeight/(float)bound.height; float scale = (float)Math.max(scaleX, scaleY); adjustUncalibrated(rectifyLeft, rectifyRight, bound, scale); }
public static Point2Transform2_F32 transformPixelToRect(CameraPinholeRadial param, FMatrixRMaj rectify) { Point2Transform2_F32 remove_p_to_p = narrow(param).undistort_F32(true, true); PointTransformHomography_F32 rectifyDistort = new PointTransformHomography_F32(rectify); return new SequencePoint2Transform2_F32(remove_p_to_p,rectifyDistort); }
/** * <p> * Adjust the rectification such that only pixels which overlap the original left image can be seen. For use with * uncalibrated images with unknown baselines. Image processing is easier since only the "true" image pixels * are visible, but information along the image border has been discarded. The rectification matrices are * overwritten with adjusted values on output. * </p> * * @param imageWidth Width of left image. * @param imageHeight Height of left image. * @param rectifyLeft Rectification matrix for left image. Input and Output. Modified. * @param rectifyRight Rectification matrix for right image. Input and Output. Modified. */ public static void allInsideLeft( int imageWidth,int imageHeight, DenseMatrix64F rectifyLeft, DenseMatrix64F rectifyRight ) { Point2Transform2_F32 tranLeft = new PointTransformHomography_F32(rectifyLeft); RectangleLength2D_F32 bound = LensDistortionOps.boundBoxInside(imageWidth, imageHeight, new PointToPixelTransform_F32(tranLeft)); double scaleX = imageWidth/(double)bound.width; double scaleY = imageHeight/(double)bound.height; double scale = Math.max(scaleX, scaleY); adjustUncalibrated(rectifyLeft, rectifyRight, bound, scale); }
/** * <p> * Creates a transform that applies rectification to unrectified distorted pixels. * </p> * * @param param Intrinsic parameters. Not modified. * @param rectify Transform for rectifying the image. Not modified. * @return Transform from unrectified to rectified pixels */ public static Point2Transform2_F32 transformPixelToRect_F32(CameraPinholeRadial param, DenseMatrix64F rectify) { Point2Transform2_F32 remove_p_to_p = transformPoint(param).undistort_F32(true, true); PointTransformHomography_F32 rectifyPixel = new PointTransformHomography_F32(rectify); return new SequencePoint2Transform2_F32(remove_p_to_p,rectifyPixel); }
/** * <p> * Adjust the rectification such that the entire original left image can be seen. For use with * uncalibrated stereo images with unknown baseline. * </p> * * <p> * Input rectification matrices are overwritten with adjusted values on output. * </p> * * @param imageWidth Width of left image. * @param imageHeight Height of left image. * @param rectifyLeft Rectification matrix for left image. Input and Output. Modified. * @param rectifyRight Rectification matrix for right image. Input and Output. Modified. */ // TODO Delete this function? It should reasonably fill the old view in most non-pathological cases public static void fullViewLeft(int imageWidth,int imageHeight, DenseMatrix64F rectifyLeft, DenseMatrix64F rectifyRight ) { Point2Transform2_F32 tranLeft = new PointTransformHomography_F32(rectifyLeft); RectangleLength2D_F32 bound = DistortImageOps.boundBox_F32(imageWidth, imageHeight, new PointToPixelTransform_F32(tranLeft)); double scaleX = imageWidth/bound.width; double scaleY = imageHeight/bound.height; double scale = Math.min(scaleX,scaleY); adjustUncalibrated(rectifyLeft, rectifyRight, bound, scale); }
/** * 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); } }
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); }
public static Point2Transform2_F32 transformPixelToRectNorm(CameraPinholeRadial param, FMatrixRMaj rectify, FMatrixRMaj rectifyK) { if (rectifyK.get(0, 1) != 0) throw new IllegalArgumentException("Skew should be zero in rectified images"); Point2Transform2_F32 remove_p_to_p = narrow(param).undistort_F32(true, true); PointTransformHomography_F32 rectifyDistort = new PointTransformHomography_F32(rectify); PinholePtoN_F32 pixelToNorm = new PinholePtoN_F32(); pixelToNorm.set(rectifyK.get(0, 0), rectifyK.get(1, 1), rectifyK.get(0, 1), rectifyK.get(0, 2), rectifyK.get(1, 2)); return new SequencePoint2Transform2_F32(remove_p_to_p, rectifyDistort, pixelToNorm); }
/** * Creates an {@link ImageDistort} for rectifying an image given its rectification matrix. * Lens distortion is assumed to have been previously removed. * * @param rectify Transform for rectifying the image. * @param imageType Type of single band image the transform is to be applied to. * @return ImageDistort for rectifying the image. */ public static <T extends ImageGray> ImageDistort<T,T> rectifyImage( DenseMatrix64F rectify , BorderType borderType, Class<T> imageType) { boolean skip = borderType == BorderType.SKIP; if( skip ) { borderType = BorderType.EXTENDED; } InterpolatePixelS<T> interp = FactoryInterpolation.bilinearPixelS(imageType, borderType); DenseMatrix64F rectifyInv = new DenseMatrix64F(3,3); CommonOps.invert(rectify,rectifyInv); PointTransformHomography_F32 rectifyTran = new PointTransformHomography_F32(rectifyInv); // don't bother caching the results since it is likely to only be applied once and is cheap to compute ImageDistort<T,T> ret = FactoryDistort.distortSB(false, interp, imageType); ret.setRenderAll(!skip); ret.setModel(new PointToPixelTransform_F32(rectifyTran)); return ret; }
Point2Transform2_F32 des_p_to_n = desired.undistort_F32(true, false); 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); } else { PointTransformHomography_F32 adjust = new PointTransformHomography_F32(A_inv); return new SequencePoint2Transform2_F32(ori_to_des, adjust);
/** * Creates an {@link ImageDistort} for rectifying an image given its rectification matrix. * Lens distortion is assumed to have been previously removed. * * @param rectify Transform for rectifying the image. * @param imageType Type of single band image the transform is to be applied to. * @return ImageDistort for rectifying the image. */ public static <T extends ImageGray<T>> ImageDistort<T,T> rectifyImage( FMatrixRMaj rectify , BorderType borderType, Class<T> imageType) { boolean skip = borderType == BorderType.SKIP; if( skip ) { borderType = BorderType.EXTENDED; } InterpolatePixelS<T> interp = FactoryInterpolation.bilinearPixelS(imageType, borderType); FMatrixRMaj rectifyInv = new FMatrixRMaj(3,3); CommonOps_FDRM.invert(rectify,rectifyInv); PointTransformHomography_F32 rectifyTran = new PointTransformHomography_F32(rectifyInv); // don't bother caching the results since it is likely to only be applied once and is cheap to compute ImageDistort<T,T> ret = FactoryDistort.distortSB(false, interp, imageType); ret.setRenderAll(!skip); ret.setModel(new PointToPixelTransform_F32(rectifyTran)); return ret; }