0

Store Image: https://drive.google.com/open?id=1uNx_6KeQaNtKNj1Y2Npd-vOvJ4Pf-X4m Product Image: https://drive.google.com/open?id=1bev8AjajqbaceUPxVs2Z3iuqUOZaeoE-

I have to find a product image in store image If you look carefully, the appy is different. The product image is 2D while the store image is 3D

Any another approach?

I have tried Template matching function of opencv

    import cv2
    import numpy as np

    img_rgb = cv2.imread('C:\\Users\\ambuj\\Desktop\\NIFLR\\store1.png')
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)

    template = cv2.imread('C:\\Users\\ambuj\\Desktop\\NIFLR\\appy1.png',0)
    template= cv2.resize(template,(25,65))

    w,h = template.shape[::-1]

    res = cv2.matchTemplate(img_gray,template,cv2.TM_SQDIFF)

    threshold = 0.1

    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)
        break

    cv2.imshow('Detected',img_rgb)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

Expected Result: In the image where there is appy there should be a rectangle

Actual result: https://drive.google.com/open?id=18QiX4MWa90jIGdvhfRn5dEOwIA6SHYlx

There is red rectangle at top left most corner.

help-info.de
  • 6,695
  • 16
  • 39
  • 41

1 Answers1

0

I think you cannot detect it with a template matching, because the template is too different from the objects on the store image. Use cascade training to find this object.

https://docs.opencv.org/3.4.1/dc/d88/tutorial_traincascade.html

  • Thanks for this. But I have only one picture and for doing this I want more training pictures. What can be done if I have only this picture? – Ambuje Gupta May 07 '19 at 18:03
  • The opencv_createsamples can generate more samples from that one positive image. You can train with them. But it works only with simple objects, for example logos. I think you can do it. You need to detect the logo of that product just from several perspectives, it was too difficult for template matching, but not for the cascade training. Maybe this link also helps: http://www.swarthmore.edu/NatSci/mzucker1/opencv-2.4.10-docs/doc/user_guide/ug_traincascade.html#positive-samples –  May 07 '19 at 19:41