Maintenance - We're currently working on things and you might experience some issues. Should be wrapped up soon!

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.

2
[Question] IP Cam and Template Matching
Post Flair (click to view more posts with a particular flair)
Author Summary
nonewjobs is in Question
Post Body

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.

Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
17,628
Link Karma
1,023
Comment Karma
16,545
Profile updated: 2 days ago
Posts updated: 7 months ago

Subreddit

Post Details

Location
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago