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 BD2A946D1A for ; Sun, 5 May 2024 22:30:51 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E30C568D574; Mon, 6 May 2024 01:30:48 +0300 (EEST) Received: from flump.de (flump.de [185.163.118.210]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9281C68D525 for ; Mon, 6 May 2024 01:30:42 +0300 (EEST) Received: from falbala.fritz.box (ip4d1692dd.dynamic.kabel-deutschland.de [77.22.146.221]) by flump.de (Postfix) with ESMTPSA id B6008D6CBD4; Mon, 6 May 2024 00:30:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flump.de; s=mail; t=1714948241; bh=ibyjaZFeD9xgxiblp9n8upTlQRYagOedIFfM5VvvXUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JW+j3V7FMgsnjw+Lfjj7xDhqQLpJPodwaLyoT8lTPpCvch5HzvqPe2swa49hf+nNe r4NrRC4GhNkrW1xLRPVyi0QBOvW4DQhnuyWvbZPJZp8BYTRYwbFsrfXHhE7XCrZIKm maYx4b8qLDs2cXg5n9co5pGOFw7KcrAB7WNv0OmE= From: Gerion Entrup To: ffmpeg-devel@ffmpeg.org Date: Mon, 6 May 2024 00:30:40 +0200 Message-ID: <20240505223040.521838-2-gerion.entrup@flump.de> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240505223040.521838-1-gerion.entrup@flump.de> References: <20240505223040.521838-1-gerion.entrup@flump.de> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] 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".