OpenCV 5.0.0
Open Source Computer Vision
読み込み中...
検索中...
見つかりません
🤖 AIによる機械翻訳(非公式) — これは OpenCV 5.0.0 公式リファレンス(英語)を AI (Claude) で自動翻訳したものです。訳に誤りを含む場合があります。正確な情報は 公式英語版(原文) を参照してください。
このモジュールは、さまざまな画像ハッシュアルゴリズムの実装を提供する。

詳細説明

画像のハッシュを抽出するアルゴリズムと、巨大なデータセットの中から最も類似した画像を高速に見つける方法を提供する。

すべての関数の名前空間は cv::img_hash である。

サポートされているアルゴリズム

画像ハッシュについては、以下の論文やWebサイトでさらに学ぶことができる:

コード例

#include "opencv2/core.hpp"
#include <iostream>
using namespace cv;
using namespace cv::img_hash;
using namespace std;
template <typename T>
inline void test_one(const std::string &title, const Mat &a, const Mat &b)
{
cout << "=== " << title << " ===" << endl;
TickMeter tick;
Mat hashA, hashB;
func = T::create();
tick.reset(); tick.start();
func->compute(a, hashA);
tick.stop();
cout << "compute1: " << tick.getTimeMilli() << " ms" << endl;
tick.reset(); tick.start();
func->compute(b, hashB);
tick.stop();
cout << "compute2: " << tick.getTimeMilli() << " ms" << endl;
cout << "compare: " << func->compare(hashA, hashB) << endl << endl;;
}
int main(int argc, char **argv)
{
if (argc != 3)
{
cerr << "must input the path of input image and target image. ex : hash_samples lena.jpg lena2.jpg" << endl;
return -1;
}
ocl::setUseOpenCL(false);
Mat input = imread(argv[1]);
Mat target = imread(argv[2]);
test_one<AverageHash>("AverageHash", input, target);
test_one<PHash>("PHash", input, target);
test_one<MarrHildrethHash>("MarrHildrethHash", input, target);
test_one<RadialVarianceHash>("RadialVarianceHash", input, target);
test_one<BlockMeanHash>("BlockMeanHash", input, target);
return 0;
}
Comma-separated Matrix Initializer.
Definition mat.hpp:964
a Class to measure passing time.
Definition utility.hpp:351
void start()
starts counting ticks.
Definition utility.hpp:360
void stop()
stops counting ticks.
Definition utility.hpp:366
void reset()
resets internal values.
Definition utility.hpp:455
double getTimeMilli() const
returns passed time in milliseconds.
Definition utility.hpp:390
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
Loads an image from a file.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
Definition average_hash.hpp:11
Definition core.hpp:107
STL namespace.

各種攻撃に対する性能

Performance chart

PHashライブラリとの速度比較(ukbenchの100枚の画像)

ご覧のとおり、img_hash モジュールのハッシュ計算速度は PHashライブラリ を大きく上回る。

補足: Average hash、PHash、Color Moment hash の比較は一覧に載せていない。これらを PHash の中で見つけられなかったためである。

動機

有用な画像ハッシュアルゴリズムをOpenCVに集約することで、それらを何度も自分で書き直したり、別のサードパーティライブラリ(例: PHashライブラリ)に依存したりする必要がなくなる。BOVWや相関マッチングは優れていてロバストであるが、画像ハッシュと比べて非常に遅い。大規模なCBIR(content based image retrieval、内容ベース画像検索)問題を扱う必要がある場合、画像ハッシュはより合理的な解決策である。

詳細情報

img_hash モジュールについては、以下のリンクからさらに学ぶことができる。これらのリンクでは、ukbenchデータセットから類似画像を見つける方法を示し、各種攻撃(コントラスト、平滑化、ノイズ(ガウシアン、ごま塩)、jpeg圧縮、透かし、リサイズ)に対する徹底的なベンチマークを提供している。

Introduction to image hash module of opencv Speed up image hashing of opencv(img_hash) and introduce color moment hash

貢献者

Tham Ngap Wei, thamn.nosp@m.gapw.nosp@m.ei@gm.nosp@m.ail..nosp@m.com

クラス

class  cv::img_hash::AverageHash
 入力画像の平均ハッシュ値を計算する。詳細...
 
class  cv::img_hash::BlockMeanHash
 ブロック平均に基づく画像ハッシュ。詳細...
 
class  cv::img_hash::ColorMomentHash
 色モーメントに基づく画像ハッシュ。 続き...
 
class  cv::img_hash::ImgHashBase
 画像ハッシュアルゴリズムの基底クラス。詳細...
 
class  cv::img_hash::MarrHildrethHash
 Marr-Hildreth 演算子ベースのハッシュ。最も低速だが、より識別力が高い。 続き...
 
class  cv::img_hash::PHash
 pHash 詳細...
 
class  cv::img_hash::RadialVarianceHash
 Radon 変換に基づく画像ハッシュ。 続きを読む...
 

列挙型

enum  cv::img_hash::BlockMeanHashMode {
  cv::img_hash::BLOCK_MEAN_HASH_MODE_0 = 0 ,
  cv::img_hash::BLOCK_MEAN_HASH_MODE_1 = 1
}
 

関数

void cv::img_hash::averageHash (cv::InputArray inputArr, cv::OutputArray outputArr)
 img_hash::AverageHash を1回の呼び出しで計算する。
 
void cv::img_hash::blockMeanHash (cv::InputArray inputArr, cv::OutputArray outputArr, int mode=BLOCK_MEAN_HASH_MODE_0)
 入力画像のブロック平均ハッシュを計算する。
 
