|
|
|
@ -96,7 +96,8 @@ void cv::gpu::GMG_GPU::initialize(cv::Size frameSize, float min, float max) |
|
|
|
|
|
|
|
|
|
nfeatures_.setTo(cv::Scalar::all(0)); |
|
|
|
|
|
|
|
|
|
boxFilter_ = cv::gpu::createBoxFilter_GPU(CV_8UC1, CV_8UC1, cv::Size(smoothingRadius, smoothingRadius)); |
|
|
|
|
if (smoothingRadius > 0) |
|
|
|
|
boxFilter_ = cv::gpu::createBoxFilter_GPU(CV_8UC1, CV_8UC1, cv::Size(smoothingRadius, smoothingRadius)); |
|
|
|
|
|
|
|
|
|
loadConstants(frameSize_.width, frameSize_.height, minVal_, maxVal_, quantizationLevels, backgroundPrior, decisionThreshold, maxFeatures, numInitializationFrames); |
|
|
|
|
} |
|
|
|
@ -130,14 +131,21 @@ void cv::gpu::GMG_GPU::operator ()(const cv::gpu::GpuMat& frame, cv::gpu::GpuMat |
|
|
|
|
initialize(frame.size(), 0.0f, frame.depth() == CV_8U ? 255.0f : frame.depth() == CV_16U ? std::numeric_limits<ushort>::max() : 1.0f); |
|
|
|
|
|
|
|
|
|
fgmask.create(frameSize_, CV_8UC1); |
|
|
|
|
if (stream) |
|
|
|
|
stream.enqueueMemSet(fgmask, cv::Scalar::all(0)); |
|
|
|
|
else |
|
|
|
|
fgmask.setTo(cv::Scalar::all(0)); |
|
|
|
|
|
|
|
|
|
funcs[frame.depth()][frame.channels() - 1](frame, fgmask, colors_, weights_, nfeatures_, frameNum_, learningRate, cv::gpu::StreamAccessor::getStream(stream)); |
|
|
|
|
|
|
|
|
|
// medianBlur
|
|
|
|
|
boxFilter_->apply(fgmask, buf_, cv::Rect(0,0,-1,-1), stream); |
|
|
|
|
int minCount = (smoothingRadius * smoothingRadius + 1) / 2; |
|
|
|
|
double thresh = 255.0 * minCount / (smoothingRadius * smoothingRadius); |
|
|
|
|
cv::gpu::threshold(buf_, fgmask, thresh, 255.0, cv::THRESH_BINARY, stream); |
|
|
|
|
if (smoothingRadius > 0) |
|
|
|
|
{ |
|
|
|
|
boxFilter_->apply(fgmask, buf_, cv::Rect(0,0,-1,-1), stream); |
|
|
|
|
int minCount = (smoothingRadius * smoothingRadius + 1) / 2; |
|
|
|
|
double thresh = 255.0 * minCount / (smoothingRadius * smoothingRadius); |
|
|
|
|
cv::gpu::threshold(buf_, fgmask, thresh, 255.0, cv::THRESH_BINARY, stream); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// keep track of how many frames we have processed
|
|
|
|
|
++frameNum_; |
|
|
|
|