Skip to content

Commit 300df41

Browse files
gerion0michaelni
authored andcommitted
libavfilter/signature_lookup: fix jaccard distance
Actually, the jaccard distance is defined as D = 1 - intersect / union. Additionally, the distance value is compared against a constant that must be between 0 and 1, which is not the case here. Both facts together has led to the fact, that the function always returned a matching course signature. To leave the constant intact and to avoid floating point computation, this commit multiplies with 1 << 16 making the constant effectively 9000 / (1<<16) =~ 0.14. Reported-by: Sachin Tilloo <[email protected]> Reviewed-by: Sachin Tilloo <[email protected]> Tested-by: Sachin Tilloo <[email protected]> Signed-off-by: Michael Niedermayer <[email protected]>
1 parent 3152c68 commit 300df41

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

libavfilter/signature_lookup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ static int get_jaccarddist(SignatureContext *sc, CoarseSignature *first, CoarseS
127127
{
128128
int jaccarddist, i, composdist = 0, cwthcount = 0;
129129
for (i = 0; i < 5; i++) {
130-
if ((jaccarddist = intersection_word(first->data[i], second->data[i])) > 0) {
130+
if ((jaccarddist = (1 << 16) * intersection_word(first->data[i], second->data[i])) > 0) {
131131
jaccarddist /= union_word(first->data[i], second->data[i]);
132132
}
133+
jaccarddist = (1 << 16) - jaccarddist;
133134
if (jaccarddist >= sc->thworddist) {
134135
if (++cwthcount > 2) {
135136
/* more than half (5/2) of distances are too wide */

0 commit comments

Comments
 (0)