Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I have the same problem as Cory recently, to solve this problem once and for all, I develop an img_hash module for open_contrib, here is the pull request. img_hash module port the image hash algorithms of PHash library and implement some algorithms do not exist in the PHash library, this include color moment hash which provide good resistance to rotation attack(-90 to 90 degree).

The ReadMe of img_hash module should give you enough information of how to use and install the module, if you need more info, please ask me from the forum, or send the question to my [email protected]

ps : At first I give BOVW a shot, the results are solid, but it take too many times to build the coed book and retrieve the features from image. Then I found image hash can help me boost up the speed(although it do not provide best accuracy).

I have the same problem as Cory recently, to solve this problem once and for all, I develop an img_hash module for open_contrib, here is the pull request. img_hash module port the image hash algorithms of PHash library and implement some algorithms do not exist in the PHash library, this include color moment hash which provide good resistance to rotation attack(-90 to 90 degree).

The ReadMe of img_hash module should give you enough information of how to use and install the module, if you need more info, please ask me from the forum, or send the question to my [email protected]

This module is very easy to use, unlike PHash library, the api are consistent and do not force you to handle the resource by yourself.

#include <opencv2/core.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/img_hash.hpp>
#include <opencv2/imgproc.hpp>

void computeHash(cv::Ptr<cv::img_hash::ImgHashBase> algo)
{
    cv::Mat const input = cv::imread("lena.png");
    cv::Mat const target = cv::imread("lena_blur.png");

    cv::Mat inHash; //hash of input image
    cv::Mat targetHash; //hash of target image

    //comupte hash of input and target
    algo->compute(input, inHash);
    algo->compute(target, targetHash);
    //Compare the similarity of inHash and targetHash
    //recommended thresholds are written in the header files
    //of every classes
    double const mismatch = algo->compare(inHash, targetHash);
    std::cout<<mismatch<<std::endl;
}

int main()
{
    //disable opencl acceleration may(or may not) boost up speed of img_hash
    cv::ocl::setUseOpenCL(false);

    computeHash(img_hash::AverageHash::create());
    computeHash(img_hash::PHash::create());
    computeHash(img_hash::MarrHildrethHash::create());
    computeHash(img_hash::RadialVarianceHash::create());
    //BlockMeanHash support mode 0 and mode 1, they associate to
    //mode 1 and mode 2 of PHash library
    computeHash(img_hash::BlockMeanHash::create(0));
    computeHash(img_hash::BlockMeanHash::create(1));
    computeHash(img_hash::ColorMomentHash::create());
}

You can measure the performance of the algorithms under different by this graph and pick the one suit by your needs.

image description

ps : At first I give BOVW a shot, the results are solid, but it take too many times to build the coed book and retrieve the features from image. Then I found image hash can help me boost up the speed(although it do not provide best accuracy).

I have the same problem as Cory recently, to solve this problem once and for all, I develop an img_hash module for open_contrib, here is the pull request. img_hash module port the image hash algorithms of PHash library and implement some algorithms do not exist in the PHash library, this include color moment hash which provide good resistance to rotation attack(-90 to 90 degree).

The ReadMe of img_hash module should give you enough information of how to use and install the module, if you need more info, please ask me from the forum, or send the question to my [email protected]

This module is very easy to use, unlike PHash library, the api are consistent and do not force you to handle the resource by yourself. yourself.

#include <opencv2/core.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/img_hash.hpp>
#include <opencv2/imgproc.hpp>

void computeHash(cv::Ptr<cv::img_hash::ImgHashBase> algo)
{
    cv::Mat const input = cv::imread("lena.png");
    cv::Mat const target = cv::imread("lena_blur.png");

    cv::Mat inHash; //hash of input image
    cv::Mat targetHash; //hash of target image

    //comupte hash of input and target
    algo->compute(input, inHash);
    algo->compute(target, targetHash);
    //Compare the similarity of inHash and targetHash
    //recommended thresholds are written in the header files
    //of every classes
    double const mismatch = algo->compare(inHash, targetHash);
    std::cout<<mismatch<<std::endl;
}

int main()
{
    //disable opencl acceleration may(or may not) boost up speed of img_hash
    cv::ocl::setUseOpenCL(false);

    computeHash(img_hash::AverageHash::create());
    computeHash(img_hash::PHash::create());
    computeHash(img_hash::MarrHildrethHash::create());
    computeHash(img_hash::RadialVarianceHash::create());
    //BlockMeanHash support mode 0 and mode 1, they associate to
    //mode 1 and mode 2 of PHash library
    computeHash(img_hash::BlockMeanHash::create(0));
    computeHash(img_hash::BlockMeanHash::create(1));
    computeHash(img_hash::ColorMomentHash::create());
}

You can measure the performance of the algorithms under different by this graph and pick the one suit by your needs.

image description

ps : At first I give BOVW a shot, the results are solid, but it take too many times to build the coed book and retrieve the features from image. Then I found image hash can help me boost up the speed(although it do not provide best accuracy).