简体   繁体   中英

Find similar image inside another image with opencv

I have to understand if an image contains another similar image. Here 2 example:

Inside this image: 在此处输入图像描述 I need to find this image: 在此处输入图像描述

or inside this在此处输入图像描述 find this在此处输入图像描述 .

The idea is: given an input image and a set of icons find which icon is present in the input image.

I've tried using MatchTemplate and feature matching with ORB and SIFT but I couldn't find any valid matches.

Here my try with MatchTemplate in Go:

package main

import (
    "fmt"
    "image/color"

    "gocv.io/x/gocv"
)

func main() {
    matImage := gocv.IMRead("/Users/pioz/Desktop/samplex.jpg", gocv.IMReadGrayScale)
    // gocv.Canny(matImage, &matImage, 200, 400)
    matTemplate := gocv.IMRead("/Users/pioz/Desktop/eld.jpg", gocv.IMReadGrayScale)
    // gocv.Canny(matTemplate, &matTemplate, 20, 40)
    matResult := gocv.NewMat()
    mask := gocv.NewMat()
    gocv.MatchTemplate(matImage, matTemplate, &matResult, gocv.TmCcoeffNormed, mask)
    mask.Close()
    minConfidence, maxConfidence, minLoc, maxLoc := gocv.MinMaxLoc(matResult)
    fmt.Println(minConfidence, maxConfidence, minLoc, maxLoc)

    gocv.Circle(&matImage, minLoc, 10, color.RGBA{0, 0, 255, 1}, 10)
    gocv.Circle(&matImage, maxLoc, 10, color.RGBA{0, 0, 255, 1}, 10)

    gocv.IMWrite("out/out.jpg", matImage)
}

Do you have any advice or snippet to solve this kind of problem?

I believe this question has already been asked - here .

Templete matching is supposed to be one of the best techniques for this kind of image processing. So, if it's not working for you, try reviewing/sharing the code you have implemented.

This link is related to OpenCV which explains feature matching and different techniques. There is also examples with code, which may come of use. Also if SIFT doesn't give staisfactory result, try affine SIFT or ASIFT .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM