mirror of
https://github.com/simon987/fastimagehash.git
synced 2025-04-10 14:16:49 +00:00
add whash wname option
This commit is contained in:
parent
356c8e4c64
commit
345e684adc
@ -35,7 +35,7 @@ static void BM_whash(benchmark::State &state) {
|
|||||||
void *buf = load_test_file(&size);
|
void *buf = load_test_file(&size);
|
||||||
|
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
whash_mem(buf, tmp, size, state.range(), 0);
|
whash_mem(buf, tmp, size, state.range(), 0, "haar");
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -200,19 +200,19 @@ int dhash_mem(void *buf, uchar *out, size_t buf_len, int hash_size) {
|
|||||||
return FASTIMAGEHASH_OK;
|
return FASTIMAGEHASH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int whash_file(const char *filepath, uchar *out, int hash_size, int img_scale) {
|
int whash_file(const char *filepath, uchar *out, int hash_size, int img_scale, const char* wname) {
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_file_in_mem(filepath, &size);
|
void *buf = load_file_in_mem(filepath, &size);
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
return FASTIMAGEHASH_READ_ERR;
|
return FASTIMAGEHASH_READ_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = whash_mem(buf, out, size, hash_size, img_scale);
|
int ret = whash_mem(buf, out, size, hash_size, img_scale, wname);
|
||||||
free(buf);
|
free(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int whash_mem(void *buf, uchar *out, size_t buf_len, const int hash_size, int img_scale) {
|
int whash_mem(void *buf, uchar *out, size_t buf_len, const int hash_size, int img_scale, const char *wname) {
|
||||||
Mat im;
|
Mat im;
|
||||||
try {
|
try {
|
||||||
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
||||||
@ -220,6 +220,10 @@ int whash_mem(void *buf, uchar *out, size_t buf_len, const int hash_size, int im
|
|||||||
return FASTIMAGEHASH_DECODE_ERR;
|
return FASTIMAGEHASH_DECODE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(wname, "haar") != 0 && strcmp(wname, "db4") != 0) {
|
||||||
|
throw std::invalid_argument("wname must be either of 'haar' or 'db4'");
|
||||||
|
}
|
||||||
|
|
||||||
if ((hash_size & (hash_size - 1)) != 0) {
|
if ((hash_size & (hash_size - 1)) != 0) {
|
||||||
throw std::invalid_argument("hash_size must be a power of two");
|
throw std::invalid_argument("hash_size must be a power of two");
|
||||||
}
|
}
|
||||||
@ -256,7 +260,7 @@ int whash_mem(void *buf, uchar *out, size_t buf_len, const int hash_size, int im
|
|||||||
data[i] = (double) pixel[i] / 255;
|
data[i] = (double) pixel[i] / 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
wave_object w = wave_init("haar");
|
wave_object w = wave_init(wname);
|
||||||
wt2_object wt = wt2_init(w, "dwt", img_scale, img_scale, dwt_level);
|
wt2_object wt = wt2_init(w, "dwt", img_scale, img_scale, dwt_level);
|
||||||
|
|
||||||
double *coeffs = dwt2(wt, data);
|
double *coeffs = dwt2(wt, data);
|
||||||
@ -362,7 +366,7 @@ void multi_hash_destroy(multi_hash_t *h) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int multi_hash_file(const char *filepath, multi_hash_t *out, int hash_size,
|
int multi_hash_file(const char *filepath, multi_hash_t *out, int hash_size,
|
||||||
int ph_highfreq_factor, int wh_img_scale) {
|
int ph_highfreq_factor, int wh_img_scale, const char* wname) {
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_file_in_mem(filepath, &size);
|
void *buf = load_file_in_mem(filepath, &size);
|
||||||
|
|
||||||
@ -370,13 +374,14 @@ int multi_hash_file(const char *filepath, multi_hash_t *out, int hash_size,
|
|||||||
return FASTIMAGEHASH_READ_ERR;
|
return FASTIMAGEHASH_READ_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = multi_hash_mem(buf, out, size, hash_size, ph_highfreq_factor, wh_img_scale);
|
int ret = multi_hash_mem(buf, out, size, hash_size, ph_highfreq_factor, wh_img_scale, wname);
|
||||||
free(buf);
|
free(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int multi_hash_mem(void *buf, multi_hash_t *out, size_t buf_len,
|
int multi_hash_mem(void *buf, multi_hash_t *out, size_t buf_len,
|
||||||
int hash_size, int ph_highfreq_factor, int wh_img_scale) {
|
int hash_size, int ph_highfreq_factor, int wh_img_scale,
|
||||||
|
const char*wname) {
|
||||||
Mat im;
|
Mat im;
|
||||||
try {
|
try {
|
||||||
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
||||||
@ -497,8 +502,7 @@ int multi_hash_mem(void *buf, multi_hash_t *out, size_t buf_len,
|
|||||||
pixels[i] = (double) pixel[i] / 255;
|
pixels[i] = (double) pixel[i] / 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: haar option
|
wave_object w = wave_init(wname);
|
||||||
wave_object w = wave_init("haar");
|
|
||||||
wt2_object wt = wt2_init(w, "dwt", wh_img_scale, wh_img_scale, dwt_level);
|
wt2_object wt = wt2_init(w, "dwt", wh_img_scale, wh_img_scale, dwt_level);
|
||||||
|
|
||||||
double *coeffs = dwt2(wt, pixels);
|
double *coeffs = dwt2(wt, pixels);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef FASTIMAGEHASH_FASTIMAGEHASH_H
|
#ifndef FASTIMAGEHASH_FASTIMAGEHASH_H
|
||||||
#define FASTIMAGEHASH_FASTIMAGEHASH_H
|
#define FASTIMAGEHASH_FASTIMAGEHASH_H
|
||||||
|
|
||||||
#define FASTIMAGEHASH_VERSION "1.0"
|
#define FASTIMAGEHASH_VERSION "2.0"
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -24,9 +24,9 @@ multi_hash_t *multi_hash_create(int hash_size);
|
|||||||
|
|
||||||
void multi_hash_destroy(multi_hash_t *h);
|
void multi_hash_destroy(multi_hash_t *h);
|
||||||
|
|
||||||
int multi_hash_file(const char *filepath, multi_hash_t *out, int hash_size, int ph_highfreq_factor, int wh_img_scale);
|
int multi_hash_file(const char *filepath, multi_hash_t *out, int hash_size, int ph_highfreq_factor, int wh_img_scale, const char*wname);
|
||||||
|
|
||||||
int multi_hash_mem(void *buf, multi_hash_t *out, size_t buf_len, int hash_size, int ph_highfreq_factor, int wh_img_scale);
|
int multi_hash_mem(void *buf, multi_hash_t *out, size_t buf_len, int hash_size, int ph_highfreq_factor, int wh_img_scale, const char* wname);
|
||||||
|
|
||||||
void hash_to_hex_string_reversed(const uchar *h, char *out, int hash_size);
|
void hash_to_hex_string_reversed(const uchar *h, char *out, int hash_size);
|
||||||
|
|
||||||
@ -44,9 +44,9 @@ int dhash_file(const char *filepath, uchar *out, int hash_size);
|
|||||||
|
|
||||||
int dhash_mem(void *buf, uchar *out, size_t buf_len, int hash_size);
|
int dhash_mem(void *buf, uchar *out, size_t buf_len, int hash_size);
|
||||||
|
|
||||||
int whash_file(const char *filepath, uchar *out, int hash_size, int img_scale);
|
int whash_file(const char *filepath, uchar *out, int hash_size, int img_scale, const char* wname);
|
||||||
|
|
||||||
int whash_mem(void *buf, uchar *out, size_t buf_len, int hash_size, int img_scale);
|
int whash_mem(void *buf, uchar *out, size_t buf_len, int hash_size, int img_scale, const char*wname);
|
||||||
|
|
||||||
int phash_file(const char *buf, uchar *out, int hash_size, int highfreq_factor);
|
int phash_file(const char *buf, uchar *out, int hash_size, int highfreq_factor);
|
||||||
|
|
||||||
|
2
imhash.c
2
imhash.c
@ -51,7 +51,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (do_whash) {
|
if (do_whash) {
|
||||||
if (whash_file(argv[i], hash, 8, 0) == 0) {
|
if (whash_file(argv[i], hash, 8, 0, "haar") == 0) {
|
||||||
hash_to_hex_string_reversed(hash, hashstr, 8);
|
hash_to_hex_string_reversed(hash, hashstr, 8);
|
||||||
printf("%s\tw:%s\n", argv[i], hashstr);
|
printf("%s\tw:%s\n", argv[i], hashstr);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user