[Python] Why does the variance result exceed 0 when using the TM_SQDIFF method to match an...

Discussão em 'Python' iniciado por Stack, Maio 21, 2025.

  1. Stack

    Stack Membro Participativo

    My code looks like this:

    import numpy as np
    import cv2

    print(f'cv2_version:{cv2.__version__}')
    test_image = cv2.imread('LIDjQLdr.jpg')
    test_gray_image = cv2.cvtColor(test_image , cv2.COLOR_BGR2GRAY)

    result = cv2.matchTemplate(test_gray_image, test_gray_image, cv2.TM_SQDIFF)
    min_val, _, min_loc, _ = cv2.minMaxLoc(result)
    print("min_val:", min_val)
    print("min_loc:", min_loc)


    This is the test image:

    [​IMG]

    Result:

    cv2_version:4.5.4

    min_val: 160.0

    min_loc: (0, 0)


    Why is the min_val greater than 0 when it should be zero?

    Continue reading...

Compartilhe esta Página