Skip to content

Commit 0e4dde1

Browse files
authored
Merge pull request opencv#7872 from alalek:merge-2.4
1 parent a206e12 commit 0e4dde1

File tree

9 files changed

+214
-170
lines changed

9 files changed

+214
-170
lines changed

cmake/OpenCVCompilerOptions.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,13 @@ if(MSVC)
418418
string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
419419
string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
420420

421-
if(NOT ENABLE_NOISY_WARNINGS AND MSVC_VERSION EQUAL 1400)
422-
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4510 /wd4610 /wd4312 /wd4201 /wd4244 /wd4328 /wd4267)
421+
if(NOT ENABLE_NOISY_WARNINGS)
422+
if(MSVC_VERSION EQUAL 1400)
423+
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4510 /wd4610 /wd4312 /wd4201 /wd4244 /wd4328 /wd4267)
424+
endif()
425+
if(MSVC_VERSION LESS 1900) # MSVS2015
426+
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127) # warning C4127: conditional expression is constant
427+
endif()
423428
endif()
424429

425430
# allow extern "C" functions throw exceptions

cmake/OpenCVUtils.cmake

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,11 @@ function(ocv_install_target)
691691
set(${__package}_TARGETS "${${__package}_TARGETS}" CACHE INTERNAL "List of ${__package} targets")
692692
endif()
693693

694-
if(INSTALL_CREATE_DISTRIB)
695-
if(MSVC AND NOT BUILD_SHARED_LIBS)
694+
if(MSVS)
695+
if(NOT INSTALL_IGNORE_PDB AND
696+
(INSTALL_PDB OR
697+
(INSTALL_CREATE_DISTRIB AND NOT BUILD_SHARED_LIBS)
698+
))
696699
set(__target "${ARGV0}")
697700

698701
set(isArchive 0)
@@ -720,13 +723,13 @@ function(ocv_install_target)
720723
get_target_property(fname ${__target} LOCATION_DEBUG)
721724
if(fname MATCHES "\\.lib$")
722725
string(REGEX REPLACE "\\.lib$" ".pdb" fname "${fname}")
723-
install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Debug)
726+
install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Debug OPTIONAL)
724727
endif()
725728

726729
get_target_property(fname ${__target} LOCATION_RELEASE)
727730
if(fname MATCHES "\\.lib$")
728731
string(REGEX REPLACE "\\.lib$" ".pdb" fname "${fname}")
729-
install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Release)
732+
install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Release OPTIONAL)
730733
endif()
731734
else()
732735
# CMake 2.8.12 broke PDB support for STATIC libraries from MSVS, fix was introduced in CMake 3.1.0.

modules/calib3d/test/test_cornerssubpix.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,18 @@ void CV_ChessboardSubpixelTest::generateIntrinsicParams()
242242

243243
TEST(Calib3d_ChessboardSubPixDetector, accuracy) { CV_ChessboardSubpixelTest test; test.safe_run(); }
244244

