mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
@@ -1112,6 +1112,7 @@ static bool ippFilter2D(int stype, int dtype, int kernel_type,
|
||||
static bool dftFilter2D(int stype, int dtype, int kernel_type,
|
||||
uchar * src_data, size_t src_step,
|
||||
uchar * dst_data, size_t dst_step,
|
||||
int width, int height,
|
||||
int full_width, int full_height,
|
||||
int offset_x, int offset_y,
|
||||
uchar * kernel_data, size_t kernel_step,
|
||||
@@ -1125,13 +1126,23 @@ static bool dftFilter2D(int stype, int dtype, int kernel_type,
|
||||
int dft_filter_size = checkHardwareSupport(CV_CPU_SSE3) && ((sdepth == CV_8U && (ddepth == CV_8U || ddepth == CV_16S)) || (sdepth == CV_32F && ddepth == CV_32F)) ? 130 : 50;
|
||||
if (kernel_width * kernel_height < dft_filter_size)
|
||||
return false;
|
||||
|
||||
// detect roi case
|
||||
if( (offset_x != 0) || (offset_y != 0) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( (width != full_width) || (height != full_height) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Point anchor = Point(anchor_x, anchor_y);
|
||||
Mat kernel = Mat(Size(kernel_width, kernel_height), kernel_type, kernel_data, kernel_step);
|
||||
|
||||
Mat src(Size(full_width-offset_x, full_height-offset_y), stype, src_data, src_step);
|
||||
Mat dst(Size(full_width, full_height), dtype, dst_data, dst_step);
|
||||
Mat src(Size(width, height), stype, src_data, src_step);
|
||||
Mat dst(Size(width, height), dtype, dst_data, dst_step);
|
||||
Mat temp;
|
||||
int src_channels = CV_MAT_CN(stype);
|
||||
int dst_channels = CV_MAT_CN(dtype);
|
||||
@@ -1144,10 +1155,10 @@ static bool dftFilter2D(int stype, int dtype, int kernel_type,
|
||||
// we just use that.
|
||||
int corrDepth = ddepth;
|
||||
if ((ddepth == CV_32F || ddepth == CV_64F) && src_data != dst_data) {
|
||||
temp = Mat(Size(full_width, full_height), dtype, dst_data, dst_step);
|
||||
temp = Mat(Size(width, height), dtype, dst_data, dst_step);
|
||||
} else {
|
||||
corrDepth = ddepth == CV_64F ? CV_64F : CV_32F;
|
||||
temp.create(Size(full_width, full_height), CV_MAKETYPE(corrDepth, dst_channels));
|
||||
temp.create(Size(width, height), CV_MAKETYPE(corrDepth, dst_channels));
|
||||
}
|
||||
crossCorr(src, kernel, temp, src.size(),
|
||||
CV_MAKETYPE(corrDepth, src_channels),
|
||||
@@ -1158,9 +1169,9 @@ static bool dftFilter2D(int stype, int dtype, int kernel_type,
|
||||
}
|
||||
} else {
|
||||
if (src_data != dst_data)
|
||||
temp = Mat(Size(full_width, full_height), dtype, dst_data, dst_step);
|
||||
temp = Mat(Size(width, height), dtype, dst_data, dst_step);
|
||||
else
|
||||
temp.create(Size(full_width, full_height), dtype);
|
||||
temp.create(Size(width, height), dtype);
|
||||
crossCorr(src, kernel, temp, src.size(),
|
||||
CV_MAKETYPE(ddepth, src_channels),
|
||||
anchor, delta, borderType);
|
||||
@@ -1293,6 +1304,7 @@ void filter2D(int stype, int dtype, int kernel_type,
|
||||
res = dftFilter2D(stype, dtype, kernel_type,
|
||||
src_data, src_step,
|
||||
dst_data, dst_step,
|
||||
width, height,
|
||||
full_width, full_height,
|
||||
offset_x, offset_y,
|
||||
kernel_data, kernel_step,
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
using namespace cv;
|
||||
using namespace detail;
|
||||
|
||||
namespace {
|
||||
|
||||
/*
|
||||
This is implementation of image segmentation algorithm GrabCut described in
|
||||
"GrabCut - Interactive Foreground Extraction using Iterated Graph Cuts".
|
||||
@@ -229,6 +231,8 @@ void GMM::calcInverseCovAndDeterm(int ci, const double singularFix)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/*
|
||||
Calculate beta - parameter of GrabCut algorithm.
|
||||
beta = 1/(2*avg(sqr(||color[i] - color[j]||)))
|
||||
@@ -380,12 +384,20 @@ static void initGMMs( const Mat& img, const Mat& mask, GMM& bgdGMM, GMM& fgdGMM
|
||||
}
|
||||
}
|
||||
CV_Assert( !bgdSamples.empty() && !fgdSamples.empty() );
|
||||
Mat _bgdSamples( (int)bgdSamples.size(), 3, CV_32FC1, &bgdSamples[0][0] );
|
||||
kmeans( _bgdSamples, GMM::componentsCount, bgdLabels,
|
||||
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType );
|
||||
Mat _fgdSamples( (int)fgdSamples.size(), 3, CV_32FC1, &fgdSamples[0][0] );
|
||||
kmeans( _fgdSamples, GMM::componentsCount, fgdLabels,
|
||||
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType );
|
||||
{
|
||||
Mat _bgdSamples( (int)bgdSamples.size(), 3, CV_32FC1, &bgdSamples[0][0] );
|
||||
int num_clusters = GMM::componentsCount;
|
||||
num_clusters = std::min(num_clusters, (int)bgdSamples.size());
|
||||
kmeans( _bgdSamples, num_clusters, bgdLabels,
|
||||
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType );
|
||||
}
|
||||
{
|
||||
Mat _fgdSamples( (int)fgdSamples.size(), 3, CV_32FC1, &fgdSamples[0][0] );
|
||||
int num_clusters = GMM::componentsCount;
|
||||
num_clusters = std::min(num_clusters, (int)fgdSamples.size());
|
||||
kmeans( _fgdSamples, num_clusters, fgdLabels,
|
||||
TermCriteria( CV_TERMCRIT_ITER, kMeansItCount, 0.0), 0, kMeansType );
|
||||
}
|
||||
|
||||
bgdGMM.initLearning();
|
||||
for( int i = 0; i < (int)bgdSamples.size(); i++ )
|
||||
|
||||
Reference in New Issue
Block a user