Пример #1
0
void BackgroundSubtractorLOBSTER_<ParallelUtils::eGLSL>::refreshModel(float fSamplesRefreshFrac, bool bForceFGUpdate) {
    lvDbgExceptionWatch;
    // == refresh
    CV_Assert(m_bInitialized);
    CV_Assert(fSamplesRefreshFrac>0.0f && fSamplesRefreshFrac<=1.0f);
    const size_t nModelSamplesToRefresh = fSamplesRefreshFrac<1.0f?(size_t)(fSamplesRefreshFrac*m_nBGSamples):m_nBGSamples;
    const size_t nRefreshSampleStartPos = fSamplesRefreshFrac<1.0f?rand()%m_nBGSamples:0;
    if(!bForceFGUpdate)
        getLatestForegroundMask(m_oLastFGMask);
    glBindBuffer(GL_SHADER_STORAGE_BUFFER,getSSBOId(BackgroundSubtractorLOBSTER_::eLOBSTERStorageBuffer_BGModelBinding));
    for(size_t nRowIdx=0; nRowIdx<(size_t)m_oFrameSize.height; ++nRowIdx) {
        const size_t nRowOffset = nRowIdx*m_oFrameSize.height;
        const size_t nModelRowOffset = nRowIdx*m_nRowStepSize;
        for(size_t nColIdx=0; nColIdx<(size_t)m_oFrameSize.width; ++nColIdx) {
            const size_t nColOffset = nColIdx+nRowOffset;
            const size_t nModelColOffset = nColIdx*m_nColStepSize+nModelRowOffset;
            if(bForceFGUpdate || !m_oLastFGMask.data[nColOffset]) {
                for(size_t nCurrModelSampleIdx=nRefreshSampleStartPos; nCurrModelSampleIdx<nRefreshSampleStartPos+nModelSamplesToRefresh; ++nCurrModelSampleIdx) {
                    int nSampleRowIdx, nSampleColIdx;
                    RandUtils::getRandSamplePosition_7x7_std2(nSampleColIdx,nSampleRowIdx,nColIdx,nRowIdx,LBSP::PATCH_SIZE/2,m_oFrameSize);
                    const size_t nSamplePxIdx = nSampleColIdx + nSampleRowIdx*m_oFrameSize.width;
                    if(bForceFGUpdate || !m_oLastFGMask.data[nSamplePxIdx]) {
                        const size_t nCurrRealModelSampleIdx = nCurrModelSampleIdx%m_nBGSamples;
                        const size_t nSampleOffset_color = nSampleColIdx*m_oLastColorFrame.step.p[1]+(nSampleRowIdx*m_oLastColorFrame.step.p[0]);
                        const size_t nSampleOffset_desc = nSampleColIdx*m_oLastDescFrame.step.p[1]+(nSampleRowIdx*m_oLastDescFrame.step.p[0]);
                        const size_t nModelPxOffset_color = nCurrRealModelSampleIdx*m_nSampleStepSize+nModelColOffset;
                        const size_t nModelPxOffset_desc = nModelPxOffset_color+(m_nBGSamples*m_nSampleStepSize);
                        for(size_t nChannelIdx=0; nChannelIdx<m_nImgChannels; ++nChannelIdx) {
                            const size_t nModelTotOffset_color = nChannelIdx+nModelPxOffset_color;
                            const size_t nModelTotOffset_desc = nChannelIdx+nModelPxOffset_desc;
                            const size_t nSampleChannelIdx = ((nChannelIdx==3||m_nImgChannels==1)?nChannelIdx:2-nChannelIdx);
                            const size_t nSampleTotOffset_color = nSampleOffset_color+nSampleChannelIdx;
                            const size_t nSampleTotOffset_desc = nSampleOffset_desc+(nSampleChannelIdx*2);
                            m_vnBGModelData[nModelTotOffset_color] = (uint)m_oLastColorFrame.data[nSampleTotOffset_color];
                            if(m_nImgChannels==1)
                                LBSP::computeDescriptor<1>(m_oLastColorFrame,m_oLastColorFrame.data[nSampleTotOffset_color],nSampleColIdx,nSampleRowIdx,0,m_anLBSPThreshold_8bitLUT[m_oLastColorFrame.data[nSampleTotOffset_color]],*((ushort*)(m_oLastDescFrame.data+nSampleTotOffset_desc)));
                            else if(m_nImgChannels==3)
                                LBSP::computeDescriptor<3>(m_oLastColorFrame,m_oLastColorFrame.data[nSampleTotOffset_color],nSampleColIdx,nSampleRowIdx,nChannelIdx,m_anLBSPThreshold_8bitLUT[m_oLastColorFrame.data[nSampleTotOffset_color]],*((ushort*)(m_oLastDescFrame.data+nSampleTotOffset_desc)));
                            else //m_nImgChannels==4
                                LBSP::computeDescriptor<4>(m_oLastColorFrame,m_oLastColorFrame.data[nSampleTotOffset_color],nSampleColIdx,nSampleRowIdx,nChannelIdx,m_anLBSPThreshold_8bitLUT[m_oLastColorFrame.data[nSampleTotOffset_color]],*((ushort*)(m_oLastDescFrame.data+nSampleTotOffset_desc)));
                            m_vnBGModelData[nModelTotOffset_desc] = (uint)*(ushort*)(m_oLastDescFrame.data+nSampleTotOffset_desc);
                        }
                    }
                }
            }
        }
    }
    glBufferData(GL_SHADER_STORAGE_BUFFER,m_nBGModelSize*sizeof(uint),m_vnBGModelData.data(),GL_STATIC_COPY);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER,BackgroundSubtractorLOBSTER_::eLOBSTERStorageBuffer_BGModelBinding,getSSBOId(BackgroundSubtractorLOBSTER_::eLOBSTERStorageBuffer_BGModelBinding));
    glErrorCheck;
}
Пример #2
0
void IBackgroundSubtractor_GLSL::apply_gl(cv::InputArray oNextImage, cv::OutputArray oLastFGMask, bool bRebindAll, double dLearningRate) {
    apply_gl(oNextImage,bRebindAll,dLearningRate);
    getLatestForegroundMask(oLastFGMask);
}
Пример #3
0
void BackgroundSubtractor_<ParallelUtils::eGLSL>::apply_async(cv::InputArray oNextImage, cv::OutputArray oLastFGMask, double dLearningRate) {
    apply_async(oNextImage,dLearningRate);
    getLatestForegroundMask(oLastFGMask);
}