245+
TEST(Calib3d_CornerSubPix, regression_7204)
246+
{
247+
cv::Mat image(cv::Size(70, 38), CV_8UC1, cv::Scalar::all(0));
248+
image(cv::Rect(65, 26, 5, 5)).setTo(cv::Scalar::all(255));
249+
image(cv::Rect(55, 31, 8, 1)).setTo(cv::Scalar::all(255));
250+
image(cv::Rect(56, 35, 14, 2)).setTo(cv::Scalar::all(255));
251+
image(cv::Rect(66, 24, 4, 2)).setTo(cv::Scalar::all(255));
252+
image.at<uchar>(24, 69) = 0;
253+
std::vector<cv::Point2f> corners;
254+
corners.push_back(cv::Point2f(65, 30));
255+
cv::cornerSubPix(image, corners, cv::Size(3, 3), cv::Size(-1, -1),
256+
cv::TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
257+
}
258+
245259
/* End of file. */

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,10 @@ class CV_EXPORTS RotatedRect
483483
@param pts The points array for storing rectangle vertices.
484484
*/
485485
void points(Point2f pts[]) const;
486-
//! returns the minimal up-right rectangle containing the rotated rectangle
486+
//! returns the minimal up-right integer rectangle containing the rotated rectangle
487487
Rect boundingRect() const;
488+
//! returns the minimal (exact) floating point rectangle containing the rotated rectangle, not intended for use with images
489+
Rect_<float> boundingRect2f() const;
488490

489491
Point2f center; //< the rectangle mass center
490492
Size2f size; //< width and height of the rectangle

modules/core/src/dxt.cpp

Lines changed: 141 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,6 +3412,125 @@ static bool ocl_mulSpectrums( InputArray _srcA, InputArray _srcB,
34123412

34133413
#endif
34143414

3415+
namespace {
3416+
3417+
#define VAL(buf, elem) (((T*)((char*)data ## buf + (step ## buf * (elem))))[0])
3418+
#define MUL_SPECTRUMS_COL(A, B, C) \
3419+
VAL(C, 0) = VAL(A, 0) * VAL(B, 0); \
3420+
for (size_t j = 1; j <= rows - 2; j += 2) \
3421+
{ \
3422+
double a_re = VAL(A, j), a_im = VAL(A, j + 1); \
3423+
double b_re = VAL(B, j), b_im = VAL(B, j + 1); \
3424+
if (conjB) b_im = -b_im; \
3425+
double c_re = a_re * b_re - a_im * b_im; \
3426+
double c_im = a_re * b_im + a_im * b_re; \
3427+
VAL(C, j) = (T)c_re; VAL(C, j + 1) = (T)c_im; \
3428+
} \
3429+
if ((rows & 1) == 0) \
3430+
VAL(C, rows-1) = VAL(A, rows-1) * VAL(B, rows-1)
3431+
3432+
template <typename T, bool conjB> static inline
3433+
void mulSpectrums_processCol_noinplace(const T* dataA, const T* dataB, T* dataC, size_t stepA, size_t stepB, size_t stepC, size_t rows)
3434+
{
3435+
MUL_SPECTRUMS_COL(A, B, C);
3436+
}
3437+
3438+
template <typename T, bool conjB> static inline
3439+
void mulSpectrums_processCol_inplaceA(const T* dataB, T* dataAC, size_t stepB, size_t stepAC, size_t rows)
3440+
{
3441+
MUL_SPECTRUMS_COL(AC, B, AC);
3442+
}
3443+
template <typename T, bool conjB, bool inplaceA> static inline
3444+
void mulSpectrums_processCol(const T* dataA, const T* dataB, T* dataC, size_t stepA, size_t stepB, size_t stepC, size_t rows)
3445+
{
3446+
if (inplaceA)
3447+
mulSpectrums_processCol_inplaceA<T, conjB>(dataB, dataC, stepB, stepC, rows);
3448+
else
3449+
mulSpectrums_processCol_noinplace<T, conjB>(dataA, dataB, dataC, stepA, stepB, stepC, rows);
3450+
}
3451+
#undef MUL_SPECTRUMS_COL
3452+
#undef VAL
3453+
3454+
template <typename T, bool conjB, bool inplaceA> static inline
3455+
void mulSpectrums_processCols(const T* dataA, const T* dataB, T* dataC, size_t stepA, size_t stepB, size_t stepC, size_t rows, size_t cols)
3456+
{
3457+
mulSpectrums_processCol<T, conjB, inplaceA>(dataA, dataB, dataC, stepA, stepB, stepC, rows);
3458+
if ((cols & 1) == 0)
3459+
{
3460+
mulSpectrums_processCol<T, conjB, inplaceA>(dataA + cols - 1, dataB + cols - 1, dataC + cols - 1, stepA, stepB, stepC, rows);
3461+
}
3462+
}
3463+
3464+
#define VAL(buf, elem) (data ## buf[(elem)])
3465+
#define MUL_SPECTRUMS_ROW(A, B, C) \
3466+
for (size_t j = j0; j < j1; j += 2) \
3467+
{ \
3468+
double a_re = VAL(A, j), a_im = VAL(A, j + 1); \
3469+
double b_re = VAL(B, j), b_im = VAL(B, j + 1); \
3470+
if (conjB) b_im = -b_im; \
3471+
double c_re = a_re * b_re - a_im * b_im; \
3472+
double c_im = a_re * b_im + a_im * b_re; \
3473+
VAL(C, j) = (T)c_re; VAL(C, j + 1) = (T)c_im; \
3474+
}
3475+
template <typename T, bool conjB> static inline
3476+
void mulSpectrums_processRow_noinplace(const T* dataA, const T* dataB, T* dataC, size_t j0, size_t j1)
3477+
{
3478+
MUL_SPECTRUMS_ROW(A, B, C);
3479+
}
3480+
template <typename T, bool conjB> static inline
3481+
void mulSpectrums_processRow_inplaceA(const T* dataB, T* dataAC, size_t j0, size_t j1)
3482+
{
3483+
MUL_SPECTRUMS_ROW(AC, B, AC);
3484+
}
3485+
template <typename T, bool conjB, bool inplaceA> static inline
3486+
void mulSpectrums_processRow(const T* dataA, const T* dataB, T* dataC, size_t j0, size_t j1)
3487+
{
3488+
if (inplaceA)
3489+
mulSpectrums_processRow_inplaceA<T, conjB>(dataB, dataC, j0, j1);
3490+
else
3491+
mulSpectrums_processRow_noinplace<T, conjB>(dataA, dataB, dataC, j0, j1);
3492+
}
3493+
#undef MUL_SPECTRUMS_ROW
3494+
#undef VAL
3495+
3496+
template <typename T, bool conjB, bool inplaceA> static inline
3497+
void mulSpectrums_processRows(const T* dataA, const T* dataB, T* dataC, size_t stepA, size_t stepB, size_t stepC, size_t rows, size_t cols, size_t j0, size_t j1, bool is_1d_CN1)
3498+
{
3499+
while (rows-- > 0)
3500+
{
3501+
if (is_1d_CN1)
3502+
dataC[0] = dataA[0]*dataB[0];
3503+
mulSpectrums_processRow<T, conjB, inplaceA>(dataA, dataB, dataC, j0, j1);
3504+
if (is_1d_CN1 && (cols & 1) == 0)
3505+
dataC[j1] = dataA[j1]*dataB[j1];
3506+
3507+
dataA = (const T*)(((char*)dataA) + stepA);
3508+
dataB = (const T*)(((char*)dataB) + stepB);
3509+
dataC = (T*)(((char*)dataC) + stepC);
3510+
}
3511+
}
3512+
3513+
3514+
template <typename T, bool conjB, bool inplaceA> static inline
3515+
void mulSpectrums_Impl_(const T* dataA, const T* dataB, T* dataC, size_t stepA, size_t stepB, size_t stepC, size_t rows, size_t cols, size_t j0, size_t j1, bool is_1d, bool isCN1)
3516+
{
3517+
if (!is_1d && isCN1)
3518+
{
3519+
mulSpectrums_processCols<T, conjB, inplaceA>(dataA, dataB, dataC, stepA, stepB, stepC, rows, cols);
3520+
}
3521+
mulSpectrums_processRows<T, conjB, inplaceA>(dataA, dataB, dataC, stepA, stepB, stepC, rows, cols, j0, j1, is_1d && isCN1);
3522+
}
3523+
template <typename T, bool conjB> static inline
3524+
void mulSpectrums_Impl(const T* dataA, const T* dataB, T* dataC, size_t stepA, size_t stepB, size_t stepC, size_t rows, size_t cols, size_t j0, size_t j1, bool is_1d, bool isCN1)
3525+
{
3526+
if (dataA == dataC)
3527+
mulSpectrums_Impl_<T, conjB, true>(dataA, dataB, dataC, stepA, stepB, stepC, rows, cols, j0, j1, is_1d, isCN1);
3528+
else
3529+
mulSpectrums_Impl_<T, conjB, false>(dataA, dataB, dataC, stepA, stepB, stepC, rows, cols, j0, j1, is_1d, isCN1);
3530+
}
3531+
3532+
} // namespace
3533+
34153534
void cv::mulSpectrums( InputArray _srcA, InputArray _srcB,
34163535
OutputArray _dst, int flags, bool conjB )
34173536
{
@@ -3422,158 +3541,50 @@ void cv::mulSpectrums( InputArray _srcA, InputArray _srcB,
34223541

34233542
Mat srcA = _srcA.getMat(), srcB = _srcB.getMat();
34243543
int depth = srcA.depth(), cn = srcA.channels(), type = srcA.type();
3425-
int rows = srcA.rows, cols = srcA.cols;
3426-
int j, k;
3544+
size_t rows = srcA.rows, cols = srcA.cols;
34273545

34283546
CV_Assert( type == srcB.type() && srcA.size() == srcB.size() );
34293547
CV_Assert( type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2 );
34303548

34313549
_dst.create( srcA.rows, srcA.cols, type );
34323550
Mat dst = _dst.getMat();
34333551

3434-
bool is_1d = (flags & DFT_ROWS) || (rows == 1 || (cols == 1 &&
3435-
srcA.isContinuous() && srcB.isContinuous() && dst.isContinuous()));
3552+
// correct inplace support
3553+
// Case 'dst.data == srcA.data' is handled by implementation,
3554+
// because it is used frequently (filter2D, matchTemplate)
3555+
if (dst.data == srcB.data)
3556+
srcB = srcB.clone(); // workaround for B only
3557+
3558+
bool is_1d = (flags & DFT_ROWS)
3559+
|| (rows == 1)
3560+
|| (cols == 1 && srcA.isContinuous() && srcB.isContinuous() && dst.isContinuous());
34363561

34373562
if( is_1d && !(flags & DFT_ROWS) )
34383563
cols = cols + rows - 1, rows = 1;
34393564

3440-
int ncols = cols*cn;
3441-
int j0 = cn == 1;
3442-
int j1 = ncols - (cols % 2 == 0 && cn == 1);
3565+
bool isCN1 = cn == 1;
3566+
size_t j0 = isCN1 ? 1 : 0;
3567+
size_t j1 = cols*cn - (((cols & 1) == 0 && cn == 1) ? 1 : 0);
34433568

3444-
if( depth == CV_32F )
3569+
if (depth == CV_32F)
34453570
{
34463571
const float* dataA = srcA.ptr<float>();
34473572
const float* dataB = srcB.ptr<float>();
34483573
float* dataC = dst.ptr<float>();
3449-
3450-
size_t stepA = srcA.step/sizeof(dataA[0]);
3451-
size_t stepB = srcB.step/sizeof(dataB[0]);
3452-
size_t stepC = dst.step/sizeof(dataC[0]);
3453-
3454-
if( !is_1d && cn == 1 )
3455-
{
3456-
for( k = 0; k < (cols % 2 ? 1 : 2); k++ )
3457-
{
3458-
if( k == 1 )
3459-
dataA += cols - 1, dataB += cols - 1, dataC += cols - 1;
3460-
dataC[0] = dataA[0]*dataB[0];
3461-
if( rows % 2 == 0 )
3462-
dataC[(rows-1)*stepC] = dataA[(rows-1)*stepA]*dataB[(rows-1)*stepB];
3463-
if( !conjB )
3464-
for( j = 1; j <= rows - 2; j += 2 )
3465-
{
3466-
double re = (double)dataA[j*stepA]*dataB[j*stepB] -
3467-
(double)dataA[(j+1)*stepA]*dataB[(j+1)*stepB];
3468-
double im = (double)dataA[j*stepA]*dataB[(j+1)*stepB] +
3469-
(double)dataA[(j+1)*stepA]*dataB[j*stepB];
3470-
dataC[j*stepC] = (float)re; dataC[(j+1)*stepC] = (float)im;
3471-
}
3472-
else
3473-
for( j = 1; j <= rows - 2; j += 2 )
3474-
{
3475-
double re = (double)dataA[j*stepA]*dataB[j*stepB] +
3476-
(double)dataA[(j+1)*stepA]*dataB[(j+1)*stepB];
3477-
double im = (double)dataA[(j+1)*stepA]*dataB[j*stepB] -
3478-
(double)dataA[j*stepA]*dataB[(j+1)*stepB];
3479-
dataC[j*stepC] = (float)re; dataC[(j+1)*stepC] = (float)im;
3480-
}
3481-
if( k == 1 )
3482-
dataA -= cols - 1, dataB -= cols - 1, dataC -= cols - 1;
3483-
}
3484-
}
3485-
3486-
for( ; rows--; dataA += stepA, dataB += stepB, dataC += stepC )
3487-
{
3488-
if( is_1d && cn == 1 )
3489-
{
3490-
dataC[0] = dataA[0]*dataB[0];
3491-
if( cols % 2 == 0 )
3492-
dataC[j1] = dataA[j1]*dataB[j1];
3493-
}
3494-
3495-
if( !conjB )
3496-
for( j = j0; j < j1; j += 2 )
3497-
{
3498-
double re = (double)dataA[j]*dataB[j] - (double)dataA[j+1]*dataB[j+1];
3499-
double im = (double)dataA[j+1]*dataB[j] + (double)dataA[j]*dataB[j+1];
3500-
dataC[j] = (float)re; dataC[j+1] = (float)im;
3501-
}
3502-
else
3503-
for( j = j0; j < j1; j += 2 )
3504-
{
3505-
double re = (double)dataA[j]*dataB[j] + (double)dataA[j+1]*dataB[j+1];
3506-
double im = (double)dataA[j+1]*dataB[j] - (double)dataA[j]*dataB[j+1];
3507-
dataC[j] = (float)re; dataC[j+1] = (float)im;
3508-
}
3509-
}
3574+
if (!conjB)
3575+
mulSpectrums_Impl<float, false>(dataA, dataB, dataC, srcA.step, srcB.step, dst.step, rows, cols, j0, j1, is_1d, isCN1);
3576+
else
3577+
mulSpectrums_Impl<float, true>(dataA, dataB, dataC, srcA.step, srcB.step, dst.step, rows, cols, j0, j1, is_1d, isCN1);
35103578
}
35113579
else
35123580
{
35133581
const double* dataA = srcA.ptr<double>();
35143582
const double* dataB = srcB.ptr<double>();
35153583
double* dataC = dst.ptr<double>();
3516-
3517-
size_t stepA = srcA.step/sizeof(dataA[0]);
3518-
size_t stepB = srcB.step/sizeof(dataB[0]);
3519-
size_t stepC = dst.step/sizeof(dataC[0]);
3520-
3521-
if( !is_1d && cn == 1 )
3522-
{
3523-
for( k = 0; k < (cols % 2 ? 1 : 2); k++ )
3524-
{
3525-
if( k == 1 )
3526-
dataA += cols - 1, dataB += cols - 1, dataC += cols - 1;
3527-
dataC[0] = dataA[0]*dataB[0];
3528-
if( rows % 2 == 0 )
3529-
dataC[(rows-1)*stepC] = dataA[(rows-1)*stepA]*dataB[(rows-1)*stepB];
3530-
if( !conjB )
3531-
for( j = 1; j <= rows - 2; j += 2 )
3532-
{
3533-
double re = dataA[j*stepA]*dataB[j*stepB] -
3534-
dataA[(j+1)*stepA]*dataB[(j+1)*stepB];
3535-
double im = dataA[j*stepA]*dataB[(j+1)*stepB] +
3536-
dataA[(j+1)*stepA]*dataB[j*stepB];
3537-
dataC[j*stepC] = re; dataC[(j+1)*stepC] = im;
3538-
}
3539-
else
3540-
for( j = 1; j <= rows - 2; j += 2 )
3541-
{
3542-
double re = dataA[j*stepA]*dataB[j*stepB] +
3543-
dataA[(j+1)*stepA]*dataB[(j+1)*stepB];
3544-
double im = dataA[(j+1)*stepA]*dataB[j*stepB] -
3545-
dataA[j*stepA]*dataB[(j+1)*stepB];
3546-
dataC[j*stepC] = re; dataC[(j+1)*stepC] = im;
3547-
}
3548-
if( k == 1 )
3549-
dataA -= cols - 1, dataB -= cols - 1, dataC -= cols - 1;
3550-
}
3551-
}
3552-
3553-
for( ; rows--; dataA += stepA, dataB += stepB, dataC += stepC )
3554-
{
3555-
if( is_1d && cn == 1 )
3556-
{
3557-
dataC[0] = dataA[0]*dataB[0];
3558-
if( cols % 2 == 0 )
3559-
dataC[j1] = dataA[j1]*dataB[j1];
3560-
}
3561-
3562-
if( !conjB )
3563-
for( j = j0; j < j1; j += 2 )
3564-
{
3565-
double re = dataA[j]*dataB[j] - dataA[j+1]*dataB[j+1];
3566-
double im = dataA[j+1]*dataB[j] + dataA[j]*dataB[j+1];
3567-
dataC[j] = re; dataC[j+1] = im;
3568-
}
3569-
else
3570-
for( j = j0; j < j1; j += 2 )
3571-
{
3572-
double re = dataA[j]*dataB[j] + dataA[j+1]*dataB[j+1];
3573-
double im = dataA[j+1]*dataB[j] - dataA[j]*dataB[j+1];
3574-
dataC[j] = re; dataC[j+1] = im;
3575-
}
3576-
}
3584+
if (!conjB)
3585+
mulSpectrums_Impl<double, false>(dataA, dataB, dataC, srcA.step, srcB.step, dst.step, rows, cols, j0, j1, is_1d, isCN1);
3586+
else
3587+
mulSpectrums_Impl<double, true>(dataA, dataB, dataC, srcA.step, srcB.step, dst.step, rows, cols, j0, j1, is_1d, isCN1);
35773588
}
35783589
}
35793590

0 commit comments

Comments
 (0)