OpenCV 4.13.0
開源電腦視覺 (Open Source Computer Vision)
載入中...
搜尋中...
無符合項
此模組提供了多種影像雜湊演算法的實作。

詳細描述

提供用於提取影像雜湊值的演算法,以及在龐大資料集中快速找出極度相似影像的方法。

所有函式的命名空間(Namespace)為 cv::img_hash

支援的演算法

您可以透過以下論文與網站進一步學習影像雜湊

程式碼範例

#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 << "必須輸入輸入影像與目標影像的路徑。範例 : 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;
}
n 維稠密陣列類別
定義於 mat.hpp:840
一個測量經過時間的類別。
定義 utility.hpp:326
void start()
開始計數刻度。
定義 utility.hpp:335
void stop()
停止計數刻度。
定義 utility.hpp:341
void reset()
重置內部數值。
定義 utility.hpp:430
double getTimeMilli() const
返回以毫秒為單位的經過時間。
定義 utility.hpp:365
std::shared_ptr< _Tp > Ptr
定義 cvstd_wrapper.hpp:23
Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
從檔案載入影像。
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3
定義 average_hash.hpp:11
定義 core.hpp:107
STL 命名空間。

不同攻擊下的效能

效能圖表

與 PHash 函式庫的速度比較(來自 ukbench 的 100 張影像)

如您所見,img_hash 模組的雜湊計算速度遠優於 PHash 函式庫

註:我沒有列出平均雜湊、PHash 和色彩矩雜湊的比較,因為我在 PHash 中找不到它們。

動機

將實用的影像雜湊演算法整合進 OpenCV,讓我們不需要一遍又一遍地重新編寫,或依賴其他第三方函式庫(例如:PHash 函式庫)。BOVW 或相關性匹配雖然不錯且穩健,但相較於影像雜湊,它們的速度非常緩慢。如果您需要處理大規模的 CBIR(基於內容的影像檢索)問題,影像雜湊是更合理的解決方案。

更多資訊

您可以透過下列連結深入了解 img_hash 模組,這些連結展示了如何從 ukbench 資料集中找出相似影像,並針對各種攻擊(對比度、模糊、雜訊(高斯、椒鹽)、JPEG 壓縮、浮水印、縮放)提供了詳盡的效能評測。

OpenCV 影像雜湊模組介紹 加速 OpenCV(img_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 轉換的影像雜湊。更多資訊...
 

列舉

列舉  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
 
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)
 計算輸入影像的徑向變異雜湊。
 

列舉類型文件

◆ 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

使用區塊區塊(步長/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

參數
inputArr欲計算雜湊值的輸入影像,類型應為 CV_8UC4、CV_8UC3 或 CV_8UC1。
outputArr輸入的雜湊值,它將包含 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 個十六進位數字,回傳類型為 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。
outputArr42 個類型為 CV_64F(double) 的雜湊值

◆ 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 個十六進位數字,回傳類型為 CV_8U
alphaMarr 小波的整數比例因子(預設=2)。
scale比例因子的層級(預設=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考慮的角度數量