test_marr_hildreth_hash.cpp 1.72 KB
Newer Older
1 2 3 4 5 6
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#include "test_precomp.hpp"

7
namespace opencv_test { namespace {
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

class CV_MarrHildrethTest : public cvtest::BaseTest
{
public:
    CV_MarrHildrethTest();
    ~CV_MarrHildrethTest();
protected:
    void run(int /* idx */);
};

CV_MarrHildrethTest::CV_MarrHildrethTest(){}
CV_MarrHildrethTest::~CV_MarrHildrethTest(){}

void CV_MarrHildrethTest::run(int )
{
    cv::Mat_<uchar> input(512,512);
    int val = 0;
    for(int row = 0; row != input.rows; ++row)
    {
        for(int col = 0; col != input.cols; ++col)
        {
            input.at<uchar>(row, col) = val % 256;
            ++val;
        }
    }

    cv::Mat hash;
    cv::img_hash::marrHildrethHash(input, hash);
    uchar const expectResult[] =
    {
        252, 126,  63,  31, 143, 199, 227, 241,
        248, 252, 126,  63,  31, 143, 199, 227,
        241, 248, 252, 126,  63,  31, 143, 199,
        227, 241, 248, 252, 126,  63,  31, 143,
        199, 227, 241, 248,  31, 143, 199, 227,
        241, 248, 252, 126,  63, 252, 126,  63,
         31, 143, 199, 227, 241, 248, 252, 126,
         63,  31, 143, 199, 227, 241, 248, 252,
        126,  63,  31, 143, 199, 227, 241, 248
    };
    uchar const *hashPtr = hash.ptr<uchar>(0);
    for(int i = 0; i != 72; ++i)
    {
        if(hashPtr[i] != expectResult[i])
        {
            ts->printf(cvtest::TS::LOG, "Wrong hash value \n");
            ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
            return;
        }
    }
}

TEST(marr_hildreth_test, accuracy) { CV_MarrHildrethTest test; test.safe_run(); }
61 62

}} // namespace