# The best way for find simple pattern on image

Hi, I would like to to find simple, specific pattern on images.

Images are black and white (binary, only value 0 for black and 255 for white). Contains ONLY white circles on black background. I need to find on them the pattern consists of five white circles arranged according to exact proportions like below (like constelation) .

On images the pattern can be rotated to any angle and freely scaled. The circles may be slightly different sizes. In fact, each of circle can be treated as a single point x, y. The image may have a different number of circles (zero included).

How is the best way to find this pattern on images using openCV?
I try to use code below, but with no success.

``````orb = cv2.ORB_create(nfeatures=1000)
kp1, des1 = orb.detectAndCompute(img1, None)
kp2, des2 = orb.detectAndCompute(img2, None)

bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)
``````

look up how ORB features work, to get an idea, why they perform poorly on your image

(wrong tool for the job)
((and ideally, you read up before writing any code â€¦))

is it some kind of â€śfiducialâ€ť or marker, you are trying to detect ?
if so, how do they get constructed ? is there some â€śgeneratorâ€ť / formula, which can be exploited later ? (RANSAC ?)

arbitrary scale makes this difficult.

there might be some math that I donâ€™t know that makes it â€śeasyâ€ť.

Iâ€™d craft some specific code for this pattern. find three points that are colinear and at equal distances. thatâ€™s a â€ścombinatorialâ€ť problem. then try to find the other two that are off the axis and check if theyâ€™re at the right distance.

you could use flann with k=2 (or more) nearest neighbor query to quickly find nearest points.

before all that, find the blobs and reduce them to points. you have points. the blob, and any shape it has, is irrelevant.

use SimpleBlobDetector to find those blobs.

3 Likes