1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
<?xml version="1.0"?>
<extension name="pHash" version="1.1.2">
<summary>pHash</summary>
<logo src='pHash.png' mimetype='image/png'/>
<license>GPL3</license>
<maintainers>
<maintainer>
<name>Evan Klinger</name>
<email>eklinger@phash.org</email>
<role>lead</role>
</maintainer>
</maintainers>
<release>
<version>0.9.1</version>
<date>2010-06-12</date>
<state>beta</state>
</release>
<deps language="cpp" platform="all">
<with defaults='/usr:/usr/local' testfile='include/pHash.h'>
<header name="pHash.h"/>
<header name="audiophash.h"/>
<lib name="pHash" platform="all" function="ph_texthash"/>
</with>
</deps>
<code role="code" position="top">
struct ph_audio_hash
{
uint32_t *hash;
int len;
};
struct ph_video_hash
{
ulong64 *hash;
int len;
};
struct ph_text_hash
{
TxtHashPoint *p;
int count;
};
</code>
<resource name="ph_video_hash" payload="ph_video_hash" alloc="no">
<description>
A ulong64 resource
</description>
<destruct>
if(resource)
{
free(resource->hash);
free(resource);
}
</destruct>
</resource>
<resource name="ph_image_hash" payload="ulong64" alloc="no">
<description>
A ulong64 resource
</description>
<destruct>
if(resource)
free(resource);
</destruct>
</resource>
<resource name="ph_audio_hash" payload="ph_audio_hash" alloc="no">
<description>
A uint32_t resource
</description>
<destruct>
if(resource)
{
free(resource->hash);
free(resource);
}
</destruct>
</resource>
<resource name="ph_txt_hash" payload="ph_text_hash" alloc="no">
<description>
A TxtHashPoint resource
</description>
<destruct>
if(resource)
{
free(resource->p);
free(resource);
}
</destruct>
</resource>
<function name="ph_dct_videohash" if="HAVE_VIDEO_HASH">
<proto>resource ph_video_hash ph_dct_videohash(string file)</proto>
<summary>pHash DCT video hash</summary>
<description>
Perceptual video hash based on DCT.
</description>
<code>
<![CDATA[
int len;
ulong64 *video_hash = ph_dct_videohash(file, len);
if(video_hash)
{
ph_video_hash *p = (ph_video_hash *)malloc(sizeof(ph_video_hash));
p->hash = video_hash;
p->len = len;
return_res = p;
}
else
RETURN_FALSE;
]]>
</code>
</function>
<function name="ph_dct_imagehash" if="HAVE_IMAGE_HASH">
<proto>resource ph_image_hash ph_dct_imagehash(string file)</proto>
<summary>pHash DCT image hash</summary>
<description>
Perceptual image hash based on DCT.
</description>
<code>
<![CDATA[
ulong64 *hash = (ulong64 *)malloc(sizeof(ulong64));
int ret = ph_dct_imagehash(file, *hash);
if(ret != 0)
{
free(hash);
RETURN_FALSE;
}
else
return_res = hash;
]]>
</code>
</function>
<function name="ph_texthash">
<proto>resource ph_txt_hash ph_texthash(string file)</proto>
<summary>pHash cyclic text hash</summary>
<description>
Perceptual text hash based on cyclic polynomials.
</description>
<code>
<![CDATA[
int num;
TxtHashPoint *txtHash = ph_texthash(file, &num);
if(txtHash)
{
ph_text_hash *h = (ph_text_hash *)malloc(sizeof(ph_text_hash));
h->p = txtHash;
h->count = num;
return_res = h;
}
else
RETURN_FALSE;
]]>
</code>
</function>
<function name="ph_audiohash" if="HAVE_AUDIO_HASH">
<proto>resource ph_audio_hash ph_audiohash(string file, int sample_rate=5512, int channels=1)</proto>
<summary>pHash audio hash</summary>
<description>
Perceptual audio hash based on bark scale.
</description>
<code>
<![CDATA[
int n;
float *audiobuf = ph_readaudio(file, sample_rate, channels, NULL, n);
if(audiobuf)
{
int nb_frames;
uint32_t *hash = ph_audiohash(audiobuf, n, sample_rate, nb_frames);
free(audiobuf);
if(hash)
{
ph_audio_hash *h = (ph_audio_hash *)malloc(sizeof(ph_audio_hash));
h->hash = hash;
h->len = nb_frames;
return_res = h;
}
else
RETURN_FALSE;
}
else
RETURN_FALSE;
]]>
</code>
</function>
<function name="ph_image_dist" if="HAVE_IMAGE_HASH">
<proto>float ph_image_dist(resource ph_image_hash h1,resource ph_image_hash h2)</proto>
<summary>pHash image distance.</summary>
<description>
Calculate distance between two images.
</description>
<code>
<![CDATA[
if(h1 && h2)
{
int dist = ph_hamming_distance(*h1, *h2);
RETURN_DOUBLE(dist);
}
else
RETURN_DOUBLE(-1);
]]>
</code>
</function>
<function name="ph_video_dist" if="HAVE_VIDEO_HASH">
<proto>float ph_video_dist(resource ph_video_hash h1,resource ph_video_hash h2, int thresh=21)</proto>
<summary>pHash video distance.</summary>
<description>
Calculate distance between two videos.
</description>
<code>
<![CDATA[
if(h1 && h2)
{
double sim = ph_dct_videohash_dist(h1->hash, h1->len, h2->hash, h2->len, thresh);
RETURN_DOUBLE(sim);
}
else
RETURN_DOUBLE(-1);
]]>
</code>
</function>
<function name="ph_audio_dist" if="HAVE_AUDIO_HASH">
<proto>float ph_audio_dist(resource ph_audio_hash h1,resource ph_audio_hash h2,
int block_size=256, float thresh=0.30)</proto>
<summary>pHash audio distance.</summary>
<description>
Calculate distance between two audio files.
</description>
<code>
<![CDATA[
if(h1 && h2)
{
int Nc;
double *cs = ph_audio_distance_ber(h1->hash, h1->len, h2->hash, h2->len,
thresh, block_size, Nc);
if(cs)
{
double max_cs = 0.0;
for (int i = 0; i < Nc; ++i)
{
if (cs[i] > max_cs)
{
max_cs = cs[i];
}
}
free(cs);
RETURN_DOUBLE(max_cs);
}
else
RETURN_DOUBLE(-1);
}
else
RETURN_DOUBLE(-1);
]]>
</code>
</function>
<function name="ph_compare_text_hashes">
<proto>array ph_compare_text_hashes(resource ph_txt_hash h1,resource ph_txt_hash h2)</proto>
<summary>pHash text distance.</summary>
<description>
Calculate distance between two text hashes.
</description>
<code>
<![CDATA[
if(h1 && h2)
{
int count = 0;
TxtMatch *m = ph_compare_text_hashes(h1->p, h1->count, h2->p, h2->count, &count);
if(m)
{
for(int i = 0; i < count; ++i)
{
zval *array;
MAKE_STD_ZVAL(array);
array_init(array);
add_assoc_long(array, "begin", m[i].first_index);
add_assoc_long(array, "end", m[i].second_index);
add_assoc_long(array, "length", m[i].length);
add_next_index_zval(return_value, array);
}
free(m);
}
else
RETURN_FALSE;
}
else
RETURN_FALSE;
]]>
</code>
</function>
</extension>
|