How do we search and release on the OpenCV template?



  • Can't understand what's wrong? I'm looking for a picture in the picture, and the releases aren't going to happen where I need to test all the search methods.

    Фрагмент который ищу

    фото где ищу

    результат

    Code:

    import cv2
    method = cv2.TM_CCOEFF
    small_image = cv2.imread('shab4.png') # что ищу
    large_image = cv2.imread('output.png') # где ищу
    result = cv2.matchTemplate(small_image, large_image, method)
    mn,_,mnLoc,_ = cv2.minMaxLoc(result)
    MPx,MPy = mnLoc
    trows,tcols = small_image.shape[:2]
    cv2.rectangle(large_image, (MPx,MPy),(MPx+tcols,MPy+trows),(0,0,255),5)
    res = cv2.resize(large_image, dsize=(2500,2500))
    cv2.namedWindow("Resized", cv2.WINDOW_NORMAL)
    cv2.imshow("Resized", res)
    cv2.waitKey(0)
    

    Somehow the code can find a picture in the picture, and there's no text.



  • cv2.matchTemplate returns unpredictable results that are most likely to coincide with the required result, which misleads the user about the reliability of the function. I mean, you can't rely on that function, ever. She may even find an insulation where he is not and cannot be (in all search modes). There is a need for a different approach: to create a desired image from the text, by means of a pillow, to compare picels (if there is no transparency, the results are quite precise). In other words, writing a search function on its own, there's no realisation of it.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2