Skip to content

Commit 567e42c

Browse files
committed
1.2025.01.20: dewarp: refix horizontal barreling from STD#5
1 parent 5055cf4 commit 567e42c

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/dewarping/CylindricalSurfaceDewarper.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ CylindricalSurfaceDewarper::CylindricalSurfaceDewarper(
109109
, m_directrixArcLength(1.0)
110110
, m_imgDirectrix1Intersector(img_directrix1)
111111
, m_imgDirectrix2Intersector(img_directrix2)
112-
, m_h_w(1.0)
113112
{
114113
initArcLengthMapper(img_directrix1, img_directrix2);
115114
}
@@ -242,14 +241,6 @@ CylindricalSurfaceDewarper::calcPlnToImgHomography(
242241
QPointF const tr = img_directrix1.back();
243242
QPointF const bl = img_directrix2.front();
244243
QPointF const br = img_directrix2.back();
245-
QPointF const top = tr - tl;
246-
QPointF const bottom = br - bl;
247-
QPointF const left = bl - tl;
248-
QPointF const right = br - tr;
249-
double const width2 = QPointF::dotProduct(top, top) + QPointF::dotProduct(bottom, bottom);
250-
double const height2 = QPointF::dotProduct(left, left) + QPointF::dotProduct(right, right);
251-
double const h_w_2 = (width2 > 0.0) ? (height2 / width2) : 1.0;
252-
m_h_w = sqrt(h_w_2);
253244

254245
boost::array<std::pair<QPointF, QPointF>, 4> pairs;
255246
pairs[0] = std::make_pair(QPointF(0, 0), tl);
@@ -380,6 +371,13 @@ CylindricalSurfaceDewarper::initArcLengthMapper(
380371
QPointF img_curve2_pt;
381372
double prev_pln_x = NumericTraits<double>::min();
382373
double pln_x;
374+
375+
Matrix<double, 3, 3> const& coeff = m_pln2img.mat();
376+
double const cm0 = coeff(2, 0) * coeff(2, 0);
377+
double const cm1 = coeff(2, 1) * coeff(2, 1);
378+
double const cnorm = cm0 + cm1;
379+
double const coeff_h_w = (cnorm > 0.0) ? (cm1 / cnorm) : 1.0;
380+
383381
while (it.next(img_curve1_pt, img_curve2_pt, pln_x))
384382
{
385383
if (pln_x <= prev_pln_x)
@@ -398,11 +396,10 @@ CylindricalSurfaceDewarper::initArcLengthMapper(
398396
double const y1 = projector.projectionScalar(img_line1_pt);
399397
double const y2 = projector.projectionScalar(img_line2_pt);
400398

401-
double const bx = 0.5 * ((y2 + y1) - 1.0) * m_h_w;
399+
double const bx = 0.5 * ((y2 + y1) - 1.0) * coeff_h_w;
402400
double const by = 1.0 - (y2 - y1);
403-
double const bb = 0.5 / sqrt(1.0 + bx * bx + by * by);
404-
double const bxy = (bx + by) * bb;
405-
double elevation = m_depthPerception * bxy;
401+
double const bxy = bx + by;
402+
double elevation = m_depthPerception / (1.0 + coeff_h_w) * bxy;
406403
elevation = qBound(-0.5, elevation, 0.5);
407404

408405
m_arcLengthMapper.addSample(pln_x, elevation);

src/dewarping/CylindricalSurfaceDewarper.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class DEWARPING_EXPORT CylindricalSurfaceDewarper
108108
private:
109109
class CoupledPolylinesIterator;
110110

111-
HomographicTransform<2, double> calcPlnToImgHomography(
111+
static HomographicTransform<2, double> calcPlnToImgHomography(
112112
std::vector<QPointF> const& img_directrix1,
113113
std::vector<QPointF> const& img_directrix2);
114114

@@ -138,7 +138,6 @@ class DEWARPING_EXPORT CylindricalSurfaceDewarper
138138
ArcLengthMapper m_arcLengthMapper;
139139
PolylineIntersector m_imgDirectrix1Intersector;
140140
PolylineIntersector m_imgDirectrix2Intersector;
141-
double m_h_w;
142141
};
143142

144143
} // namespace dewarping

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
#define SCANTAILOR_VERSION_H_
2121

2222
#define STFAMILY "experimental"
23-
#define VERSION "1.2025.01.18" // Must be "x.x.x.x" or an empty string.
23+
#define VERSION "1.2025.01.20" // Must be "x.x.x.x" or an empty string.
2424

2525
#endif

0 commit comments

Comments
 (0)