Пример #1
0
    void FillRhombMask(View & mask, const Rect & rect, uint8_t index)
    {
        assert(mask.format == View::Gray8 && Rect(mask.Size()).Contains(rect));

        Simd::Fill(mask, 0);

        Point c = rect.Center();
        for(ptrdiff_t row = rect.top; row < rect.bottom; ++row)
        {
            ptrdiff_t indent = std::abs(row - c.y)*rect.Width()/rect.Height();
            ptrdiff_t left = rect.left + indent;
            ptrdiff_t right = rect.right - indent;
            ptrdiff_t offset = row*mask.stride + left;
            for(ptrdiff_t col = left; col < right; ++col, ++offset)
                mask.data[offset] = Random(2) ? index : 0;
        }
    }
Пример #2
0
        /*!
            Estimates shift of current image relative to background image.

            \param [in] current - current image.
            \param [in] region - a region at the background where the algorithm start to search current image. Estimated shift is taken relative of the region.
            \param [in] maxShift - a 2D-point which characterizes maximal possible shift of the region (along X and Y axes).
            \param [in] hiddenAreaPenalty - a parameter used to restrict searching of the shift at the border of background image.
            \param [in] regionAreaMin - a parameter used to set minimal area of region use for shift estimation. By default is equal to 25.
            \return a result of shift estimation.
        */
        bool Estimate(const View & current, const Rect & region, const Point & maxShift, double hiddenAreaPenalty = 0, ptrdiff_t regionAreaMin = REGION_CORRELATION_AREA_MIN)
        {
            assert(current.Size() == region.Size() && region.Area() > 0);
            assert(_current.Size() && _current[0].width >= current.width && _current[0].height >= current.height);

            if (region.Area() < regionAreaMin)
                return false;

            InitLevels(region, maxShift, regionAreaMin);
            SetCurrent(current, region);

            Point shift;
            for (ptrdiff_t i = _levels.size() - 1; i >= 0; i--)
            {
                shift.x *= 2;
                shift.y *= 2;
                if (!SearchLocalMin(_levels[i], shift, hiddenAreaPenalty))
                    return false;
                shift = _levels[i].shift;
            }
            return true;
        }