Skip to content

Commit bf2f7b0

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 27edba4 + 84c29dc commit bf2f7b0

File tree

13 files changed

+593
-82
lines changed

13 files changed

+593
-82
lines changed

cmake/checks/cpu_vsx_asm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ int main()
1616
{
1717
__vector float vf;
1818
__vector signed int vi;
19-
__asm__ __volatile__ ("xvcvsxwsp %x0,%x1" : "=wf" (vf) : "wa" (vi));
19+
__asm__ __volatile__ ("xvcvsxwsp %x0,%x1" : "=wa" (vf) : "wa" (vi));
2020
return 0;
2121
}

doc/tutorials/features2d/homography/homography.markdown

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ For detailed explanations about the theory, please refer to a computer vision co
1212
* An Invitation to 3-D Vision: From Images to Geometric Models, @cite Ma:2003:IVI
1313
* Computer Vision: Algorithms and Applications, @cite RS10
1414

15-
The tutorial code can be found [here](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/features2D/Homography).
15+
The tutorial code can be found here [C++](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/features2D/Homography),
16+
[Python](https://github.com/opencv/opencv/tree/master/samples/python/tutorial_code/features2D/Homography),
17+
[Java](https://github.com/opencv/opencv/tree/master/samples/java/tutorial_code/features2D/Homography).
1618
The images used in this tutorial can be found [here](https://github.com/opencv/opencv/tree/master/samples/data) (`left*.jpg`).
1719

1820
Basic theory {#tutorial_homography_Basic_theory}
@@ -171,23 +173,63 @@ The following image shows the source image (left) and the chessboard view that w
171173

172174
The first step consists to detect the chessboard corners in the source and desired images:
173175

176+
@add_toggle_cpp
174177
@snippet perspective_correction.cpp find-corners
178+
@end_toggle
179+
180+
@add_toggle_python
181+
@snippet samples/python/tutorial_code/features2D/Homography/perspective_correction.py find-corners
182+
@end_toggle
183+
184+
@add_toggle_java
185+
@snippet samples/java/tutorial_code/features2D/Homography/PerspectiveCorrection.java find-corners
186+
@end_toggle
175187

176188
The homography is estimated easily with:
177189

190+
@add_toggle_cpp
178191
@snippet perspective_correction.cpp estimate-homography
192+
@end_toggle
193+
194+
@add_toggle_python
195+
@snippet samples/python/tutorial_code/features2D/Homography/perspective_correction.py estimate-homography
196+
@end_toggle
197+
198+
@add_toggle_java
199+
@snippet samples/java/tutorial_code/features2D/Homography/PerspectiveCorrection.java estimate-homography
200+
@end_toggle
179201

180202
To warp the source chessboard view into the desired chessboard view, we use @ref cv::warpPerspective
181203

204+
@add_toggle_cpp
182205
@snippet perspective_correction.cpp warp-chessboard
206+
@end_toggle
207+
208+
@add_toggle_python
209+
@snippet samples/python/tutorial_code/features2D/Homography/perspective_correction.py warp-chessboard
210+
@end_toggle
211+
212+
@add_toggle_java
213+
@snippet samples/java/tutorial_code/features2D/Homography/PerspectiveCorrection.java warp-chessboard
214+
@end_toggle
183215

184216
The result image is:
185217

186218
![](images/homography_perspective_correction_chessboard_warp.jpg)
187219

188220
To compute the coordinates of the source corners transformed by the homography:
189221

222+
@add_toggle_cpp
190223
@snippet perspective_correction.cpp compute-transformed-corners
224+
@end_toggle
225+
226+
@add_toggle_python
227+
@snippet samples/python/tutorial_code/features2D/Homography/perspective_correction.py compute-transformed-corners
228+
@end_toggle
229+
230+
@add_toggle_java
231+
@snippet samples/java/tutorial_code/features2D/Homography/PerspectiveCorrection.java compute-transformed-corners
232+
@end_toggle
191233

192234
To check the correctness of the calculation, the matching lines are displayed:
193235

@@ -499,17 +541,57 @@ The figure below shows the two generated views of the Suzanne model, with only a
499541

500542
With the known associated camera poses and the intrinsic parameters, the relative rotation between the two views can be computed:
501543

544+
@add_toggle_cpp
502545
@snippet panorama_stitching_rotating_camera.cpp extract-rotation
546+
@end_toggle
503547

548+
@add_toggle_python
549+
@snippet samples/python/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.py extract-rotation
550+
@end_toggle
551+
552+
@add_toggle_java
553+
@snippet samples/java/tutorial_code/features2D/Homography/PanoramaStitchingRotatingCamera.java extract-rotation
554+
@end_toggle
555+
556+
@add_toggle_cpp
504557
@snippet panorama_stitching_rotating_camera.cpp compute-rotation-displacement
558+
@end_toggle
559+
560+
@add_toggle_python
561+
@snippet samples/python/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.py compute-rotation-displacement
562+
@end_toggle
563+
564+
@add_toggle_java
565+
@snippet samples/java/tutorial_code/features2D/Homography/PanoramaStitchingRotatingCamera.java compute-rotation-displacement
566+
@end_toggle
505567

506568
Here, the second image will be stitched with respect to the first image. The homography can be calculated using the formula above:
507569

570+
@add_toggle_cpp
508571
@snippet panorama_stitching_rotating_camera.cpp compute-homography
572+
@end_toggle
573+
574+
@add_toggle_python
575+
@snippet samples/python/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.py compute-homography
576+
@end_toggle
577+
578+
@add_toggle_java
579+
@snippet samples/java/tutorial_code/features2D/Homography/PanoramaStitchingRotatingCamera.java compute-homography
580+
@end_toggle
509581

510582
The stitching is made simply with:
511583

584+
@add_toggle_cpp
512585
@snippet panorama_stitching_rotating_camera.cpp stitch
586+
@end_toggle
587+
588+
@add_toggle_python
589+
@snippet samples/python/tutorial_code/features2D/Homography/panorama_stitching_rotating_camera.py stitch
590+
@end_toggle
591+
592+
@add_toggle_java
593+
@snippet samples/java/tutorial_code/features2D/Homography/PanoramaStitchingRotatingCamera.java stitch
594+
@end_toggle
513595

514596
The resulting image is:
515597

modules/calib3d/include/opencv2/calib3d.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,18 @@ v = f_y \times y'' + c_y
118118
tangential distortion coefficients. \f$s_1\f$, \f$s_2\f$, \f$s_3\f$, and \f$s_4\f$, are the thin prism distortion
119119
coefficients. Higher-order coefficients are not considered in OpenCV.
120120
121-
The next figures show two common types of radial distortion: barrel distortion (typically \f$ k_1 < 0 \f$) and pincushion distortion (typically \f$ k_1 > 0 \f$).
121+
The next figures show two common types of radial distortion: barrel distortion
122+
(\f$ 1 + k_1 r^2 + k_2 r^4 + k_3 r^6 \f$ monotonically decreasing)
123+
and pincushion distortion (\f$ 1 + k_1 r^2 + k_2 r^4 + k_3 r^6 \f$ monotonically increasing).
124+
Radial distortion is always monotonic for real lenses,
125+
and if the estimator produces a non monotonic result,
126+
this should be considered a calibration failure.
127+
More generally, radial distortion must be monotonic and the distortion function, must be bijective.
128+
A failed estimation result may look deceptively good near the image center
129+
but will work poorly in e.g. AR/SFM applications.
130+
The optimization method used in OpenCV camera calibration does not include these constraints as
131+
the framework does not support the required integer programming and polynomial inequalities.
132+
See [issue #15992](https://github.com/opencv/opencv/issues/15992) for additional information.
122133
123134
![](pics/distortion_examples.png)
124135
![](pics/distortion_examples2.png)

modules/core/include/opencv2/core/cvdef.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ namespace cv {
167167
#undef abs
168168
#undef Complex
169169

170+
#if defined __cplusplus
171+
#include <limits>
172+
#else
170173
#include <limits.h>
174+
#endif
175+
171176
#include "opencv2/core/hal/interface.h"
172177

173178
#if defined __ICL

modules/core/include/opencv2/core/hal/intrin_vsx.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ inline v_float32x4 v_load_expand(const float16_t* ptr)
13381338
return v_float32x4(vec_extract_fp_from_shorth(vf16));
13391339
#elif CV_VSX3 && !defined(CV_COMPILER_VSX_BROKEN_ASM)
13401340
vec_float4 vf32;
1341-
__asm__ __volatile__ ("xvcvhpsp %x0,%x1" : "=wf" (vf32) : "wa" (vec_mergeh(vf16, vf16)));
1341+
__asm__ __volatile__ ("xvcvhpsp %x0,%x1" : "=wa" (vf32) : "wa" (vec_mergeh(vf16, vf16)));
13421342
return v_float32x4(vf32);
13431343
#else
13441344
const vec_int4 z = vec_int4_z, delta = vec_int4_sp(0x38000000);
@@ -1363,7 +1363,7 @@ inline void v_pack_store(float16_t* ptr, const v_float32x4& v)
13631363
// fixme: Is there any builtin op or intrinsic that cover "xvcvsphp"?
13641364
#if CV_VSX3 && !defined(CV_COMPILER_VSX_BROKEN_ASM)
13651365
vec_ushort8 vf16;
1366-
__asm__ __volatile__ ("xvcvsphp %x0,%x1" : "=wa" (vf16) : "wf" (v.val));
1366+
__asm__ __volatile__ ("xvcvsphp %x0,%x1" : "=wa" (vf16) : "wa" (v.val));
13671367
vec_st_l8(vec_mergesqe(vf16, vf16), ptr);
13681368
#else
13691369
const vec_int4 signmask = vec_int4_sp(0x80000000);

modules/core/include/opencv2/core/types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ _Tp Point_<_Tp>::dot(const Point_& pt) const
12151215
template<typename _Tp> inline
12161216
double Point_<_Tp>::ddot(const Point_& pt) const
12171217
{
1218-
return (double)x*pt.x + (double)y*pt.y;
1218+
return (double)x*(double)(pt.x) + (double)y*(double)(pt.y);
12191219
}
12201220

12211221
template<typename _Tp> inline

modules/core/include/opencv2/core/vsx_utils.hpp

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ VSX_FINLINE(rt) fnm(const rg& a, const rg& b) { return fn2(a, b); }
110110
#if defined(__GNUG__) && !defined(__clang__)
111111

112112
// inline asm helper
113-
#define VSX_IMPL_1RG(rt, rto, rg, rgo, opc, fnm) \
114-
VSX_FINLINE(rt) fnm(const rg& a) \
115-
{ rt rs; __asm__ __volatile__(#opc" %x0,%x1" : "="#rto (rs) : #rgo (a)); return rs; }
113+
#define VSX_IMPL_1RG(rt, rg, opc, fnm) \
114+
VSX_FINLINE(rt) fnm(const rg& a) \
115+
{ rt rs; __asm__ __volatile__(#opc" %x0,%x1" : "=wa" (rs) : "wa" (a)); return rs; }
116116

117117
#define VSX_IMPL_1VRG(rt, rg, opc, fnm) \
118118
VSX_FINLINE(rt) fnm(const rg& a) \
@@ -233,6 +233,10 @@ VSX_FINLINE(rt) fnm(const rg& a, const rg& b) \
233233
#if __GNUG__ < 5
234234
// vec_xxpermdi in gcc4 missing little-endian supports just like clang
235235
# define vec_permi(a, b, c) vec_xxpermdi(b, a, (3 ^ (((c) & 1) << 1 | (c) >> 1)))
236+
// same as vec_xxpermdi
237+
# undef vec_vbpermq
238+
VSX_IMPL_2VRG(vec_udword2, vec_uchar16, vbpermq, vec_vbpermq)
239+
VSX_IMPL_2VRG(vec_dword2, vec_char16, vbpermq, vec_vbpermq)
236240
#else
237241
# define vec_permi vec_xxpermdi
238242
#endif // __GNUG__ < 5
@@ -257,44 +261,38 @@ VSX_REDIRECT_1RG(vec_float4, vec_double2, vec_cvfo, __builtin_vsx_xvcvdpsp)
257261
VSX_REDIRECT_1RG(vec_double2, vec_float4, vec_cvfo, __builtin_vsx_xvcvspdp)
258262

259263
// converts word and doubleword to double-precision
260-
#ifdef vec_ctd
261-
# undef vec_ctd
262-
#endif
263-
VSX_IMPL_1RG(vec_double2, wd, vec_int4, wa, xvcvsxwdp, vec_ctdo)
264-
VSX_IMPL_1RG(vec_double2, wd, vec_uint4, wa, xvcvuxwdp, vec_ctdo)
265-
VSX_IMPL_1RG(vec_double2, wd, vec_dword2, wi, xvcvsxddp, vec_ctd)
266-
VSX_IMPL_1RG(vec_double2, wd, vec_udword2, wi, xvcvuxddp, vec_ctd)
264+
#undef vec_ctd
265+
VSX_IMPL_1RG(vec_double2, vec_int4, xvcvsxwdp, vec_ctdo)
266+
VSX_IMPL_1RG(vec_double2, vec_uint4, xvcvuxwdp, vec_ctdo)
267+
VSX_IMPL_1RG(vec_double2, vec_dword2, xvcvsxddp, vec_ctd)
268+
VSX_IMPL_1RG(vec_double2, vec_udword2, xvcvuxddp, vec_ctd)
267269

268270
// converts word and doubleword to single-precision
269271
#undef vec_ctf
270-
VSX_IMPL_1RG(vec_float4, wf, vec_int4, wa, xvcvsxwsp, vec_ctf)
271-
VSX_IMPL_1RG(vec_float4, wf, vec_uint4, wa, xvcvuxwsp, vec_ctf)
272-
VSX_IMPL_1RG(vec_float4, wf, vec_dword2, wi, xvcvsxdsp, vec_ctfo)
273-
VSX_IMPL_1RG(vec_float4, wf, vec_udword2, wi, xvcvuxdsp, vec_ctfo)
272+
VSX_IMPL_1RG(vec_float4, vec_int4, xvcvsxwsp, vec_ctf)
273+
VSX_IMPL_1RG(vec_float4, vec_uint4, xvcvuxwsp, vec_ctf)
274+
VSX_IMPL_1RG(vec_float4, vec_dword2, xvcvsxdsp, vec_ctfo)
275+
VSX_IMPL_1RG(vec_float4, vec_udword2, xvcvuxdsp, vec_ctfo)
274276

275277
// converts single and double precision to signed word
276278
#undef vec_cts
277-
VSX_IMPL_1RG(vec_int4, wa, vec_double2, wd, xvcvdpsxws, vec_ctso)
278-
VSX_IMPL_1RG(vec_int4, wa, vec_float4, wf, xvcvspsxws, vec_cts)
279+
VSX_IMPL_1RG(vec_int4, vec_double2, xvcvdpsxws, vec_ctso)
280+
VSX_IMPL_1RG(vec_int4, vec_float4, xvcvspsxws, vec_cts)
279281

280282
// converts single and double precision to unsigned word
281283
#undef vec_ctu
282-
VSX_IMPL_1RG(vec_uint4, wa, vec_double2, wd, xvcvdpuxws, vec_ctuo)
283-
VSX_IMPL_1RG(vec_uint4, wa, vec_float4, wf, xvcvspuxws, vec_ctu)
284+
VSX_IMPL_1RG(vec_uint4, vec_double2, xvcvdpuxws, vec_ctuo)
285+
VSX_IMPL_1RG(vec_uint4, vec_float4, xvcvspuxws, vec_ctu)
284286

285287
// converts single and double precision to signed doubleword
286-
#ifdef vec_ctsl
287-
# undef vec_ctsl
288-
#endif
289-
VSX_IMPL_1RG(vec_dword2, wi, vec_double2, wd, xvcvdpsxds, vec_ctsl)
290-
VSX_IMPL_1RG(vec_dword2, wi, vec_float4, wf, xvcvspsxds, vec_ctslo)
288+
#undef vec_ctsl
289+
VSX_IMPL_1RG(vec_dword2, vec_double2, xvcvdpsxds, vec_ctsl)
290+
VSX_IMPL_1RG(vec_dword2, vec_float4, xvcvspsxds, vec_ctslo)
291291

292292
// converts single and double precision to unsigned doubleword
293-
#ifdef vec_ctul
294-
# undef vec_ctul
295-
#endif
296-
VSX_IMPL_1RG(vec_udword2, wi, vec_double2, wd, xvcvdpuxds, vec_ctul)
297-
VSX_IMPL_1RG(vec_udword2, wi, vec_float4, wf, xvcvspuxds, vec_ctulo)
293+
#undef vec_ctul
294+
VSX_IMPL_1RG(vec_udword2, vec_double2, xvcvdpuxds, vec_ctul)
295+
VSX_IMPL_1RG(vec_udword2, vec_float4, xvcvspuxds, vec_ctulo)
298296

299297
// just in case if GCC doesn't define it
300298
#ifndef vec_xl

0 commit comments

Comments
 (0)