Commit 0e4dde17 authored by Alexander Alekhin's avatar Alexander Alekhin Committed by GitHub

Merge pull request #7872 from alalek:merge-2.4

parent a206e121
......@@ -418,8 +418,13 @@ if(MSVC)
string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
if(NOT ENABLE_NOISY_WARNINGS AND MSVC_VERSION EQUAL 1400)
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4510 /wd4610 /wd4312 /wd4201 /wd4244 /wd4328 /wd4267)
if(NOT ENABLE_NOISY_WARNINGS)
if(MSVC_VERSION EQUAL 1400)
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4510 /wd4610 /wd4312 /wd4201 /wd4244 /wd4328 /wd4267)
endif()
if(MSVC_VERSION LESS 1900) # MSVS2015
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127) # warning C4127: conditional expression is constant
endif()
endif()
# allow extern "C" functions throw exceptions
......
......@@ -691,8 +691,11 @@ function(ocv_install_target)
set(${__package}_TARGETS "${${__package}_TARGETS}" CACHE INTERNAL "List of ${__package} targets")
endif()
if(INSTALL_CREATE_DISTRIB)
if(MSVC AND NOT BUILD_SHARED_LIBS)
if(MSVS)
if(NOT INSTALL_IGNORE_PDB AND
(INSTALL_PDB OR
(INSTALL_CREATE_DISTRIB AND NOT BUILD_SHARED_LIBS)
))
set(__target "${ARGV0}")
set(isArchive 0)
......@@ -720,13 +723,13 @@ function(ocv_install_target)
get_target_property(fname ${__target} LOCATION_DEBUG)
if(fname MATCHES "\\.lib$")
string(REGEX REPLACE "\\.lib$" ".pdb" fname "${fname}")
install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Debug)
install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Debug OPTIONAL)
endif()
get_target_property(fname ${__target} LOCATION_RELEASE)
if(fname MATCHES "\\.lib$")
string(REGEX REPLACE "\\.lib$" ".pdb" fname "${fname}")
install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Release)
install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Release OPTIONAL)
endif()
else()
# CMake 2.8.12 broke PDB support for STATIC libraries from MSVS, fix was introduced in CMake 3.1.0.
......
......@@ -242,4 +242,18 @@ void CV_ChessboardSubpixelTest::generateIntrinsicParams()
TEST(Calib3d_ChessboardSubPixDetector, accuracy) { CV_ChessboardSubpixelTest test; test.safe_run(); }
TEST(Calib3d_CornerSubPix, regression_7204)
{
cv::Mat image(cv::Size(70, 38), CV_8UC1, cv::Scalar::all(0));
image(cv::Rect(65, 26, 5, 5)).setTo(cv::Scalar::all(255));
image(cv::Rect(55, 31, 8, 1)).setTo(cv::Scalar::all(255));
image(cv::Rect(56, 35, 14, 2)).setTo(cv::Scalar::all(255));
image(cv::Rect(66, 24, 4, 2)).setTo(cv::Scalar::all(255));
image.at<uchar>(24, 69) = 0;
std::vector<cv::Point2f> corners;
corners.push_back(cv::Point2f(65, 30));
cv::cornerSubPix(image, corners, cv::Size(3, 3), cv::Size(-1, -1),
cv::TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
}
/* End of file. */
......@@ -483,8 +483,10 @@ public:
@param pts The points array for storing rectangle vertices.
*/
void points(Point2f pts[]) const;
//! returns the minimal up-right rectangle containing the rotated rectangle
//! returns the minimal up-right integer rectangle containing the rotated rectangle
Rect boundingRect() const;
//! returns the minimal (exact) floating point rectangle containing the rotated rectangle, not intended for use with images
Rect_<float> boundingRect2f() const;
Point2f center; //< the rectangle mass center
Size2f size; //< width and height of the rectangle
......
......@@ -3412,6 +3412,125 @@ static bool ocl_mulSpectrums( InputArray _srcA, InputArray _srcB,
#endif
namespace {
#define VAL(buf, elem) (((T*)((char*)data ## buf + (step ## buf * (elem))))[0])
#define MUL_SPECTRUMS_COL(A, B, C) \
VAL(C, 0) = VAL(A, 0) * VAL(B, 0); \
for (size_t j = 1; j <= rows - 2; j += 2) \
{ \
double a_re = VAL(A, j), a_im = VAL(A, j + 1); \
double b_re = VAL(B, j), b_im = VAL(B, j + 1); \
if (conjB) b_im = -b_im; \
double c_re = a_re * b_re - a_im * b_im; \
double c_im = a_re * b_im + a_im * b_re; \
VAL(C, j) = (T)c_re; VAL(C, j + 1) = (T)c_im; \
} \
if ((rows & 1) == 0) \
VAL(C, rows-1) = VAL(A, rows-1) * VAL(B, rows-1)
template <typename T, bool conjB> static inline
void mulSpectrums_processCol_noinplace(const T* dataA, const T* dataB, T* dataC, size_t stepA, size_t stepB, size_t stepC, size_t rows)
{
MUL_SPECTRUMS_COL(A, B, C);
}
template <typename T, bool conjB> static inline
void mulSpectrums_processCol_inplaceA(const T* dataB, T* dataAC, size_t stepB, size_t stepAC, size_t rows)
{
MUL_SPECTRUMS_COL(AC, B, AC);
}
template <typename T, bool conjB, bool inplaceA> static inline
void mulSpectrums_processCol(const T* dataA, const T* dataB, T* dataC, size_t stepA, size_t stepB, size_t stepC, size_t rows)
{
if (inplaceA)
mulSpectrums_processCol_inplaceA<T, conjB>(dataB, dataC, stepB, stepC, rows);
else
mulSpectrums_processCol_noinplace<T, conjB>(dataA, dataB, dataC, stepA, stepB, stepC, rows);
}
#undef MUL_SPECTRUMS_COL
#undef VAL
template <typename T, bool conjB, bool inplaceA> static inline
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)
{
mulSpectrums_processCol<T, conjB, inplaceA>(dataA, dataB, dataC, stepA, stepB, stepC, rows);
if ((cols & 1) == 0)
{
mulSpectrums_processCol<T, conjB, inplaceA>(dataA + cols - 1, dataB + cols - 1, dataC + cols - 1, stepA, stepB, stepC, rows);
}
}
#define VAL(buf, elem) (data ## buf[(elem)])
#define MUL_SPECTRUMS_ROW(A, B, C) \
for (size_t j = j0; j < j1; j += 2) \
{ \
double a_re = VAL(A, j), a_im = VAL(A, j + 1); \
double b_re = VAL(B, j), b_im = VAL(B, j + 1); \
if (conjB) b_im = -b_im; \
double c_re = a_re * b_re - a_im * b_im; \
double c_im = a_re * b_im + a_im * b_re; \
VAL(C, j) = (T)c_re; VAL(C, j + 1) = (T)c_im; \
}
template <typename T, bool conjB> static inline
void mulSpectrums_processRow_noinplace(const T* dataA, const T* dataB, T* dataC, size_t j0, size_t j1)
{
MUL_SPECTRUMS_ROW(A, B, C);
}
template <typename T, bool conjB> static inline
void mulSpectrums_processRow_inplaceA(const T* dataB, T* dataAC, size_t j0, size_t j1)
{
MUL_SPECTRUMS_ROW(AC, B, AC);
}
template <typename T, bool conjB, bool inplaceA> static inline
void mulSpectrums_processRow(const T* dataA, const T* dataB, T* dataC, size_t j0, size_t j1)
{
if (inplaceA)
mulSpectrums_processRow_inplaceA<T, conjB>(dataB, dataC, j0, j1);
else
mulSpectrums_processRow_noinplace<T, conjB>(dataA, dataB, dataC, j0, j1);
}
#undef MUL_SPECTRUMS_ROW
#undef VAL
template <typename T, bool conjB, bool inplaceA> static inline
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)
{
while (rows-- > 0)
{
if (is_1d_CN1)
dataC[0] = dataA[0]*dataB[0];
mulSpectrums_processRow<T, conjB, inplaceA>(dataA, dataB, dataC, j0, j1);
if (is_1d_CN1 && (cols & 1) == 0)
dataC[j1] = dataA[j1]*dataB[j1];
dataA = (const T*)(((char*)dataA) + stepA);
dataB = (const T*)(((char*)dataB) + stepB);
dataC = (T*)(((char*)dataC) + stepC);
}
}
template <typename T, bool conjB, bool inplaceA> static inline
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)
{
if (!is_1d && isCN1)
{
mulSpectrums_processCols<T, conjB, inplaceA>(dataA, dataB, dataC, stepA, stepB, stepC, rows, cols);
}
mulSpectrums_processRows<T, conjB, inplaceA>(dataA, dataB, dataC, stepA, stepB, stepC, rows, cols, j0, j1, is_1d && isCN1);
}
template <typename T, bool conjB> static inline
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)
{
if (dataA == dataC)
mulSpectrums_Impl_<T, conjB, true>(dataA, dataB, dataC, stepA, stepB, stepC, rows, cols, j0, j1, is_1d, isCN1);
else
mulSpectrums_Impl_<T, conjB, false>(dataA, dataB, dataC, stepA, stepB, stepC, rows, cols, j0, j1, is_1d, isCN1);
}
} // namespace
void cv::mulSpectrums( InputArray _srcA, InputArray _srcB,
OutputArray _dst, int flags, bool conjB )
{
......@@ -3422,8 +3541,7 @@ void cv::mulSpectrums( InputArray _srcA, InputArray _srcB,
Mat srcA = _srcA.getMat(), srcB = _srcB.getMat();
int depth = srcA.depth(), cn = srcA.channels(), type = srcA.type();
int rows = srcA.rows, cols = srcA.cols;
int j, k;
size_t rows = srcA.rows, cols = srcA.cols;
CV_Assert( type == srcB.type() && srcA.size() == srcB.size() );
CV_Assert( type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2 );
......@@ -3431,149 +3549,42 @@ void cv::mulSpectrums( InputArray _srcA, InputArray _srcB,
_dst.create( srcA.rows, srcA.cols, type );
Mat dst = _dst.getMat();
bool is_1d = (flags & DFT_ROWS) || (rows == 1 || (cols == 1 &&
srcA.isContinuous() && srcB.isContinuous() && dst.isContinuous()));
// correct inplace support
// Case 'dst.data == srcA.data' is handled by implementation,
// because it is used frequently (filter2D, matchTemplate)
if (dst.data == srcB.data)
srcB = srcB.clone(); // workaround for B only
bool is_1d = (flags & DFT_ROWS)
|| (rows == 1)
|| (cols == 1 && srcA.isContinuous() && srcB.isContinuous() && dst.isContinuous());
if( is_1d && !(flags & DFT_ROWS) )
cols = cols + rows - 1, rows = 1;
int ncols = cols*cn;
int j0 = cn == 1;
int j1 = ncols - (cols % 2 == 0 && cn == 1);
bool isCN1 = cn == 1;
size_t j0 = isCN1 ? 1 : 0;
size_t j1 = cols*cn - (((cols & 1) == 0 && cn == 1) ? 1 : 0);
if( depth == CV_32F )
if (depth == CV_32F)
{
const float* dataA = srcA.ptr<float>();
const float* dataB = srcB.ptr<float>();
float* dataC = dst.ptr<float>();
size_t stepA = srcA.step/sizeof(dataA[0]);
size_t stepB = srcB.step/sizeof(dataB[0]);
size_t stepC = dst.step/sizeof(dataC[0]);
if( !is_1d && cn == 1 )
{
for( k = 0; k < (cols % 2 ? 1 : 2); k++ )
{
if( k == 1 )
dataA += cols - 1, dataB += cols - 1, dataC += cols - 1;
dataC[0] = dataA[0]*dataB[0];
if( rows % 2 == 0 )
dataC[(rows-1)*stepC] = dataA[(rows-1)*stepA]*dataB[(rows-1)*stepB];
if( !conjB )
for( j = 1; j <= rows - 2; j += 2 )
{
double re = (double)dataA[j*stepA]*dataB[j*stepB] -
(double)dataA[(j+1)*stepA]*dataB[(j+1)*stepB];
double im = (double)dataA[j*stepA]*dataB[(j+1)*stepB] +
(double)dataA[(j+1)*stepA]*dataB[j*stepB];
dataC[j*stepC] = (float)re; dataC[(j+1)*stepC] = (float)im;
}
else
for( j = 1; j <= rows - 2; j += 2 )
{
double re = (double)dataA[j*stepA]*dataB[j*stepB] +
(double)dataA[(j+1)*stepA]*dataB[(j+1)*stepB];
double im = (double)dataA[(j+1)*stepA]*dataB[j*stepB] -
(double)dataA[j*stepA]*dataB[(j+1)*stepB];
dataC[j*stepC] = (float)re; dataC[(j+1)*stepC] = (float)im;
}
if( k == 1 )
dataA -= cols - 1, dataB -= cols - 1, dataC -= cols - 1;
}
}
for( ; rows--; dataA += stepA, dataB += stepB, dataC += stepC )
{
if( is_1d && cn == 1 )
{
dataC[0] = dataA[0]*dataB[0];
if( cols % 2 == 0 )
dataC[j1] = dataA[j1]*dataB[j1];
}
if( !conjB )
for( j = j0; j < j1; j += 2 )
{
double re = (double)dataA[j]*dataB[j] - (double)dataA[j+1]*dataB[j+1];
double im = (double)dataA[j+1]*dataB[j] + (double)dataA[j]*dataB[j+1];
dataC[j] = (float)re; dataC[j+1] = (float)im;
}
else
for( j = j0; j < j1; j += 2 )
{
double re = (double)dataA[j]*dataB[j] + (double)dataA[j+1]*dataB[j+1];
double im = (double)dataA[j+1]*dataB[j] - (double)dataA[j]*dataB[j+1];
dataC[j] = (float)re; dataC[j+1] = (float)im;
}
}
if (!conjB)
mulSpectrums_Impl<float, false>(dataA, dataB, dataC, srcA.step, srcB.step, dst.step, rows, cols, j0, j1, is_1d, isCN1);
else
mulSpectrums_Impl<float, true>(dataA, dataB, dataC, srcA.step, srcB.step, dst.step, rows, cols, j0, j1, is_1d, isCN1);
}
else
{
const double* dataA = srcA.ptr<double>();
const double* dataB = srcB.ptr<double>();
double* dataC = dst.ptr<double>();
size_t stepA = srcA.step/sizeof(dataA[0]);
size_t stepB = srcB.step/sizeof(dataB[0]);
size_t stepC = dst.step/sizeof(dataC[0]);
if( !is_1d && cn == 1 )
{
for( k = 0; k < (cols % 2 ? 1 : 2); k++ )
{
if( k == 1 )
dataA += cols - 1, dataB += cols - 1, dataC += cols - 1;
dataC[0] = dataA[0]*dataB[0];
if( rows % 2 == 0 )
dataC[(rows-1)*stepC] = dataA[(rows-1)*stepA]*dataB[(rows-1)*stepB];
if( !conjB )
for( j = 1; j <= rows - 2; j += 2 )
{
double re = dataA[j*stepA]*dataB[j*stepB] -
dataA[(j+1)*stepA]*dataB[(j+1)*stepB];
double im = dataA[j*stepA]*dataB[(j+1)*stepB] +
dataA[(j+1)*stepA]*dataB[j*stepB];
dataC[j*stepC] = re; dataC[(j+1)*stepC] = im;
}
else
for( j = 1; j <= rows - 2; j += 2 )
{
double re = dataA[j*stepA]*dataB[j*stepB] +
dataA[(j+1)*stepA]*dataB[(j+1)*stepB];
double im = dataA[(j+1)*stepA]*dataB[j*stepB] -
dataA[j*stepA]*dataB[(j+1)*stepB];
dataC[j*stepC] = re; dataC[(j+1)*stepC] = im;
}
if( k == 1 )
dataA -= cols - 1, dataB -= cols - 1, dataC -= cols - 1;
}
}
for( ; rows--; dataA += stepA, dataB += stepB, dataC += stepC )
{
if( is_1d && cn == 1 )
{
dataC[0] = dataA[0]*dataB[0];
if( cols % 2 == 0 )
dataC[j1] = dataA[j1]*dataB[j1];
}
if( !conjB )
for( j = j0; j < j1; j += 2 )
{
double re = dataA[j]*dataB[j] - dataA[j+1]*dataB[j+1];
double im = dataA[j+1]*dataB[j] + dataA[j]*dataB[j+1];
dataC[j] = re; dataC[j+1] = im;
}
else
for( j = j0; j < j1; j += 2 )
{
double re = dataA[j]*dataB[j] + dataA[j+1]*dataB[j+1];
double im = dataA[j+1]*dataB[j] - dataA[j]*dataB[j+1];
dataC[j] = re; dataC[j+1] = im;
}
}
if (!conjB)
mulSpectrums_Impl<double, false>(dataA, dataB, dataC, srcA.step, srcB.step, dst.step, rows, cols, j0, j1, is_1d, isCN1);
else
mulSpectrums_Impl<double, true>(dataA, dataB, dataC, srcA.step, srcB.step, dst.step, rows, cols, j0, j1, is_1d, isCN1);
}
}
......
......@@ -5566,6 +5566,16 @@ Rect RotatedRect::boundingRect() const
return r;
}
Rect_<float> RotatedRect::boundingRect2f() const
{
Point2f pt[4];
points(pt);
Rect_<float> r(Point_<float>(min(min(min(pt[0].x, pt[1].x), pt[2].x), pt[3].x), min(min(min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
Point_<float>(max(max(max(pt[0].x, pt[1].x), pt[2].x), pt[3].x), max(max(max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
return r;
}
}
// glue
......
......@@ -419,9 +419,6 @@ static void fixCCS( Mat& mat, int cols, int flags )
}
}
#if defined _MSC_VER && _MSC_VER >= 1700
#pragma optimize("", off)
#endif
static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
{
dst.create(src1.rows, src1.cols, src1.type());
......@@ -430,12 +427,27 @@ static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
CV_Assert( src1.size == src2.size && src1.type() == src2.type() &&
(src1.type() == CV_32FC2 || src1.type() == CV_64FC2) );
const Mat* src1_ = &src1;
Mat src1_tmp;
if (dst.data == src1.data)
{
src1_tmp = src1.clone();
src1_ = &src1_tmp;
}
const Mat* src2_ = &src2;
Mat src2_tmp;
if (dst.data == src2.data)
{
src2_tmp = src2.clone();
src2_ = &src2_tmp;
}
for( i = 0; i < dst.rows; i++ )
{
if( depth == CV_32F )
{
const float* a = src1.ptr<float>(i);
const float* b = src2.ptr<float>(i);
const float* a = src1_->ptr<float>(i);
const float* b = src2_->ptr<float>(i);
float* c = dst.ptr<float>(i);
if( !(flags & CV_DXT_MUL_CONJ) )
......@@ -459,8 +471,8 @@ static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
}
else
{
const double* a = src1.ptr<double>(i);
const double* b = src2.ptr<double>(i);
const double* a = src1_->ptr<double>(i);
const double* b = src2_->ptr<double>(i);
double* c = dst.ptr<double>(i);
if( !(flags & CV_DXT_MUL_CONJ) )
......@@ -484,9 +496,6 @@ static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
}
}
}
#if defined _MSC_VER && _MSC_VER >= 1700
#pragma optimize("", on)
#endif
}
......@@ -778,9 +787,7 @@ public:
protected:
void run_func();
void prepare_to_validation( int test_case_idx );
#if defined(__aarch64__) && defined(NDEBUG)
double get_success_error_level( int test_case_idx, int i, int j );
#endif
};
......@@ -788,31 +795,19 @@ CxCore_MulSpectrumsTest::CxCore_MulSpectrumsTest() : CxCore_DXTBaseTest( true, t
{
}
#if defined(__aarch64__) && defined(NDEBUG)
double CxCore_MulSpectrumsTest::get_success_error_level( int test_case_idx, int i, int j )
{
(void)test_case_idx;
CV_Assert(i == OUTPUT);
CV_Assert(j == 0);
int elem_depth = CV_MAT_DEPTH(cvGetElemType(test_array[i][j]));
if( elem_depth <= CV_32F )
{
return ArrayTest::get_success_error_level( test_case_idx, i, j );
}
switch( test_case_idx )
{
// Usual threshold is too strict for these test cases due to the difference of fmsub and fsub
case 399:
case 420:
return DBL_EPSILON * 20000;
case 65:
case 161:
case 287:
case 351:
case 458:
return DBL_EPSILON * 10000;
default:
return ArrayTest::get_success_error_level( test_case_idx, i, j );
}
CV_Assert(elem_depth == CV_32F || elem_depth == CV_64F);
element_wise_relative_error = false;
double maxInputValue = 1000; // ArrayTest::get_minmax_bounds
double err = 8 * maxInputValue; // result = A*B + C*D
return (elem_depth == CV_32F ? FLT_EPSILON : DBL_EPSILON) * err;
}
#endif
void CxCore_MulSpectrumsTest::run_func()
{
......
......@@ -167,6 +167,9 @@ static void divSpectrums( InputArray _srcA, InputArray _srcB, OutputArray _dst,
_dst.create( srcA.rows, srcA.cols, type );
Mat dst = _dst.getMat();
CV_Assert(dst.data != srcA.data); // non-inplace check
CV_Assert(dst.data != srcB.data); // non-inplace check
bool is_1d = (flags & DFT_ROWS) || (rows == 1 || (cols == 1 &&
srcA.isContinuous() && srcB.isContinuous() && dst.isContinuous()));
......
......@@ -63,6 +63,7 @@ static bool log_power_checkpoints;
#include <sys/syscall.h>
#include <pthread.h>
#include <cerrno>
static void setCurrentThreadAffinityMask(int mask)
{
pid_t pid=gettid();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment