예제 #1
0
void BackgroundSubtractorLOBSTER_<ParallelUtils::eGLSL>::getBackgroundDescriptorsImage(cv::OutputArray oBGDescImg) const {
    lvDbgExceptionWatch;
    CV_Assert(m_bInitialized);
    glAssert(m_bGLInitialized && !m_vnBGModelData.empty());
    CV_Assert(LBSP::DESC_SIZE==2);
    oBGDescImg.create(m_oFrameSize,CV_16UC(int(m_nImgChannels)));
    cv::Mat oOutputImg = oBGDescImg.getMatRef();
    glBindBuffer(GL_SHADER_STORAGE_BUFFER,getSSBOId(BackgroundSubtractorLOBSTER_::eLOBSTERStorageBuffer_BGModelBinding));
    glGetBufferSubData(GL_SHADER_STORAGE_BUFFER,0,m_nBGModelSize*sizeof(uint),(void*)m_vnBGModelData.data());
    glErrorCheck;
    for(size_t nRowIdx=0; nRowIdx<(size_t)m_oFrameSize.height; ++nRowIdx) {
        const size_t nModelRowOffset = nRowIdx*m_nRowStepSize;
        const size_t nImgRowOffset = nRowIdx*oOutputImg.step.p[0];
        for(size_t nColIdx=0; nColIdx<(size_t)m_oFrameSize.width; ++nColIdx) {
            const size_t nModelColOffset = nColIdx*m_nColStepSize+nModelRowOffset;
            const size_t nImgColOffset = nColIdx*oOutputImg.step.p[1]+nImgRowOffset;
            std::array<float,4> afCurrPxSum = {0.0f,0.0f,0.0f,0.0f};
            for(size_t nSampleIdx=0; nSampleIdx<m_nBGSamples; ++nSampleIdx) {
                const size_t nModelPxOffset_color = nSampleIdx*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 = nChannelIdx+nModelPxOffset_desc;
                    afCurrPxSum[nChannelIdx] += m_vnBGModelData[nModelTotOffset];
                }
            }
            for(size_t nChannelIdx=0; nChannelIdx<m_nImgChannels; ++nChannelIdx) {
                const size_t nSampleChannelIdx = ((nChannelIdx==3||m_nImgChannels==1)?nChannelIdx:2-nChannelIdx);
                const size_t nImgTotOffset = nSampleChannelIdx*2+nImgColOffset;
                *(ushort*)(oOutputImg.data+nImgTotOffset) = (ushort)(afCurrPxSum[nChannelIdx]/m_nBGSamples);
            }
        }
    }
}
예제 #2
0
    void findTemplateMatchCandidates(
        cv::InputArray image,
        cv::InputArray templ,
        cv::InputArray templMask,
        cv::OutputArray candidates,
        cv::Size partitionSize,
        int maxWeakErrors, 
        float maxMeanDifference)
    {
        TemplateMatchCandidates tmc;
        tmc.setSourceImage(image.getMat());
        tmc.setPartitionSize(partitionSize);
        tmc.setTemplateSize(templ.size());
        tmc.initialize();

        candidates.create(
            image.size().height - templ.size().height + 1, 
            image.size().width - templ.size().width + 1,            
            CV_8UC1);

        tmc.findCandidates(templ.getMat(), templMask.getMat(), candidates.getMatRef(), maxWeakErrors, maxMeanDifference);
    }