The tutorial is easy to understand

Usage scenarios

Look for contours that are similar to existing images

Results show

Find contour results

The original image

The picture to look for

Autojs version

8.8.16-0

Autojs bring opencv3.4.3

Script summary

Compare the similarity between two shapes using matchShapes,

The first parameter is object 1 to be matched, the second is object 2 to be matched,

The most important thing is to be visual. Opencv supports drawing any graphics as well as text

Find similar outline steps explained

1. See what contours are available

2. What we are looking for is the heart in the upper right corner. Cut out the heart from the original picture and take a look at the outline of the heart

3. We note the comparison outline, matchShapes returns a distance, we take below 2 and draw the value

4. There are too many similar silhouettes, and some silhouettes are obviously not similar, so we add regional dimensions, such as just the right one

This head is round. How is it more similar than a heart? (The lower the similarity, the more similar)

The normal return value is 0 or 1 at the maximum for matchShapes.

Change the matchShapes parameter to 0.03

6. So far, you have found the outline of love

If there are still more than one contour, we can continue to add dimensions, such as the contour’s area, aspect ratio, color, width and height,

A bit more complex can be matched with the relative position of other more obvious contours

The general steps of processing images

Read image –> Gaussian Blur –> Grayscale –> binarization –> findContours–>

matchShapes–>minAreaRect–> contourArea–> drawContours

The statement

This tutorial is for study only and is prohibited for other purposes