Пример #1
0
float FastCorner::shiTomasiScore_10(const ImageRef<unsigned char>& im, const Point2i& pos)
{
    const unsigned char* p3 = &(im.data())[(pos.y - 3) * im.width()];
    const unsigned char* p2 = &(im.data())[(pos.y - 2) * im.width()];
    const unsigned char* p1 = &(im.data())[(pos.y - 1) * im.width()];
    const unsigned char* s  = &(im.data())[pos.y * im.width()];
    const unsigned char* n1 = &(im.data())[(pos.y + 1) * im.width()];
    const unsigned char* n2 = &(im.data())[(pos.y + 2) * im.width()];
    const unsigned char* n3 = &(im.data())[(pos.y + 3) * im.width()];
    float Dxx = 0.0f;
    float Dxy = 0.0f;
    float Dyy = 0.0f;
    const int endx = pos.x + 3;
    for (int x = pos.x - 3; x<=endx; ++x) {
        float dx = (float)(p2[x+1] - p2[x-1]); float dy = (float)(p1[x] - p3[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;

        dx = (float)(p1[x+1] - p1[x-1]); dy = (float)(s[x] - p2[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;

        dx = (float)(s[x+1] - s[x-1]); dy = (float)(n1[x] - p1[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;

        dx = (float)(n1[x+1] - n1[x-1]); dy = (float)(n2[x] - s[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;

        dx = (float)(n2[x+1] - n2[x-1]); dy = (float)(n3[x] - n1[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;
    }

    const float sum_Dxx_Dyy = Dxx + Dyy;

    float r = 0.04f * 0.5f * (sum_Dxx_Dyy - std::sqrt(sum_Dxx_Dyy * sum_Dxx_Dyy - 4.0f * (Dxx * Dyy - Dxy * Dxy)));
    return r;
}