title: Object detection with OpenCV
body: <p>i'm currently trying to study Computer Vision and playing with Python OpenCV 3. </p>
  
  <p>What i'm trying to implement is detector that takes <em>logo image</em> and some other image, that may or may not contain this logo, and finds all appearances of logo on this image. Logo on this image can be scaled, rotated, shot at different angle. Here is test dataset: <a href="https://imgur.com/a/aT5g1" rel="nofollow">https://imgur.com/a/aT5g1</a></p>
  
  <p>First 2 images is 'logo images' and others are images to search logo on and then results that my current implementation returns. Worst case is last picture where truck with Mars logo shot at different, from 'logo image', angle.</p>
  
  <p>Here is my current implementation which is very trivial:</p>
  
  <pre><code>def match(im1,im2,detector=sift,iterations=5,matcher=BFmatch,min_matches=10,detector_kwargs={}):
      img1 = load_image(im1)
      img2 = load_image(im2)
      train_img = load_image(im2)
  
      src_img, kp1, des1 = detector(img1)
      train_img, kp2, des2 = detector(train_img)
  
      matches = matcher(des1,des2)
  
      for i in range(iterations):
          if len(matches) &lt; min_matches:
              break
          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)
  
          M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
  
          h,w,_ = img1.shape
          pts = np.float32([ [0,0],[0,h-1],[w-1,h-1],[w-1,0] ]).reshape(-1,1,2)
          dst = cv2.perspectiveTransform(pts,M)
  
          img2 = cv2.polylines(img2,[np.int32(dst)],True,255,3, cv2.LINE_AA)
          train_img = cv2.fillPoly(train_img,[np.int32(dst)],True,255)
  
          train_img, kp2, des2 = detector(train_img)
  
          matches = matcher(des1,des2)
  
  
      img3 = cv2.drawMatches(img1,kp1,img2,kp2,None,None,flags=2)
  
      plt.imshow(img3),plt.show()
  </code></pre>
  
  <p>Here i use SIFT detector(sift) and Brute Force Matcher(BFmatch).</p>
  
  <p>I would be glad to hear advices and recommendations how i can impove this detector.</p>