Find similar image inside another image with opencv

Viewed 3173

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

Inside this image: enter image description here I need to find this image: enter image description here

or inside this enter image description here find this enter image description here.

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?

2 Answers

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.

Related