1 | initial version |
Supra56, thank you for the additional interest:
import cv2 import numpy as np
cap = cv2.VideoCapture(0) cv2.startWindowThread() while(1): _, frame = cap.read() cv2.imshow('frame',frame) k = cv2.waitKey(1) if k == 27: break
cap.release() cv2.destroyAllWindows()
The issue is I can not halt the video feed, must kill via closing the command line editor.
The second example must halt via closing the image, pressing keyboard has no effect.
import cv2 import numpy as np
img_rgb = cv2.imread('opencv-template-matching-python-tutorial.jpg') img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('opencv-template-for-matching.jpg',0) w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED) threshold = 0.8 loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]): cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,255,255), 2)
cv2.imshow('Detected',img_rgb) cv2.waitKey(0) cv2.destroyAllWindows()