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 A93FA47318 for ; Sun, 2 Jun 2024 12:03:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 975EE68D605; Sun, 2 Jun 2024 15:03:44 +0300 (EEST) Received: from flump.de (flump.de [185.163.118.210]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F05268D466 for ; Sun, 2 Jun 2024 15:03:38 +0300 (EEST) Received: from falbala.fritz.box (ip4d1692dd.dynamic.kabel-deutschland.de [77.22.146.221]) by flump.de (Postfix) with ESMTPSA id 93C9CF72362; Sun, 2 Jun 2024 14:03:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flump.de; s=mail; t=1717329817; bh=6U37JYeE8xNagXdwLXFL5igj6NaLmIWJ07ab0Y+AxCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=3cv6btDSH0KSa5i/9gAKD2hEshV+4UoedOZscOhpEokA+SwBKMd0mmynqutUd+tyk u7L/NW7tv/4URUOX0bnx7E5j/a8LpPYnMtuYvfMQGgRlr7C4e5039tFPZk0FMHaBY3 TlpXrkpSlv+w1EV0Mmp2NRmfnk7IJKrCXL/XsdhA= From: Gerion Entrup To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Jun 2024 14:02:53 +0200 Message-ID: <20240602120334.832369-1-gerion.entrup@flump.de> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240531201721.GO2821752@pb2> References: <20240531201721.GO2821752@pb2> 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 --- Sorry, it should apply clean now. 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 a0ca818a9b..46602874de 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 /= union_word(first->data[i], second->data[i]); } + 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".