vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
// 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.
|
||||
|
||||
#ifndef OPENCV_IMG_HASH_H
|
||||
#define OPENCV_IMG_HASH_H
|
||||
|
||||
#include "opencv2/img_hash/average_hash.hpp"
|
||||
#include "opencv2/img_hash/block_mean_hash.hpp"
|
||||
#include "opencv2/img_hash/color_moment_hash.hpp"
|
||||
#include "opencv2/img_hash/marr_hildreth_hash.hpp"
|
||||
#include "opencv2/img_hash/phash.hpp"
|
||||
#include "opencv2/img_hash/radial_variance_hash.hpp"
|
||||
|
||||
/**
|
||||
@defgroup img_hash The module brings implementations of different image hashing algorithms.
|
||||
|
||||
Provide algorithms to extract the hash of images and fast way to figure out most similar images in
|
||||
huge data set.
|
||||
|
||||
Namespace for all functions is cv::img_hash.
|
||||
|
||||
### Supported Algorithms
|
||||
|
||||
- Average hash (also called Different hash)
|
||||
- PHash (also called Perceptual hash)
|
||||
- Marr Hildreth Hash
|
||||
- Radial Variance Hash
|
||||
- Block Mean Hash (modes 0 and 1)
|
||||
- Color Moment Hash (this is the one and only hash algorithm resist to rotation attack(-90~90 degree))
|
||||
|
||||
You can study more about image hashing from following paper and websites:
|
||||
|
||||
- "Implementation and benchmarking of perceptual image hash functions" @cite zauner2010implementation
|
||||
- "Looks Like It" @cite lookslikeit
|
||||
|
||||
### Code Example
|
||||
|
||||
@include samples/hash_samples.cpp
|
||||
|
||||
### Performance under different attacks
|
||||
|
||||

|
||||
|
||||
### Speed comparison with PHash library (100 images from ukbench)
|
||||
|
||||

|
||||

|
||||
|
||||
As you can see, hash computation speed of img_hash module outperform [PHash library](http://www.phash.org/) a lot.
|
||||
|
||||
PS : I do not list out the comparison of Average hash, PHash and Color Moment hash, because I cannot
|
||||
find them in PHash.
|
||||
|
||||
### Motivation
|
||||
|
||||
Collects useful image hash algorithms into opencv, so we do not need to rewrite them by ourselves
|
||||
again and again or rely on another 3rd party library(ex : PHash library). BOVW or correlation
|
||||
matching are good and robust, but they are very slow compare with image hash, if you need to deal
|
||||
with large scale CBIR(content based image retrieval) problem, image hash is a more reasonable
|
||||
solution.
|
||||
|
||||
### More info
|
||||
|
||||
You can learn more about img_hash modules from following links, these links show you how to find
|
||||
similar image from ukbench dataset, provide thorough benchmark of different attacks(contrast, blur,
|
||||
noise(gaussion,pepper and salt), jpeg compression, watermark, resize).
|
||||
|
||||
* [Introduction to image hash module of opencv](http://qtandopencv.blogspot.my/2016/06/introduction-to-image-hash-module-of.html)
|
||||
* [Speed up image hashing of opencv(img_hash) and introduce color moment hash](http://qtandopencv.blogspot.my/2016/06/speed-up-image-hashing-of-opencvimghash.html)
|
||||
|
||||
### Contributors
|
||||
|
||||
Tham Ngap Wei, thamngapwei@gmail.com
|
||||
|
||||
*/
|
||||
|
||||
#endif // OPENCV_IMG_HASH_H
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
|
||||
#ifndef OPENCV_AVERAGE_HASH_HPP
|
||||
#define OPENCV_AVERAGE_HASH_HPP
|
||||
|
||||
#include "img_hash_base.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace img_hash {
|
||||
|
||||
//! @addtogroup img_hash
|
||||
//! @{
|
||||
|
||||
/** @brief Computes average hash value of the input image
|
||||
|
||||
This is a fast image hashing algorithm, but only work on simple case. For more details, please
|
||||
refer to @cite lookslikeit
|
||||
*/
|
||||
class CV_EXPORTS_W AverageHash : public ImgHashBase
|
||||
{
|
||||
public:
|
||||
CV_WRAP static Ptr<AverageHash> create();
|
||||
protected:
|
||||
AverageHash() {}
|
||||
};
|
||||
|
||||
/** @brief Calculates img_hash::AverageHash in one call
|
||||
@param inputArr input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1.
|
||||
@param outputArr Hash value of input, it will contain 16 hex decimal number, return type is CV_8U
|
||||
*/
|
||||
CV_EXPORTS_W void averageHash(cv::InputArray inputArr, cv::OutputArray outputArr);
|
||||
|
||||
//! @}
|
||||
|
||||
}} // cv::img_hash::
|
||||
|
||||
#endif // OPENCV_AVERAGE_HASH_HPP
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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.
|
||||
|
||||
#ifndef OPENCV_BLOCK_MEAN_HASH_HPP
|
||||
#define OPENCV_BLOCK_MEAN_HASH_HPP
|
||||
|
||||
#include "img_hash_base.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace img_hash {
|
||||
|
||||
//! @addtogroup img_hash
|
||||
//! @{
|
||||
|
||||
enum BlockMeanHashMode
|
||||
{
|
||||
BLOCK_MEAN_HASH_MODE_0 = 0, //!< use fewer block and generate 16*16/8 uchar hash value
|
||||
BLOCK_MEAN_HASH_MODE_1 = 1, //!< use block blocks(step sizes/2), generate 31*31/8 + 1 uchar hash value
|
||||
};
|
||||
|
||||
/** @brief Image hash based on block mean.
|
||||
|
||||
See @cite zauner2010implementation for details.
|
||||
*/
|
||||
class CV_EXPORTS_W BlockMeanHash : public ImgHashBase
|
||||
{
|
||||
public:
|
||||
/** @brief Create BlockMeanHash object
|
||||
@param mode the mode
|
||||
*/
|
||||
CV_WRAP void setMode(int mode);
|
||||
CV_WRAP std::vector<double> getMean() const;
|
||||
CV_WRAP static Ptr<BlockMeanHash> create(int mode = BLOCK_MEAN_HASH_MODE_0);
|
||||
protected:
|
||||
BlockMeanHash() {}
|
||||
};
|
||||
|
||||
/** @brief Computes block mean hash of the input image
|
||||
@param inputArr input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1.
|
||||
@param outputArr Hash value of input, it will contain 16 hex decimal number, return type is CV_8U
|
||||
@param mode the mode
|
||||
*/
|
||||
CV_EXPORTS_W void blockMeanHash(cv::InputArray inputArr,
|
||||
cv::OutputArray outputArr,
|
||||
int mode = BLOCK_MEAN_HASH_MODE_0);
|
||||
|
||||
//! @}
|
||||
|
||||
}} // cv::img_hash::
|
||||
|
||||
#endif // OPENCV_BLOCK_MEAN_HASH_HPP
|
||||
@@ -0,0 +1,41 @@
|
||||
// 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.
|
||||
|
||||
#ifndef OPENCV_COLOR_MOMENT_HASH_HPP
|
||||
#define OPENCV_COLOR_MOMENT_HASH_HPP
|
||||
|
||||
#include "img_hash_base.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace img_hash {
|
||||
|
||||
//! @addtogroup img_hash
|
||||
//! @{
|
||||
|
||||
/** @brief Image hash based on color moments.
|
||||
|
||||
See @cite tang2012perceptual for details.
|
||||
*/
|
||||
class CV_EXPORTS_W ColorMomentHash : public ImgHashBase
|
||||
{
|
||||
public:
|
||||
CV_WRAP static Ptr<ColorMomentHash> create();
|
||||
protected:
|
||||
ColorMomentHash() {}
|
||||
};
|
||||
|
||||
/** @brief Computes color moment hash of the input, the algorithm
|
||||
is come from the paper "Perceptual Hashing for Color Images
|
||||
Using Invariant Moments"
|
||||
@param inputArr input image want to compute hash value,
|
||||
type should be CV_8UC4, CV_8UC3 or CV_8UC1.
|
||||
@param outputArr 42 hash values with type CV_64F(double)
|
||||
*/
|
||||
CV_EXPORTS_W void colorMomentHash(cv::InputArray inputArr, cv::OutputArray outputArr);
|
||||
|
||||
//! @}
|
||||
|
||||
}} // cv::img_hash::
|
||||
|
||||
#endif // OPENCV_COLOR_MOMENT_HASH_HPP
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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.
|
||||
|
||||
#ifndef OPENCV_IMG_HASH_BASE_HPP
|
||||
#define OPENCV_IMG_HASH_BASE_HPP
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace img_hash {
|
||||
|
||||
//! @addtogroup img_hash
|
||||
//! @{
|
||||
|
||||
/** @brief The base class for image hash algorithms
|
||||
*/
|
||||
class CV_EXPORTS_W ImgHashBase : public Algorithm
|
||||
{
|
||||
public:
|
||||
class ImgHashImpl;
|
||||
|
||||
~ImgHashBase();
|
||||
/** @brief Computes hash of the input image
|
||||
@param inputArr input image want to compute hash value
|
||||
@param outputArr hash of the image
|
||||
*/
|
||||
CV_WRAP void compute(cv::InputArray inputArr, cv::OutputArray outputArr);
|
||||
/** @brief Compare the hash value between inOne and inTwo
|
||||
@param hashOne Hash value one
|
||||
@param hashTwo Hash value two
|
||||
@return value indicate similarity between inOne and inTwo, the meaning
|
||||
of the value vary from algorithms to algorithms
|
||||
*/
|
||||
CV_WRAP double compare(cv::InputArray hashOne, cv::InputArray hashTwo) const;
|
||||
protected:
|
||||
ImgHashBase();
|
||||
protected:
|
||||
Ptr<ImgHashImpl> pImpl;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
} } // cv::img_hash::
|
||||
|
||||
#endif // OPENCV_IMG_HASH_BASE_HPP
|
||||
@@ -0,0 +1,64 @@
|
||||
// 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.
|
||||
|
||||
#ifndef OPENCV_MARR_HILDRETH_HASH_HPP
|
||||
#define OPENCV_MARR_HILDRETH_HASH_HPP
|
||||
|
||||
#include "img_hash_base.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace img_hash {
|
||||
|
||||
//! @addtogroup img_hash
|
||||
//! @{
|
||||
|
||||
/** @brief Marr-Hildreth Operator Based Hash, slowest but more discriminative.
|
||||
|
||||
See @cite zauner2010implementation for details.
|
||||
*/
|
||||
class CV_EXPORTS_W MarrHildrethHash : public ImgHashBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief self explain
|
||||
*/
|
||||
CV_WRAP float getAlpha() const;
|
||||
|
||||
/**
|
||||
* @brief self explain
|
||||
*/
|
||||
CV_WRAP float getScale() const;
|
||||
|
||||
/** @brief Set Mh kernel parameters
|
||||
@param alpha int scale factor for marr wavelet (default=2).
|
||||
@param scale int level of scale factor (default = 1)
|
||||
*/
|
||||
CV_WRAP void setKernelParam(float alpha, float scale);
|
||||
|
||||
/**
|
||||
@param alpha int scale factor for marr wavelet (default=2).
|
||||
@param scale int level of scale factor (default = 1)
|
||||
*/
|
||||
CV_WRAP static Ptr<MarrHildrethHash> create(float alpha = 2.0f, float scale = 1.0f);
|
||||
protected:
|
||||
MarrHildrethHash() {}
|
||||
};
|
||||
|
||||
/** @brief Computes average hash value of the input image
|
||||
@param inputArr input image want to compute hash value,
|
||||
type should be CV_8UC4, CV_8UC3, CV_8UC1.
|
||||
@param outputArr Hash value of input, it will contain 16 hex
|
||||
decimal number, return type is CV_8U
|
||||
@param alpha int scale factor for marr wavelet (default=2).
|
||||
@param scale int level of scale factor (default = 1)
|
||||
*/
|
||||
CV_EXPORTS_W void marrHildrethHash(cv::InputArray inputArr,
|
||||
cv::OutputArray outputArr,
|
||||
float alpha = 2.0f, float scale = 1.0f);
|
||||
|
||||
//! @}
|
||||
|
||||
}} // cv::img_hash::
|
||||
|
||||
#endif // OPENCV_MARR_HILDRETH_HASH_HPP
|
||||
@@ -0,0 +1,41 @@
|
||||
// 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.
|
||||
|
||||
#ifndef OPENCV_PHASH_HPP
|
||||
#define OPENCV_PHASH_HPP
|
||||
|
||||
#include "img_hash_base.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace img_hash {
|
||||
|
||||
//! @addtogroup img_hash
|
||||
//! @{
|
||||
|
||||
/** @brief pHash
|
||||
|
||||
Slower than average_hash, but tolerant of minor modifications
|
||||
|
||||
This algorithm can combat more variation than averageHash, for more details please refer to @cite lookslikeit
|
||||
*/
|
||||
class CV_EXPORTS_W PHash : public ImgHashBase
|
||||
{
|
||||
public:
|
||||
CV_WRAP static Ptr<PHash> create();
|
||||
protected:
|
||||
PHash() {}
|
||||
};
|
||||
|
||||
/** @brief Computes pHash value of the input image
|
||||
@param inputArr input image want to compute hash value,
|
||||
type should be CV_8UC4, CV_8UC3, CV_8UC1.
|
||||
@param outputArr Hash value of input, it will contain 8 uchar value
|
||||
*/
|
||||
CV_EXPORTS_W void pHash(cv::InputArray inputArr, cv::OutputArray outputArr);
|
||||
|
||||
//! @}
|
||||
|
||||
} } // cv::img_hash::
|
||||
|
||||
#endif // OPENCV_PHASH_HPP
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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.
|
||||
|
||||
#ifndef OPENCV_RADIAL_VARIANCE_HASH_HPP
|
||||
#define OPENCV_RADIAL_VARIANCE_HASH_HPP
|
||||
|
||||
#include "img_hash_base.hpp"
|
||||
|
||||
namespace cv {
|
||||
namespace img_hash {
|
||||
|
||||
//! @addtogroup img_hash
|
||||
//! @{
|
||||
|
||||
|
||||
/** @brief Image hash based on Radon transform.
|
||||
|
||||
See @cite tang2012perceptual for details.
|
||||
*/
|
||||
class CV_EXPORTS_W RadialVarianceHash : public ImgHashBase
|
||||
{
|
||||
public:
|
||||
CV_WRAP static Ptr<RadialVarianceHash> create(double sigma = 1, int numOfAngleLine = 180);
|
||||
|
||||
CV_WRAP int getNumOfAngleLine() const;
|
||||
CV_WRAP double getSigma() const;
|
||||
|
||||
CV_WRAP void setNumOfAngleLine(int value);
|
||||
CV_WRAP void setSigma(double value);
|
||||
|
||||
// internals
|
||||
std::vector<double> getFeatures();
|
||||
cv::Mat getHash();
|
||||
Mat getPixPerLine(Mat const &input);
|
||||
Mat getProjection();
|
||||
protected:
|
||||
RadialVarianceHash() {}
|
||||
};
|
||||
|
||||
/** @brief Computes radial variance hash of the input image
|
||||
@param inputArr input image want to compute hash value,
|
||||
type should be CV_8UC4, CV_8UC3, CV_8UC1.
|
||||
@param outputArr Hash value of input
|
||||
@param sigma Gaussian kernel standard deviation
|
||||
@param numOfAngleLine The number of angles to consider
|
||||
*/
|
||||
CV_EXPORTS_W void radialVarianceHash(cv::InputArray inputArr,
|
||||
cv::OutputArray outputArr,
|
||||
double sigma = 1,
|
||||
int numOfAngleLine = 180);
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
}} // cv::img_hash::
|
||||
|
||||
#endif // OPENCV_RADIAL_VARIANCE_HASH_HPP
|
||||
Reference in New Issue
Block a user