1212#include < aliceVision/image/Image.hpp>
1313#include < aliceVision/image/io.hpp>
1414#include < aliceVision/image/Sampler.hpp>
15+ #include < aliceVision/image/remap.hpp>
16+ #include < aliceVision/camera/IntrinsicScaleOffsetDisto.hpp>
1517#include < boost/program_options.hpp>
1618
1719// These constants define the current software version.
@@ -96,8 +98,7 @@ void ImageIntrinsicsTransform(const image::Image<T>& imageIn,
9698 yOffset = roi.ybegin ;
9799 }
98100
99- image_ud.resize (widthRoi, heightRoi, true , fillcolor);
100- const image::Sampler2d<image::SamplerLinear> sampler;
101+ image::Image<Vec2> map (widthRoi, heightRoi);
101102
102103#pragma omp parallel for
103104 for (int y = 0 ; y < heightRoi; ++y)
@@ -108,15 +109,41 @@ void ImageIntrinsicsTransform(const image::Image<T>& imageIn,
108109
109110 // compute coordinates with distortion
110111 const Vec3 intermediate = intrinsicOutput.backProjectUnit (undisto_pix);
111- const Vec2 disto_pix = intrinsicSource.project (intermediate.homogeneous (), true );
112+ map (y, x) = intrinsicSource.project (intermediate.homogeneous (), true );
113+ }
114+ }
112115
113- // pick pixel if it is in the image domain
114- if (imageIn.contains (disto_pix (1 ), disto_pix (0 )))
115- {
116- image_ud (y, x) = sampler (imageIn, disto_pix (1 ), disto_pix (0 ));
117- }
116+ remapInter (imageIn, map, fillcolor, image_ud);
117+ }
118+
119+ bool isFullComputeNeeded (const camera::IntrinsicBase & source, const camera::IntrinsicBase & dest)
120+ {
121+ // Is the output undistorted
122+ if (dest.hasDistortion ())
123+ {
124+ return true ;
125+ }
126+
127+ // Do we need to cast to a different intrinsic type ?
128+ if (source.getType () != dest.getType ())
129+ {
130+ return true ;
131+ }
132+
133+ // Are the "non distortion" parameters equal ?
134+ try
135+ {
136+ const auto & isod = dynamic_cast <const camera::IntrinsicScaleOffsetDisto&>(source);
137+ if (!isod.equalTo (dest, true ))
138+ {
139+ return true ;
118140 }
119141 }
142+ catch (const std::bad_cast& e)
143+ {
144+ }
145+
146+ return false ;
120147}
121148
122149template <typename T>
@@ -260,17 +287,18 @@ bool processImage(const std::string& dstFileName,
260287 roi = convertRodToRoi (outputIntrinsic, rod);
261288 }
262289
263- bool shortCut = (sourceIntrinsic.getType () == outputIntrinsic.getType ()) &&
264- (outputIntrinsic.hasDistortion () == false );
265- if (shortCut)
290+ // Guess if we can accelerate stuff
291+ if (isFullComputeNeeded (sourceIntrinsic, outputIntrinsic))
266292 {
267- // undistort the image and save it
268- ImageRemoveDistortion (image, sourceIntrinsic, outputIntrinsic, image_ud, image::RGBAfColor (0.0 ), rod);
293+ // Transform the image and save it
294+ ALICEVISION_LOG_INFO (" Using full complex transform." );
295+ ImageIntrinsicsTransform (image, sourceIntrinsic, outputIntrinsic, image_ud, image::RGBAfColor (0.0 ), rod);
269296 }
270297 else
271298 {
272- // Transform the image and save it
273- ImageIntrinsicsTransform (image, sourceIntrinsic, outputIntrinsic, image_ud, image::RGBAfColor (0.0 ), rod);
299+ // undistort the image and save it
300+ ALICEVISION_LOG_INFO (" Using Simplified undistortion transform." );
301+ ImageRemoveDistortion (image, sourceIntrinsic, outputIntrinsic, image_ud, image::RGBAfColor (0.0 ), rod);
274302 }
275303
276304 // Write the result
0 commit comments