コード例 #1
0
ファイル: gmg.cpp プロジェクト: AaronPlay/opencv
void cv::gpu::GMG_GPU::operator ()(const cv::gpu::GpuMat& frame, cv::gpu::GpuMat& fgmask, float newLearningRate, cv::gpu::Stream& stream)
{
    using namespace cv::gpu::cudev::bgfg_gmg;

    typedef void (*func_t)(PtrStepSzb frame, PtrStepb fgmask, PtrStepSzi colors, PtrStepf weights, PtrStepi nfeatures,
                           int frameNum, float learningRate, bool updateBackgroundModel, cudaStream_t stream);
    static const func_t funcs[6][4] =
    {
        {update_gpu<uchar>, 0, update_gpu<uchar3>, update_gpu<uchar4>},
        {0,0,0,0},
        {update_gpu<ushort>, 0, update_gpu<ushort3>, update_gpu<ushort4>},
        {0,0,0,0},
        {0,0,0,0},
        {update_gpu<float>, 0, update_gpu<float3>, update_gpu<float4>}
    };

    CV_Assert(frame.depth() == CV_8U || frame.depth() == CV_16U || frame.depth() == CV_32F);
    CV_Assert(frame.channels() == 1 || frame.channels() == 3 || frame.channels() == 4);

    if (newLearningRate != -1.0f)
    {
        CV_Assert(newLearningRate >= 0.0f && newLearningRate <= 1.0f);
        learningRate = newLearningRate;
    }

    if (frame.size() != frameSize_)
        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);
    fgmask.setTo(cv::Scalar::all(0), stream);

    funcs[frame.depth()][frame.channels() - 1](frame, fgmask, colors_, weights_, nfeatures_, frameNum_, learningRate, updateBackgroundModel, cv::gpu::StreamAccessor::getStream(stream));

    // medianBlur
    if (smoothingRadius > 0)
    {
        boxFilter_->apply(fgmask, buf_, 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_;
}
コード例 #2
0
void sg::uncropFFTGPU( cv::gpu::GpuMat const & input, cv::gpu::GpuMat & output, std::vector<cv::gpu::GpuMat> & splitBuffer )
{
	cv::Size originalSize = input.size();
	cv::Size oldSize = output.size();

  if( input.channels() > 1 )
  {
		cv::gpu::split( input, splitBuffer );
    splitBuffer[0]( cv::Rect( 0, 0, oldSize.width, oldSize.height ) ).copyTo( output );
  }
	else
  	input( cv::Rect( 0, 0, oldSize.width, oldSize.height ) ).copyTo( output );

	cv::gpu::multiply( output, ( 1.0 / ( originalSize.width * originalSize.height ) ), output );
}
コード例 #3
0
		void meanStdDev(const cv::gpu::GpuMat& mtx,cv::Scalar& mean, cv::Scalar& stddev){
			assert(1==mtx.channels());

			size_t elem_num = mtx.rows * mtx.cols;
			cv::gpu::GpuMat buf;
			mean = cv::gpu::sum( mtx, buf);
			stddev = cv::gpu::sqrSum( mtx, buf);
			for(int i=0;i<mean.cols;i++){
				mean[i] /= elem_num;
			}
			stddev = cv::gpu::sqrSum( mtx, buf);
			for(int i=0;i<stddev.cols;i++){
				stddev[i] /= elem_num;
				stddev[i] = std::sqrt(stddev[i] - std::pow(mean[i],2));
			}
		}
コード例 #4
0
ファイル: mog.cpp プロジェクト: AaronPlay/opencv
void cv::gpu::MOG_GPU::operator()(const cv::gpu::GpuMat& frame, cv::gpu::GpuMat& fgmask, float learningRate, Stream& stream)
{
    using namespace cv::gpu::cudev::mog;

    CV_Assert(frame.depth() == CV_8U);

    int ch = frame.channels();
    int work_ch = ch;

    if (nframes_ == 0 || learningRate >= 1.0 || frame.size() != frameSize_ || work_ch != mean_.channels())
        initialize(frame.size(), frame.type());

    fgmask.create(frameSize_, CV_8UC1);

    ++nframes_;
    learningRate = learningRate >= 0.0f && nframes_ > 1 ? learningRate : 1.0f / std::min(nframes_, history);
    CV_Assert(learningRate >= 0.0f);

    mog_gpu(frame, ch, fgmask, weight_, sortKey_, mean_, var_, nmixtures_,
            varThreshold, learningRate, backgroundRatio, noiseSigma,
            StreamAccessor::getStream(stream));
}