This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I'm pretty new to opencv. I snagged some code from the web and am doing template matching with saved images with no problem.
I can also take snapshots from the cam and save them, etc.
Where I run into issues is trying to combine the two. For this exercise I'm just trying to locate an icon on my phone. Although the code runs, I'm not getting the results I'm after. Here is my horrible attempt to make this happen. Where am I going wrong?
import cv2
import numpy as np
cam = cv2.VideoCapture('http://192.168.1.99/videostream.cgi?user=admin&pwd=snoozer')
cv2.namedWindow("test")
while True:
ret, frame = cam.read()
cv2.imshow("test", frame)
if not ret:
break
k = cv2.waitKey(1)
if k%6 == 27:
# ESC pressed
print("Escape hit, closing...")mport cv2
cam = cv2.VideoCapture('http://192.168.1.99/videostream.cgi?user=admin&pwd=snoozer')
cv2.namedWindow("test")
while True:
ret, frame = cam.read()
cv2.imshow("test", frame)
elif k%6 == 32:
# SPACE pressed
image = cam.read()
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
template = cv2.imread('newopencvicon.png',0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(gray_frame, template, cv2.TM_CCOEFF_NORMED)
threshold = .7
loc = np.where(res >= threshold)
cv2.startWindowThread()
for pt in zip(*loc[::-1]):
ctrpntx = pt[0] w/2
ctrpnty = pt[1] h/2
cv2.circle(image, (int(ctrpntx),int(ctrpnty)), int(w/2), (255,0,255), 5)
cv2.namedWindow("Found It!")
cv2.imshow('Found It!', frame)
cv2.imwrite('result.png',frame)
cv2.waitKey(0)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
sys.exit()
cam.release()
cv2.destroyAllWindows()
I'm sure there's a LOT wrong here and probably some unnecessary things, but this is a First Pancake and a learning exercise for me.
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/opencv/comm...