Ask Your Question
1

Image recognition on photo

asked 2019-09-14 09:21:46 -0500

maxp gravatar image

Hello

I am working on recognizing a given image in the world (through a photo). That is, a list of specific images is stored in the database, and when processing a photo with one of these images, it (the image) should be recognized.

I use SURF + flannBasedMatcher to recognize images, and Lowe's ratio test to sift out incorrect matches. But when comparing photos with many images stored in the database, there are still situations when the wrong image is recognized, since the number of keypoints is sufficient to find the image suitable.

I also wanted to tie the recognition of objects in the image in order to limit both database search and improve image recognition, but unfortunately, there are no suitable objects on my images that can be detected.

I think that comparing the contours of the necessary objects in the image and photo can help me, as an additional sign of recognition, but I don’t know yet how I can correctly implement this.

Help me please)

I use OpenCV 4 and python 3.6

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2019-09-17 07:41:51 -0500

maxp gravatar image

I did it.

It looks something like this.

  1. After matching, I filter them by double Lowe's test (good_threshold=0.59, less_good_threshold = 0.675) and get a match percent.

    good = []
    for m, n in matches:
        if m.distance < good_threshold*n.distance:
            good.append(m)
    
    less_good = []
    for m, n in matches:
        if m.distance < less_good_threshold*n.distance:
            less_good.append(m)
    
    match_percent = len(good) / len(less_good) * 100
    
  2. Then I get homography

    if len(matches) < 4: return None

    src_pts = np.float32( [kp1[m.queryIdx].pt for m in matches]).reshape(-1, 1, 2) dst_pts = np.float32( [kp2[m.trainIdx].pt for m in matches]).reshape(-1, 1, 2)

    H, _ = cv.findHomography(src_pts, dst_pts, cv.RANSAC, 5.0)

  3. Then I test homography

    def is_good_homography(H) -> bool: det = H[0][0] * H[1][1] - H[1][0] * H[0][1] if det < 0: return False

    N1 = math.sqrt(H[0][0] * H[0][0] + H[1][0] * H[1][0]) if (N1 > 4 or N1 < 0.1): return False

    N2 = math.sqrt(H[0][1] * H[0][1] + H[1][1] * H[1][1]) if (N2 > 4 or N2 < 0.1): return False

    N3 = math.sqrt(H[2][0] * H[2][0] + H[2][1] * H[2][1]) if (N3 > 0.002): return False

    return True

  4. If match percent and homography are good, the reference image is recognized on photo

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-09-14 09:21:46 -0500

Seen: 78 times

Last updated: Sep 17