1

I am currently using OpenCV and Python to parse through screenshots of websites to identify if any of the logos in my database are present in the screenshot. Basically just finding a small image within a larger image. Most libraries like OpenCV can do this, but they do it visually by outlining where the smaller image is found or something. I just need to return True or False to indicate whether the logo was found in the image. Any help would be appreciated! I'm using OpenCV, Pillow, and Numpy right now, but I'm open to suggestions if anyone knows a better library to use for this. Here is my current function:

def check_image(screenshot_template, logo_template):

    try:
        img_rgb = cv2.imread(screenshot_template)
        img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
        template = cv2.imread(logo_template,0)
        w, h = template.shape[::-1]

        res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
        threshold = 0.7
        loc = np.where( res >= threshold)
        for pt in zip(*loc[::-1]):
            cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)

        cv2.imwrite('res.jpg',img_rgb)
        check = equal(screenshot_template, '/home/ubuntu/cerberus/res.jpg')
        return check
    except Exception as e:
        print e
        return True
CHV
  • 11
  • 1
  • IIUC you need to check if `res` is lesser than some threshold. See [this](http://stackoverflow.com/a/32532321/3293881), seems very close, with a different template match mode. – Divakar Mar 24 '16 at 19:00
  • Thanks @Divakar. I'll check that out and see if I can tweak what they have going on there to work for my code. – CHV Mar 24 '16 at 19:29

0 Answers0