Skip to content

Commit a97b6e9

Browse files
author
Fabien Servant
committed
Update exportImages to handle potential large scale changes
1 parent d8d2022 commit a97b6e9

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

src/aliceVision/camera/IntrinsicScaleOffsetDisto.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ std::shared_ptr<IntrinsicScaleOffsetDisto> IntrinsicScaleOffsetDisto::cast(std::
1515
}
1616

1717
bool IntrinsicScaleOffsetDisto::operator==(const IntrinsicBase& otherBase) const
18+
{
19+
return equalTo(otherBase, false);
20+
}
21+
22+
bool IntrinsicScaleOffsetDisto::equalTo(const IntrinsicBase& otherBase, bool ignoreDistortion) const
1823
{
1924
if (!IntrinsicScaleOffset::operator==(otherBase))
2025
{
@@ -26,6 +31,11 @@ bool IntrinsicScaleOffsetDisto::operator==(const IntrinsicBase& otherBase) const
2631
return false;
2732
}
2833

34+
if (ignoreDistortion)
35+
{
36+
return true;
37+
}
38+
2939
const IntrinsicScaleOffsetDisto& other = static_cast<const IntrinsicScaleOffsetDisto&>(otherBase);
3040

3141
if (_distortionInitializationMode != other._distortionInitializationMode)

src/aliceVision/camera/IntrinsicScaleOffsetDisto.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,21 @@ class IntrinsicScaleOffsetDisto : public IntrinsicScaleOffset
6363

6464
void assign(const IntrinsicBase& other) override { *this = dynamic_cast<const IntrinsicScaleOffsetDisto&>(other); }
6565

66+
/**
67+
* @brief compare to another intrinsic object
68+
* @param otherBase an intrinsic object to compare to.
69+
* @return true if both objects are considered equal
70+
*/
6671
bool operator==(const IntrinsicBase& otherBase) const override;
6772

73+
/**
74+
* @brief compare to another intrinsic object
75+
* @param otherBase an intrinsic object to compare to.
76+
* @param ignoreDistortion ignore difference in distortion.
77+
* @return true if both objects are considered equal
78+
*/
79+
bool equalTo(const IntrinsicBase& otherBase, bool ignoreDistortion) const;
80+
6881
void setDistortionObject(std::shared_ptr<Distortion> object) { _pDistortion = object; }
6982

7083
bool hasDistortion() const override { return _pDistortion != nullptr || _pUndistortion != nullptr; }

src/software/utils/main_exportImages.cpp

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
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

122149
template<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

Comments
 (0)