From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 54D1448EA9 for ; Wed, 29 May 2024 12:07:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0189068D4F6; Wed, 29 May 2024 15:07:20 +0300 (EEST) Received: from flump.de (flump.de [185.163.118.210]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E4CCE68D3C5 for ; Wed, 29 May 2024 15:07:13 +0300 (EEST) Received: from falbala.sra.uni-hannover.de (unknown [130.75.33.21]) by flump.de (Postfix) with ESMTPSA id 3EB34F4D868; Wed, 29 May 2024 14:07:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flump.de; s=mail; t=1716984433; bh=ibyjaZFeD9xgxiblp9n8upTlQRYagOedIFfM5VvvXUY=; h=From:To:Cc:Subject:Date; b=THcn1tOJ/FhdvwhWBOAYP5d7ZiVmwSwukjbEh8rJTtzZZA9gl3sigcPs4zWZHaA3A KVXxkagw8EZ02t7JOso/DmiGJce+7roCX8wYfbROEUfW4d2Xwf57+eLvlm9UKOVQBr afF4dZUS73RJJJKKX1I3o8r5Q/WYI+fVFKkyfQKg= From: Gerion Entrup To: ffmpeg-devel@ffmpeg.org Date: Wed, 29 May 2024 14:06:07 +0200 Message-ID: <20240529120607.517822-1-gerion.entrup@flump.de> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavfilter/signature_lookup: fix jaccard distance X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Sachin Tilloo Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 Reviewed-by: Sachin Tilloo Tested-by: Sachin Tilloo --- libavfilter/signature_lookup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavfilter/signature_lookup.c b/libavfilter/signature_lookup.c index b39a3e225b..b90b63f3f2 100644 --- a/libavfilter/signature_lookup.c +++ b/libavfilter/signature_lookup.c @@ -127,9 +127,10 @@ static int get_jaccarddist(SignatureContext *sc, CoarseSignature *first, CoarseS { int jaccarddist, i, composdist = 0, cwthcount = 0; for (i = 0; i < 5; i++) { - if ((jaccarddist = intersection_word(first->data[i], second->data[i])) > 0) { + if ((jaccarddist = (1 << 16) * intersection_word(first->data[i], second->data[i])) > 0) { jaccarddist /= FFMAX(union_word(first->data[i], second->data[i]), 1); } + jaccarddist = (1 << 16) - jaccarddist; if (jaccarddist >= sc->thworddist) { if (++cwthcount > 2) { /* more than half (5/2) of distances are too wide */ -- 2.43.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".