mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge pull request #12877 from maver1:3.4
* Updated ICV packages and IPP integration * core(test): minMaxIdx IPP regression test * core(ipp): workaround minMaxIdx problem * core(ipp): workaround meanStdDev() CV_32FC3 buffer overrun * Returned semicolon after CV_INSTRUMENT_REGION_IPP()
This commit is contained in:
committed by
Alexander Alekhin
parent
c8fc8d210b
commit
e397434cb6
@@ -767,9 +767,13 @@ CV_EXPORTS_W void setUseIPP(bool flag);
|
||||
CV_EXPORTS_W String getIppVersion();
|
||||
|
||||
// IPP Not-Exact mode. This function may force use of IPP then both IPP and OpenCV provide proper results
|
||||
// but have internal accuracy differences which have to much direct or indirect impact on accuracy tests.
|
||||
// but have internal accuracy differences which have too much direct or indirect impact on accuracy tests.
|
||||
CV_EXPORTS_W bool useIPP_NotExact();
|
||||
CV_EXPORTS_W void setUseIPP_NotExact(bool flag);
|
||||
#if OPENCV_ABI_COMPATIBILITY < 400
|
||||
CV_EXPORTS_W bool useIPP_NE();
|
||||
CV_EXPORTS_W void setUseIPP_NE(bool flag);
|
||||
#endif
|
||||
|
||||
} // ipp
|
||||
|
||||
|
||||
@@ -194,8 +194,8 @@ T* allocSingleton(size_t count = 1) { return static_cast<T*>(allocSingletonBuffe
|
||||
#define IPP_DISABLE_LAB_RGB 1 // breaks OCL accuracy tests
|
||||
#define IPP_DISABLE_RGB_XYZ 1 // big accuracy difference
|
||||
#define IPP_DISABLE_XYZ_RGB 1 // big accuracy difference
|
||||
#define IPP_DISABLE_HAAR 1 // improper integration/results
|
||||
#define IPP_DISABLE_HOUGH 1 // improper integration/results
|
||||
#define IPP_DISABLE_FILTER2D_BIG_MASK 1 // different results on masks > 7x7
|
||||
|
||||
#define IPP_DISABLE_GAUSSIANBLUR_PARALLEL 1 // not supported (2017u2 / 2017u3)
|
||||
|
||||
@@ -229,7 +229,9 @@ T* allocSingleton(size_t count = 1) { return static_cast<T*>(allocSingletonBuffe
|
||||
# pragma GCC diagnostic ignored "-Wsuggest-override"
|
||||
# endif
|
||||
#include "iw++/iw.hpp"
|
||||
# ifdef HAVE_IPP_IW_LL
|
||||
#include "iw/iw_ll.h"
|
||||
# endif
|
||||
# if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5
|
||||
# pragma GCC diagnostic pop
|
||||
# endif
|
||||
|
||||
@@ -341,7 +341,7 @@ namespace cv
|
||||
{
|
||||
static bool ipp_extractChannel(const Mat &src, Mat &dst, int channel)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
int srcChannels = src.channels();
|
||||
@@ -379,7 +379,7 @@ static bool ipp_extractChannel(const Mat &src, Mat &dst, int channel)
|
||||
|
||||
static bool ipp_insertChannel(const Mat &src, Mat &dst, int channel)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
int srcChannels = src.channels();
|
||||
|
||||
@@ -328,7 +328,7 @@ void Mat::copyTo( OutputArray _dst ) const
|
||||
#ifdef HAVE_IPP
|
||||
static bool ipp_copyTo(const Mat &src, Mat &dst, const Mat &mask)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
if(mask.channels() > 1 || mask.depth() != CV_8U)
|
||||
@@ -463,7 +463,7 @@ Mat& Mat::operator = (const Scalar& s)
|
||||
#ifdef HAVE_IPP
|
||||
static bool ipp_Mat_setTo_Mat(Mat &dst, Mat &_val, Mat &mask)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
if(mask.empty())
|
||||
@@ -1152,7 +1152,7 @@ namespace cv {
|
||||
static bool ipp_copyMakeBorder( Mat &_src, Mat &_dst, int top, int bottom,
|
||||
int left, int right, int _borderType, const Scalar& value )
|
||||
{
|
||||
#if defined HAVE_IPP_IW && !IPP_DISABLE_PERF_COPYMAKE
|
||||
#if defined HAVE_IPP_IW_LL && !IPP_DISABLE_PERF_COPYMAKE
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
::ipp::IwiBorderSize borderSize(left, top, right, bottom);
|
||||
|
||||
@@ -674,6 +674,11 @@ static bool ipp_meanStdDev(Mat& src, OutputArray _mean, OutputArray _sdv, Mat& m
|
||||
if (cn > 1)
|
||||
return false;
|
||||
#endif
|
||||
#if IPP_VERSION_X100 < 201901
|
||||
// IPP_DISABLE: 32f C3C functions can read outside of allocated memory
|
||||
if (cn > 1 && src.depth() == CV_32F)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
size_t total_size = src.total();
|
||||
int rows = src.size[0], cols = rows ? (int)(total_size/rows) : 0;
|
||||
|
||||
@@ -228,7 +228,7 @@ static MergeFunc getMergeFunc(int depth)
|
||||
namespace cv {
|
||||
static bool ipp_merge(const Mat* mv, Mat& dst, int channels)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
if(channels != 3 && channels != 4)
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "opencv2/core/openvx/ovx_defs.hpp"
|
||||
#include "stat.hpp"
|
||||
|
||||
#define IPP_DISABLE_MINMAXIDX_MANY_ROWS 1 // see Core_MinMaxIdx.rows_overflow test
|
||||
|
||||
/****************************************************************************************\
|
||||
* minMaxLoc *
|
||||
\****************************************************************************************/
|
||||
@@ -624,6 +626,10 @@ static bool ipp_minMaxIdx(Mat &src, double* _minVal, double* _maxVal, int* _minI
|
||||
if(src.dims <= 2)
|
||||
{
|
||||
IppiSize size = ippiSize(src.size());
|
||||
#if defined(_WIN32) && !defined(_WIN64) && IPP_VERSION_X100 == 201900 && IPP_DISABLE_MINMAXIDX_MANY_ROWS
|
||||
if (size.height > 65536)
|
||||
return false; // test: Core_MinMaxIdx.rows_overflow
|
||||
#endif
|
||||
size.width *= src.channels();
|
||||
|
||||
status = ippMinMaxFun(src.ptr(), (int)src.step, size, dataType, pMinVal, pMaxVal, pMinIdx, pMaxIdx, (Ipp8u*)mask.ptr(), (int)mask.step);
|
||||
|
||||
@@ -236,7 +236,7 @@ static SplitFunc getSplitFunc(int depth)
|
||||
namespace cv {
|
||||
static bool ipp_split(const Mat& src, Mat* mv, int channels)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
if(channels != 3 && channels != 4)
|
||||
|
||||
@@ -2078,7 +2078,12 @@ public:
|
||||
cv::String env = pIppEnv;
|
||||
if(env.size())
|
||||
{
|
||||
#if IPP_VERSION_X100 >= 201703
|
||||
#if IPP_VERSION_X100 >= 201900
|
||||
const Ipp64u minorFeatures = ippCPUID_MOVBE|ippCPUID_AES|ippCPUID_CLMUL|ippCPUID_ABR|ippCPUID_RDRAND|ippCPUID_F16C|
|
||||
ippCPUID_ADCOX|ippCPUID_RDSEED|ippCPUID_PREFETCHW|ippCPUID_SHA|ippCPUID_MPX|ippCPUID_AVX512CD|ippCPUID_AVX512ER|
|
||||
ippCPUID_AVX512PF|ippCPUID_AVX512BW|ippCPUID_AVX512DQ|ippCPUID_AVX512VL|ippCPUID_AVX512VBMI|ippCPUID_AVX512_4FMADDPS|
|
||||
ippCPUID_AVX512_4VNNIW|ippCPUID_AVX512IFMA;
|
||||
#elif IPP_VERSION_X100 >= 201703
|
||||
const Ipp64u minorFeatures = ippCPUID_MOVBE|ippCPUID_AES|ippCPUID_CLMUL|ippCPUID_ABR|ippCPUID_RDRAND|ippCPUID_F16C|
|
||||
ippCPUID_ADCOX|ippCPUID_RDSEED|ippCPUID_PREFETCHW|ippCPUID_SHA|ippCPUID_MPX|ippCPUID_AVX512CD|ippCPUID_AVX512ER|
|
||||
ippCPUID_AVX512PF|ippCPUID_AVX512BW|ippCPUID_AVX512DQ|ippCPUID_AVX512VL|ippCPUID_AVX512VBMI;
|
||||
@@ -2279,7 +2284,7 @@ void setUseIPP(bool flag)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool useIPP_NE()
|
||||
bool useIPP_NotExact()
|
||||
{
|
||||
#ifdef HAVE_IPP
|
||||
CoreTLSData* data = getCoreTlsData().get();
|
||||
@@ -2293,17 +2298,29 @@ bool useIPP_NE()
|
||||
#endif
|
||||
}
|
||||
|
||||
void setUseIPP_NE(bool flag)
|
||||
void setUseIPP_NotExact(bool flag)
|
||||
{
|
||||
CoreTLSData* data = getCoreTlsData().get();
|
||||
#ifdef HAVE_IPP
|
||||
data->useIPP_NE = (getIPPSingleton().useIPP_NE)?flag:false;
|
||||
data->useIPP_NE = flag;
|
||||
#else
|
||||
CV_UNUSED(flag);
|
||||
data->useIPP_NE = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if OPENCV_ABI_COMPATIBILITY < 400
|
||||
bool useIPP_NE()
|
||||
{
|
||||
return useIPP_NotExact();
|
||||
}
|
||||
|
||||
void setUseIPP_NE(bool flag)
|
||||
{
|
||||
setUseIPP_NotExact(flag);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace ipp
|
||||
|
||||
} // namespace cv
|
||||
|
||||
@@ -2298,4 +2298,30 @@ TEST(UMat_Core_DivideRules, type_32f) { testDivide<float, true>(); }
|
||||
TEST(Core_DivideRules, type_64f) { testDivide<double, false>(); }
|
||||
TEST(UMat_Core_DivideRules, type_64f) { testDivide<double, true>(); }
|
||||
|
||||
|
||||
TEST(Core_MinMaxIdx, rows_overflow)
|
||||
{
|
||||
const int N = 65536 + 1;
|
||||
const int M = 1;
|
||||
{
|
||||
setRNGSeed(123);
|
||||
Mat m(N, M, CV_32FC1);
|
||||
randu(m, -100, 100);
|
||||
double minVal = 0, maxVal = 0;
|
||||
int minIdx[CV_MAX_DIM] = { 0 }, maxIdx[CV_MAX_DIM] = { 0 };
|
||||
cv::minMaxIdx(m, &minVal, &maxVal, minIdx, maxIdx);
|
||||
|
||||
double minVal0 = 0, maxVal0 = 0;
|
||||
int minIdx0[CV_MAX_DIM] = { 0 }, maxIdx0[CV_MAX_DIM] = { 0 };
|
||||
cv::ipp::setUseIPP(false);
|
||||
cv::minMaxIdx(m, &minVal0, &maxVal0, minIdx0, maxIdx0);
|
||||
cv::ipp::setUseIPP(true);
|
||||
|
||||
EXPECT_FALSE(fabs(minVal0 - minVal) > 1e-6 || fabs(maxVal0 - maxVal) > 1e-6) << "NxM=" << N << "x" << M <<
|
||||
" min=" << minVal0 << " vs " << minVal <<
|
||||
" max=" << maxVal0 << " vs " << maxVal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}} // namespace
|
||||
|
||||
@@ -4585,7 +4585,7 @@ static bool ippFilter2D(int stype, int dtype, int kernel_type,
|
||||
return false;
|
||||
#endif
|
||||
|
||||
#if IPP_VERSION_X100 < 201801
|
||||
#if IPP_DISABLE_FILTER2D_BIG_MASK
|
||||
// Too big difference compared to OpenCV FFT-based convolution
|
||||
if(kernel_type == CV_32FC1 && (type == ipp16s || type == ipp16u) && (kernel_width > 7 || kernel_height > 7))
|
||||
return false;
|
||||
|
||||
@@ -3321,7 +3321,7 @@ static bool ipp_resize(const uchar * src_data, size_t src_step, int src_width, i
|
||||
return false;
|
||||
|
||||
// Resize which doesn't match OpenCV exactly
|
||||
if (!cv::ipp::useIPP_NE())
|
||||
if (!cv::ipp::useIPP_NotExact())
|
||||
{
|
||||
if (ippInter == ippNearest || ippInter == ippSuper || (ippDataType == ipp8u && ippInter == ippLinear))
|
||||
return false;
|
||||
|
||||
+47
-212
@@ -94,7 +94,6 @@ typedef struct CvHidHaarClassifierCascade
|
||||
sqsumtype *pq0, *pq1, *pq2, *pq3;
|
||||
sumtype *p0, *p1, *p2, *p3;
|
||||
|
||||
void** ipp_stages;
|
||||
bool is_tree;
|
||||
bool isStumpBased;
|
||||
} CvHidHaarClassifierCascade;
|
||||
@@ -128,23 +127,6 @@ icvReleaseHidHaarClassifierCascade( CvHidHaarClassifierCascade** _cascade )
|
||||
{
|
||||
if( _cascade && *_cascade )
|
||||
{
|
||||
#ifdef HAVE_IPP
|
||||
CvHidHaarClassifierCascade* cascade = *_cascade;
|
||||
if( CV_IPP_CHECK_COND && cascade->ipp_stages )
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < cascade->count; i++ )
|
||||
{
|
||||
if( cascade->ipp_stages[i] )
|
||||
#if IPP_VERSION_X100 < 900 && !IPP_DISABLE_HAAR
|
||||
ippiHaarClassifierFree_32f( (IppiHaarClassifier_32f*)cascade->ipp_stages[i] );
|
||||
#else
|
||||
cvFree(&cascade->ipp_stages[i]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
cvFree( &cascade->ipp_stages );
|
||||
#endif
|
||||
cvFree( _cascade );
|
||||
}
|
||||
}
|
||||
@@ -153,10 +135,6 @@ icvReleaseHidHaarClassifierCascade( CvHidHaarClassifierCascade** _cascade )
|
||||
static CvHidHaarClassifierCascade*
|
||||
icvCreateHidHaarClassifierCascade( CvHaarClassifierCascade* cascade )
|
||||
{
|
||||
CvRect* ipp_features = 0;
|
||||
float *ipp_weights = 0, *ipp_thresholds = 0, *ipp_val1 = 0, *ipp_val2 = 0;
|
||||
int* ipp_counts = 0;
|
||||
|
||||
CvHidHaarClassifierCascade* out = 0;
|
||||
|
||||
int i, j, k, l;
|
||||
@@ -312,72 +290,9 @@ icvCreateHidHaarClassifierCascade( CvHaarClassifierCascade* cascade )
|
||||
}
|
||||
}
|
||||
|
||||
#if defined HAVE_IPP && !IPP_DISABLE_HAAR
|
||||
int can_use_ipp = CV_IPP_CHECK_COND && (!out->has_tilted_features && !out->is_tree && out->isStumpBased);
|
||||
|
||||
if( can_use_ipp )
|
||||
{
|
||||
int ipp_datasize = cascade->count*sizeof(out->ipp_stages[0]);
|
||||
float ipp_weight_scale=(float)(1./((orig_window_size.width-icv_object_win_border*2)*
|
||||
(orig_window_size.height-icv_object_win_border*2)));
|
||||
|
||||
out->ipp_stages = (void**)cvAlloc( ipp_datasize );
|
||||
memset( out->ipp_stages, 0, ipp_datasize );
|
||||
|
||||
ipp_features = (CvRect*)cvAlloc( max_count*3*sizeof(ipp_features[0]) );
|
||||
ipp_weights = (float*)cvAlloc( max_count*3*sizeof(ipp_weights[0]) );
|
||||
ipp_thresholds = (float*)cvAlloc( max_count*sizeof(ipp_thresholds[0]) );
|
||||
ipp_val1 = (float*)cvAlloc( max_count*sizeof(ipp_val1[0]) );
|
||||
ipp_val2 = (float*)cvAlloc( max_count*sizeof(ipp_val2[0]) );
|
||||
ipp_counts = (int*)cvAlloc( max_count*sizeof(ipp_counts[0]) );
|
||||
|
||||
for( i = 0; i < cascade->count; i++ )
|
||||
{
|
||||
CvHaarStageClassifier* stage_classifier = cascade->stage_classifier + i;
|
||||
for( j = 0, k = 0; j < stage_classifier->count; j++ )
|
||||
{
|
||||
CvHaarClassifier* classifier = stage_classifier->classifier + j;
|
||||
int rect_count = 2 + (classifier->haar_feature->rect[2].r.width != 0);
|
||||
|
||||
ipp_thresholds[j] = classifier->threshold[0];
|
||||
ipp_val1[j] = classifier->alpha[0];
|
||||
ipp_val2[j] = classifier->alpha[1];
|
||||
ipp_counts[j] = rect_count;
|
||||
|
||||
for( l = 0; l < rect_count; l++, k++ )
|
||||
{
|
||||
ipp_features[k] = classifier->haar_feature->rect[l].r;
|
||||
//ipp_features[k].y = orig_window_size.height - ipp_features[k].y - ipp_features[k].height;
|
||||
ipp_weights[k] = classifier->haar_feature->rect[l].weight*ipp_weight_scale;
|
||||
}
|
||||
}
|
||||
|
||||
if( ippiHaarClassifierInitAlloc_32f( (IppiHaarClassifier_32f**)&out->ipp_stages[i],
|
||||
(const IppiRect*)ipp_features, ipp_weights, ipp_thresholds,
|
||||
ipp_val1, ipp_val2, ipp_counts, stage_classifier->count ) < 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
if( i < cascade->count )
|
||||
{
|
||||
for( j = 0; j < i; j++ )
|
||||
if( out->ipp_stages[i] )
|
||||
ippiHaarClassifierFree_32f( (IppiHaarClassifier_32f*)out->ipp_stages[i] );
|
||||
cvFree( &out->ipp_stages );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
cascade->hid_cascade = out;
|
||||
assert( (char*)haar_node_ptr - (char*)out <= datasize );
|
||||
|
||||
cvFree( &ipp_features );
|
||||
cvFree( &ipp_weights );
|
||||
cvFree( &ipp_thresholds );
|
||||
cvFree( &ipp_val1 );
|
||||
cvFree( &ipp_val2 );
|
||||
cvFree( &ipp_counts );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -975,120 +890,54 @@ public:
|
||||
std::vector<int> rejectLevelsLocal;
|
||||
std::vector<double> levelWeightsLocal;
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
if(CV_IPP_CHECK_COND && cascade->hid_cascade->ipp_stages )
|
||||
{
|
||||
IppiRect iequRect = {equRect.x, equRect.y, equRect.width, equRect.height};
|
||||
CV_INSTRUMENT_FUN_IPP(ippiRectStdDev_32f_C1R, sum1.ptr<float>(y1), (int)sum1.step,
|
||||
sqsum1.ptr<double>(y1), (int)sqsum1.step,
|
||||
norm1->ptr<float>(y1), (int)norm1->step,
|
||||
ippiSize(ssz.width, ssz.height), iequRect);
|
||||
|
||||
int positive = (ssz.width/ystep)*((ssz.height + ystep-1)/ystep);
|
||||
|
||||
if( ystep == 1 )
|
||||
(*mask1) = Scalar::all(1);
|
||||
else
|
||||
for( y = y1; y < y2; y++ )
|
||||
{
|
||||
uchar* mask1row = mask1->ptr(y);
|
||||
memset( mask1row, 0, ssz.width );
|
||||
|
||||
if( y % ystep == 0 )
|
||||
for( x = 0; x < ssz.width; x += ystep )
|
||||
mask1row[x] = (uchar)1;
|
||||
}
|
||||
|
||||
for( int j = 0; j < cascade->count; j++ )
|
||||
for( y = y1; y < y2; y += ystep )
|
||||
for( x = 0; x < ssz.width; x += ystep )
|
||||
{
|
||||
if (CV_INSTRUMENT_FUN_IPP(ippiApplyHaarClassifier_32f_C1R,
|
||||
sum1.ptr<float>(y1), (int)sum1.step,
|
||||
norm1->ptr<float>(y1), (int)norm1->step,
|
||||
mask1->ptr<uchar>(y1), (int)mask1->step,
|
||||
ippiSize(ssz.width, ssz.height), &positive,
|
||||
cascade->hid_cascade->stage_classifier[j].threshold,
|
||||
(IppiHaarClassifier_32f*)cascade->hid_cascade->ipp_stages[j]) < 0 )
|
||||
positive = 0;
|
||||
if( positive <= 0 )
|
||||
break;
|
||||
double gypWeight;
|
||||
int result = cvRunHaarClassifierCascadeSum( cascade, cvPoint(x,y), gypWeight, 0 );
|
||||
if( rejectLevels )
|
||||
{
|
||||
if( result == 1 )
|
||||
result = -1*cascade->count;
|
||||
if( cascade->count + result < 4 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
rejectLevelsLocal.push_back(-result);
|
||||
levelWeightsLocal.push_back(gypWeight);
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
rejectLevels->insert(rejectLevels->end(), rejectLevelsLocal.begin(), rejectLevelsLocal.end());
|
||||
levelWeights->insert(levelWeights->end(), levelWeightsLocal.begin(), levelWeightsLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
rejectLevelsLocal.clear();
|
||||
levelWeightsLocal.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( result > 0 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CV_IMPL_ADD(CV_IMPL_IPP|CV_IMPL_MT);
|
||||
|
||||
if( positive > 0 )
|
||||
for( y = y1; y < y2; y += ystep )
|
||||
{
|
||||
uchar* mask1row = mask1->ptr(y);
|
||||
for( x = 0; x < ssz.width; x += ystep )
|
||||
if( mask1row[x] != 0 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
}
|
||||
if( --positive == 0 )
|
||||
break;
|
||||
}
|
||||
if( positive == 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif // IPP
|
||||
for( y = y1; y < y2; y += ystep )
|
||||
for( x = 0; x < ssz.width; x += ystep )
|
||||
{
|
||||
double gypWeight;
|
||||
int result = cvRunHaarClassifierCascadeSum( cascade, cvPoint(x,y), gypWeight, 0 );
|
||||
if( rejectLevels )
|
||||
{
|
||||
if( result == 1 )
|
||||
result = -1*cascade->count;
|
||||
if( cascade->count + result < 4 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
rejectLevelsLocal.push_back(-result);
|
||||
levelWeightsLocal.push_back(gypWeight);
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
rejectLevels->insert(rejectLevels->end(), rejectLevelsLocal.begin(), rejectLevelsLocal.end());
|
||||
levelWeights->insert(levelWeights->end(), levelWeightsLocal.begin(), levelWeightsLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
rejectLevelsLocal.clear();
|
||||
levelWeightsLocal.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( result > 0 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rejectLevelsLocal.size())
|
||||
{
|
||||
@@ -1283,12 +1132,6 @@ cvHaarDetectObjectsForROC( const CvArr* _img,
|
||||
if( flags & CV_HAAR_SCALE_IMAGE )
|
||||
{
|
||||
CvSize winSize0 = cascade->orig_window_size;
|
||||
#ifdef HAVE_IPP
|
||||
int use_ipp = CV_IPP_CHECK_COND && (cascade->hid_cascade->ipp_stages != 0);
|
||||
|
||||
if( use_ipp )
|
||||
normImg.reset(cvCreateMat( img->rows, img->cols, CV_32FC1));
|
||||
#endif
|
||||
imgSmall.reset(cvCreateMat( img->rows + 1, img->cols + 1, CV_8UC1 ));
|
||||
|
||||
for( factor = 1; ; factor *= scaleFactor )
|
||||
@@ -1330,15 +1173,7 @@ cvHaarDetectObjectsForROC( const CvArr* _img,
|
||||
int stripCount = ((sz1.width/ystep)*(sz1.height + ystep-1)/ystep + LOCS_PER_THREAD/2)/LOCS_PER_THREAD;
|
||||
stripCount = std::min(std::max(stripCount, 1), 100);
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
if( use_ipp )
|
||||
{
|
||||
cv::Mat fsum(sum1.rows, sum1.cols, CV_32F, sum1.data.ptr, sum1.step);
|
||||
cv::cvarrToMat(&sum1).convertTo(fsum, CV_32F, 1, -(1<<24));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
cvSetImagesForHaarClassifierCascade( cascade, &sum1, &sqsum1, _tilted, 1. );
|
||||
cvSetImagesForHaarClassifierCascade( cascade, &sum1, &sqsum1, _tilted, 1. );
|
||||
|
||||
cv::Mat _norm1 = cv::cvarrToMat(&norm1), _mask1 = cv::cvarrToMat(&mask1);
|
||||
cv::parallel_for_(cv::Range(0, stripCount),
|
||||
|
||||
Reference in New Issue
Block a user