Template Matching

비록 Self Driving Car에서의 Object Detection에서는 차 형태나 색깔의 다양성으로 인해 쓰이지는 않으나 다른 부분에서 참고할만하다.

OpenCV

http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html

Udacity

https://classroom.udacity.com/nanodegrees/nd013/parts/fbf77062-5703-404e-b60c-95b78b2f3f9e/modules/2b62a1c3-e151-4a0e-b6b6-e424fa46ceab/lessons/05b03f20-8c4b-453c-b41e-9fac590278c7/concepts/9acf11c2-a5a9-4e5a-ba86-1e92246fff99

Find Matches Implementation

# Define a function to search for template matches

# and return a list of bounding boxes

def find_matches(img, template_list):

\# Define an empty list to take bbox coords

bbox\_list = \[\]

\# Define matching method

\# Other options include: cv2.TM\_CCORR\_NORMED', 'cv2.TM\_CCOEFF', 'cv2.TM\_CCORR',

\#         'cv2.TM\_SQDIFF', 'cv2.TM\_SQDIFF\_NORMED'

method = cv2.TM\_CCOEFF\_NORMED

\# Iterate through template list

for temp in template\_list:

    \# Read in templates one by one

    tmp = mpimg.imread\(temp\)

    \# Use cv2.matchTemplate\(\) to search the image

    result = cv2.matchTemplate\(img, tmp, method\)

    \# Use cv2.minMaxLoc\(\) to extract the location of the best match

    min\_val, max\_val, min\_loc, max\_loc = cv2.minMaxLoc\(result\)

    \# Determine a bounding box for the match

    w, h = \(tmp.shape\[1\], tmp.shape\[0\]\)

    if method in \[cv2.TM\_SQDIFF, cv2.TM\_SQDIFF\_NORMED\]:

        top\_left = min\_loc

    else:

        top\_left = max\_loc

    bottom\_right = \(top\_left\[0\] + w, top\_left\[1\] + h\)

    \# Append bbox position to list

    bbox\_list.append\(\(top\_left, bottom\_right\)\)

    \# Return the list of bounding boxes

return bbox\_list

results matching ""

    No results matching ""