i using Python 2.7 and opencv 2.4.13.6
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
template = cv2.imread("bildklein.jpg") #Zugriff auf Bild 2
gray_template = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
w, h = gray_template.shape[::-1]
while True:
_, frame = cap.read()
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
res = cv2.matchTemplate(gray_frame, gray_template, cv2.TM_CCOEFF_NORMED)
loc = np.where(res >= 0.6)
for pt in zip(*loc[::-1]):
cv2.rectangle(frame, pt, (pt[0] + w, pt[1] + h), (0, 255, 0), 3)
cv2.imshow("Frame", frame)
if cv2.waitKey(1) & 0xFF == ord('q'): #Schliessen der Videofenster (Taste q)
break
cap.release()
cv2.destroyAllWindows()
It doesn't work. I have three problems and i do not find a solution.
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 18: invalid start byte
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::cvtColor, file C:\build\2_4_winpack-bindings-win32-vc14-static\opencv\modules\imgproc\src\color.cpp, line 3783 Traceback (most recent call last):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 18: ordinal not in range(128)