pageauc / speed-camera

A Unix, Windows, Raspberry Pi Object Speed Camera using python, opencv, video streaming, motion tracking. Includes a Standalone Web Server Interface, Image Search using opencv template match and a whiptail Admin Menu Interface Includes picam and webcam Plugins for motion track security camera configuration including rclone sync script. watch-app allows remotely controller camera configuration from a remote storage service name. Uses sqlite3 and gnuplot for reporting. Recently added openalpr license plate reader support.
Apache License 2.0
987 stars 173 forks source link

How to use ip cam? #19

Closed radhitee closed 6 years ago

radhitee commented 6 years ago

Hi, your code is awesome, I've tried this code,but I want to use my IP cam, how to use ip cam with this code? Thanks

pageauc commented 6 years ago

I do not have an IP camera to do testing but you could try reading directly from IP camera using config.py WEBCAM_SRC variable per sample below. Substitute your IP camera URL per sample below. Give that a try and let me know if it works.

WEBCAM = True WEBCAM_SRC = "http://192.168.0.153:5000/video_feed?dummy=mjpg"

If not you would need to write another threaded class to read the IP camera video stream from the IP camera. See sample code below

import cv2
import urllib 
import numpy as np

stream=urllib.urlopen('http://192.168.0.153:5000/video_feed')
bytes=''
while True:
    bytes+=stream.read(1024)
    a = bytes.find('\xff\xd8')
    b = bytes.find('\xff\xd9')
    if a!=-1 and b!=-1:
        jpg = bytes[a:b+2]
        bytes= bytes[b+2:]
        i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
        cv2.imshow('i',i)
        if cv2.waitKey(1) ==27:
            exit(0)
radhitee commented 6 years ago

Thanks, I will try

Pada tanggal Min, 25 Mar 2018 20.16, Claude Pageau notifications@github.com menulis:

I do not have an IP camera to do testing but you could try reading directly from IP camera using config.py WEBCAM_SRC variable per sample below. Substitute your IP camera URL per sample below. Give that a try and let me know if it works.

WEBCAM = True WEBCAM_SRC = "http://192.168.0.153:5000/video_feed?dummy=mjpg"

If not you would need to write another threaded class to read the IP camera video stream from the IP camera. See sample code below

import cv2 import urllib import numpy as np

stream=urllib.urlopen('http://192.168.0.153:5000/video_feed') bytes='' while True: bytes+=stream.read(1024) a = bytes.find('\xff\xd8') b = bytes.find('\xff\xd9') if a!=-1 and b!=-1: jpg = bytes[a:b+2] bytes= bytes[b+2:] i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR) cv2.imshow('i',i) if cv2.waitKey(1) ==27: exit(0)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/19#issuecomment-375969792, or mute the thread https://github.com/notifications/unsubscribe-auth/AE9kFUrAUZJqBXQza9nyag8xbAQOxps4ks5th5iygaJpZM4S6EjH .

pageauc commented 6 years ago

Below is a link for a class that reads IP camera stream and converts to jpg. It could be imported directly using import. Note it does not handle login to camera. If I get a chance I will setup one of my RPI's as an IP camera and do some testing to read stream into speed camera similar to class code below. As we will shortly be travelling, this may take a while. Claude ... https://github.com/BrandonJoffe/home_surveillance/blob/master/system/Camera.py