• opencv CalcHist2D_8uInvoker


    opencv  CalcHist2D_8uInvoker

    class CalcHist2D_8uInvoker
    {
    public:
        CalcHist2D_8uInvoker( const std::vector<uchar*>& _ptrs, const std::vector<int>& _deltas,
                              Size imsize, Mat& hist, int dims, const std::vector<size_t>& _tab,
                              tbb::mutex* lock )
            : mask_(_ptrs[dims]),
              mstep_(_deltas[dims*2 + 1]),
              imageWidth_(imsize.width),
              histSize_(hist.size()), histType_(hist.type()),
              tab_((size_t*)&_tab[0]),
              histogramWriteLock_(lock),
              globalHistogram_(hist.data)
        {
            p_[0] = (uchar*)(&_ptrs[0])[0]; p_[1] = (uchar*)(&_ptrs[0])[1];
            step_[0] = (&_deltas[0])[1];    step_[1] = (&_deltas[0])[3];
            d_[0] = (&_deltas[0])[0];       d_[1] = (&_deltas[0])[2];
        }
    
        void operator()( const BlockedRange& range ) const
        {
            uchar* p0 = p_[0] + range.begin()*(step_[0] + imageWidth_*d_[0]);
            uchar* p1 = p_[1] + range.begin()*(step_[1] + imageWidth_*d_[1]);
            uchar* mask = mask_ + range.begin()*mstep_;
    
            Mat localHist = Mat::zeros(histSize_, histType_);
            uchar* localHistData = localHist.data;
            tbb::mutex::scoped_lock lock;
    
            for(int i = range.begin(); i < range.end(); i++, p0 += step_[0], p1 += step_[1])
            {
                if( !mask_ )
                {
                    for( int x = 0; x < imageWidth_; x++, p0 += d_[0], p1 += d_[1] )
                    {
                        size_t idx = tab_[*p0] + tab_[*p1 + 256];
                        if( idx < OUT_OF_RANGE )
                        {
                            ++*(int*)(localHistData + idx);
                        }
                    }
                }
                else
                {
                    for( int x = 0; x < imageWidth_; x++, p0 += d_[0], p1 += d_[1] )
                    {
                        size_t idx;
                        if( mask[x] && (idx = tab_[*p0] + tab_[*p1 + 256]) < OUT_OF_RANGE )
                        {
                            ++*(int*)(localHistData + idx);
                        }
                    }
                    mask += mstep_;
                }
            }
    
            lock.acquire(*histogramWriteLock_);
            for(int i = 0; i < histSize_.width*histSize_.height; i++)
            {
                ((int*)globalHistogram_)[i] += ((int*)localHistData)[i];
            }
            lock.release();
        }
    
        static bool isFit( const Mat& histogram, const Size imageSize )
        {
            return ( (histogram.total() > 4*4 &&  histogram.total() <= 116*116
                      && imageSize.width * imageSize.height >= 320*240)
                     || (histogram.total() > 116*116 && imageSize.width * imageSize.height >= 1280*720) );
        }
    
    private:
        uchar* p_[two];
        uchar* mask_;
        int step_[two];
        int d_[two];
        int mstep_;
        int imageWidth_;
        Size histSize_;
        int histType_;
        size_t* tab_;
        tbb::mutex* histogramWriteLock_;
        uchar* globalHistogram_;
    };

    代码参考:opencv-3.4.1modulesimgprocsrchistogram.cpp

    ########################################

    QQ 3087438119
  • 相关阅读:
    每天出门前,记得提醒自己一遍,别落下了梦想
    逐帧动画 and 有限状态机(fsm)
    【备忘】指定为同名callback的jsonp && IE下script loaded状态标记
    【NodeCC】nodejs版本的脚本压缩和compo工具
    半年拾遗
    context2D上的texture mapping
    软件系统配置UI(QT)
    MongoDB增加排序内存版本4.4.1
    搭建Mingw64环境并使用git管理ffmpeg
    js 运算符
  • 原文地址:https://www.cnblogs.com/herd/p/15441279.html
Copyright © 2020-2023  润新知