Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error at template matching in Python

I'm trying to template matching using my web cam.I used web cam feed as source and used a template as small image that taken from web cam. Both template and source have same bit depth.(uint8). same data type of source(left) and template(right)

I'm using OpenCV3.0 with python 2.7 in VS 2013 IDE I got this error:

C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\imgproc\src\templmatch.cpp:1062: error: (-215) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2 in function cv::matchTemplate

Give me a solution

Thank in advance

Error at template matching in Python

I'm trying to template matching using my web cam.I used web cam feed as source and used a template as small image that taken from web cam. Both template and source have same bit depth.(uint8). same data type of source(left) and template(right)

I'm using OpenCV3.0 with python 2.7 in VS 2013 IDE I got this error:

C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\imgproc\src\templmatch.cpp:1062: error: (-215) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2 in function cv::matchTemplate

Code:

import cv2
import numpy as np

cam=cv2.VideoCapture(1)
template = cv2.imread("C:/Users/Nandika/Desktop/ttt.jpg",0)
w, h = template.shape[::-1]

method=cv2.TM_CCOEFF_NORMED

    while 1:
        _,img=cam.read()
        res = cv2.matchTemplate(img,template,method)
        min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)

        # If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
        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)

        cv2.rectangle(img,top_left, bottom_right, 255, 2)

        cv2.imshow('img',img)


        if cv2.waitKey(1) & 0xFF == ord('q'):
            cv2.destroyAllWindow

Give me a solution

Thank in advance