From 5572a775f44cefed8c8c14da29ecef11c5d3593e Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期二, 07 五月 2024 16:52:11 +0800 Subject: [PATCH] 修复以图搜图出现多个相同目标的bug --- compare/compare.go | 34 ++++++++++++++++++++++++++++++---- 1 files changed, 30 insertions(+), 4 deletions(-) diff --git a/compare/compare.go b/compare/compare.go index 8121d58..59f989a 100644 --- a/compare/compare.go +++ b/compare/compare.go @@ -40,7 +40,19 @@ if _, ok := cache.CacheMap.Area[id]; ok { targets := cache.CacheMap.Area[id].Walk(DoSdkCompare, floatFeat, baseScore) if len(targets) > 0 { - scResult.CompareResult = append(scResult.CompareResult, targets...) + // 姣斿缁撴灉鍘婚噸, 鍚屼竴涓汉鍒拌杩囧涓皬鍖�, 缂撳瓨鏁版嵁鍐呬細鏈夊鏉¤褰� + for idx, t := range targets { + var isRepeat bool + for _, r := range scResult.CompareResult { + if t.Id == r.Id { + isRepeat = true + break + } + } + if !isRepeat { + scResult.CompareResult = append(scResult.CompareResult, targets[idx]) + } + } } walkedArea[id] = struct{}{} @@ -64,15 +76,29 @@ targets := val.Walk(DoSdkCompare, floatFeat, baseScore) if len(targets) > 0 { - scResult.CompareResult = append(scResult.CompareResult, targets...) + if len(targets) > 0 { + // 姣斿缁撴灉鍘婚噸, 鍚屼竴涓汉鍒拌杩囧涓皬鍖�, 缂撳瓨鏁版嵁鍐呬細鏈夊鏉¤褰� + for idx, t := range targets { + var isRepeat bool + for _, r := range scResult.CompareResult { + if t.Id == r.Id { + isRepeat = true + break + } + } + if !isRepeat { + scResult.CompareResult = append(scResult.CompareResult, targets[idx]) + } + } + } // todo 娣诲姞灏忓尯澶栫殑鍏宠仈鍏崇郴, 涓嬫浼樺厛姣斿 } } done: - logger.Debugf("姣斿缁撴灉 %d鏉�, %+v", len(scResult.CompareResult), scResult.CompareResult) + logger.Debugf("姣斿缁撴灉 %d鏉�", len(scResult.CompareResult)) if len(scResult.CompareResult) > 0 { - logger.Debugf("姣斿缁撴灉%+v", scResult.CompareResult) + logger.Debugf("姣斿缁撴灉%+v", scResult.CompareResult) } buf, err := proto.Marshal(&scResult) -- Gitblit v1.8.0