void cv::img_hash::colorMomentHash (cv::InputArray inputArr, cv::OutputArray outputArr)
 入力の色モーメントハッシュを計算する。アルゴリズムは論文"Perceptual Hashing for Color Images Using Invariant Moments"に基づく。
 
void cv::img_hash::marrHildrethHash (cv::InputArray inputArr, cv::OutputArray outputArr, float alpha=2.0f, float scale=1.0f)
 入力画像の平均ハッシュ値を計算する。
 
void cv::img_hash::pHash (cv::InputArray inputArr, cv::OutputArray outputArr)
 入力画像のpHash値を計算する。
 
void cv::img_hash::radialVarianceHash (cv::InputArray inputArr, cv::OutputArray outputArr, double sigma=1, int numOfAngleLine=180)
 入力画像の動径分散ハッシュ(radial variance hash)を計算する。
 

列挙型詳解

◆ BlockMeanHashMode

#include <opencv2/img_hash/block_mean_hash.hpp>

列挙値
BLOCK_MEAN_HASH_MODE_0 
Python: cv.img_hash.BLOCK_MEAN_HASH_MODE_0

より少ないブロックを使用し、16*16/8 個の uchar ハッシュ値を生成する

BLOCK_MEAN_HASH_MODE_1 
Python: cv.img_hash.BLOCK_MEAN_HASH_MODE_1

blocks(ステップサイズ/2) でブロックを使用し、31*31/8 + 1 個の uchar ハッシュ値を生成する

関数詳解

◆ averageHash()

void cv::img_hash::averageHash ( cv::InputArray inputArr,
cv::OutputArray outputArr )
Python:
cv.img_hash.averageHash(inputArr[, outputArr]) -> outputArr

#include <opencv2/img_hash/average_hash.hpp>

img_hash::AverageHash を1回の呼び出しで計算する。

引数
inputArrハッシュ値を計算したい入力画像。型は CV_8UC4、CV_8UC3、CV_8UC1 のいずれかである必要がある。
outputArr入力のハッシュ値。16個の16進数を含み、戻り値の型は CV_8U

◆ blockMeanHash()

void cv::img_hash::blockMeanHash ( cv::InputArray inputArr,
cv::OutputArray outputArr,
int mode = BLOCK_MEAN_HASH_MODE_0 )
Python:
cv.img_hash.blockMeanHash(inputArr[, outputArr[, mode]]) -> outputArr

#include <opencv2/img_hash/block_mean_hash.hpp>

入力画像のブロック平均ハッシュを計算する。

引数
inputArrハッシュ値を計算したい入力画像。型は CV_8UC4、CV_8UC3、CV_8UC1 のいずれかである必要がある。
outputArr入力のハッシュ値。16個の16進数を含み、戻り値の型は CV_8U
modeモード

◆ colorMomentHash()

void cv::img_hash::colorMomentHash ( cv::InputArray inputArr,
cv::OutputArray outputArr )
Python:
cv.img_hash.colorMomentHash(inputArr[, outputArr]) -> outputArr

#include <opencv2/img_hash/color_moment_hash.hpp>

入力のカラーモーメントハッシュを計算する。アルゴリズムは論文 "Perceptual Hashing for Color Images Using Invariant Moments" に由来する。

引数
inputArrハッシュ値を計算したい入力画像。型は CV_8UC4、CV_8UC3、CV_8UC1 のいずれかである必要がある。
outputArrCV_64F(double) の42個のハッシュ値

◆ marrHildrethHash()

void cv::img_hash::marrHildrethHash ( cv::InputArray inputArr,
cv::OutputArray outputArr,
float alpha = 2.0f,
float scale = 1.0f )
Python:
cv.img_hash.marrHildrethHash(inputArr[, outputArr[, alpha[, scale]]]) -> outputArr

#include <opencv2/img_hash/marr_hildreth_hash.hpp>

入力画像の平均ハッシュ値を計算する。

引数
inputArrハッシュ値を計算したい入力画像。型は CV_8UC4、CV_8UC3、CV_8UC1 のいずれかである必要がある。
outputArr入力のハッシュ値。16個の16進数を含み、戻り値の型は CV_8U
alphamarrウェーブレットのスケール係数 (int、デフォルト=2)。
scaleスケール係数のレベル (int、デフォルト = 1)

◆ pHash()

void cv::img_hash::pHash ( cv::InputArray inputArr,
cv::OutputArray outputArr )
Python:
cv.img_hash.pHash(inputArr[, outputArr]) -> outputArr

#include <opencv2/img_hash/phash.hpp>

入力画像のpHash値を計算する。

引数
inputArrハッシュ値を計算したい入力画像。型は CV_8UC4、CV_8UC3、CV_8UC1 のいずれかである必要がある。
outputArr入力のハッシュ値。8個の uchar 値を含む

◆ radialVarianceHash()

void cv::img_hash::radialVarianceHash ( cv::InputArray inputArr,
cv::OutputArray outputArr,
double sigma = 1,
int numOfAngleLine = 180 )
Python:
cv.img_hash.radialVarianceHash(inputArr[, outputArr[, sigma[, numOfAngleLine]]]) -> outputArr

#include <opencv2/img_hash/radial_variance_hash.hpp>

入力画像の動径分散ハッシュを計算する。

引数
inputArrハッシュ値を計算したい入力画像。型は CV_8UC4、CV_8UC3、CV_8UC1 のいずれかである必要がある。
outputArr入力のハッシュ値
sigmaガウシアンカーネルの標準偏差
numOfAngleLine考慮する角度の数