From c51424e0699b502388aafb22f7cbd60857fc53db Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Thu, 17 Feb 2022 19:58:47 -0800 Subject: [PATCH] First Commit --- README.md | 1 + pyimagesearch/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 162 bytes pyimagesearch/motion_detection/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 179 bytes .../singlemotiondetector.cpython-310.pyc | Bin 0 -> 1544 bytes .../motion_detection/singlemotiondetector.py | 57 ++++++++ templates/index.html | 23 ++++ webstreaming.py | 127 ++++++++++++++++++ 9 files changed, 208 insertions(+) create mode 100644 README.md create mode 100644 pyimagesearch/__init__.py create mode 100644 pyimagesearch/__pycache__/__init__.cpython-310.pyc create mode 100644 pyimagesearch/motion_detection/__init__.py create mode 100644 pyimagesearch/motion_detection/__pycache__/__init__.cpython-310.pyc create mode 100644 pyimagesearch/motion_detection/__pycache__/singlemotiondetector.cpython-310.pyc create mode 100644 pyimagesearch/motion_detection/singlemotiondetector.py create mode 100644 templates/index.html create mode 100644 webstreaming.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..05285af --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# simple-security-camera-page diff --git a/pyimagesearch/__init__.py b/pyimagesearch/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyimagesearch/__pycache__/__init__.cpython-310.pyc b/pyimagesearch/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..34f93a918776e5c02ac8b97bb7f595707ef37014 GIT binary patch literal 162 zcmd1j<>g`kf`%KsNg(<$h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o6w&*(xTqIJKxa zCM_p1H#5d1wK%&ZzaS={C_gJTxuiHII5oMnD6^!}IWae;pfWQzF+H_7HL)l;BPKpR fGcU6wK3=b&@)n0pZhlH>PO2Tq_+lm?!NLFlMtvw0 literal 0 HcmV?d00001 diff --git a/pyimagesearch/motion_detection/__init__.py b/pyimagesearch/motion_detection/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyimagesearch/motion_detection/__pycache__/__init__.cpython-310.pyc b/pyimagesearch/motion_detection/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5d4894afa87dab6be09f53920e566ffbbe78fd5f GIT binary patch literal 179 zcmd1j<>g`kf{q)!Ng(<$h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o11(*(xTqIJKxa zCM_p1H#5d1wK%&ZzaS={C_gJTxuiHII5oMnD6^!}IWae;pfWQzF+H_7HL)l;BPKV$ uBr`uRJ|(pTs1V4CiI30B%PfhH*DI*J#bJ}1pHiBWY6r5fm{+}CXzgly6sPA&bdxe10J-GC2nk%cEo}7?}Kq1Y`rfnCyN&{w|M1 zKAtAQJRa{w`BRxK#>XO?feZO~6orL|<#IQej~B~$9-K#c6o~L*JU6cT-1rJkk8=}2 zEv}`Rc(_I_iX@Ox zow&R3b-lbA8^GvW zOqef#k!YpEAS-IZ!)sDfkTFFS;Y8}-7^e?V$$+;NgL;Mf`h}W(5?rcL(LQ1=AXs(573KFMm%1vcmVQxPq;z%b`S$pWmk4ivV-Ba!w zk6GC&+hwQh%AT@S>x#hIQ0*&ni@2p6)l!|e5u9wPrfRFM=4Afx)SvXF!8X%?Fof6%H$W zS>a`cf3EPwYc*N7;5z`Ge*k2g-p8A46L%TI?4?V(xQE-6VTbnM+QXpJ%*CG~f39XGM_IC!z_eLYKApP!s(FxI=WS2>qzK=uP7| v$i+^h>l$g_@~pI&FP7pht+=g;erR)e2gab9K6JjQ{rFOsMGc4@_ + + Video Surveillance + + + +

Video Surveillance

+
+ +
+ + \ No newline at end of file diff --git a/webstreaming.py b/webstreaming.py new file mode 100644 index 0000000..98a1de7 --- /dev/null +++ b/webstreaming.py @@ -0,0 +1,127 @@ +# import the necessary packages +from pyimagesearch.motion_detection.singlemotiondetector import SingleMotionDetector +from imutils.video import VideoStream +from flask import Response +from flask import Flask +from flask import render_template +import threading +import argparse +import datetime +import imutils +import time +import cv2 + +# initialize the output frame and a lock used to ensure thread-safe +# exchanges of the output frames (useful when multiple browsers/tabs +# are viewing the stream) +outputFrame = None +lock = threading.Lock() + +# initialize a flask object +app = Flask(__name__) + +# initialize the video stream and allow the camera sensor to +# warmup +#vs = VideoStream(usePiCamera=1).start() +vs = VideoStream(src=0).start() +time.sleep(2.0) + +@app.route("/") +def index(): + # return the rendered template + return render_template("index.html") + +def detect_motion(frameCount): + # grab global references to the video stream, output frame, and + # lock variables + global vs, outputFrame, lock + + # initialize the motion detector and the total number of frames + # read thus far + md = SingleMotionDetector(accumWeight=0.1) + total = 0 + + # loop over frames from the video stream + while True: + # read the next frame from the video stream, resize it, + # convert the frame to grayscale, and blur it + frame = vs.read() + frame = imutils.resize(frame, width=400) + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + gray = cv2.GaussianBlur(gray, (7, 7), 0) + + # grab the current timestamp and draw it on the frame + timestamp = datetime.datetime.now() + cv2.putText(frame, timestamp.strftime( + "%A %d %B %Y %I:%M:%S%p"), (10, frame.shape[0] - 10), + cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1) + + # if the total number of frames has reached a sufficient + # number to construct a reasonable background model, then + # continue to process the frame + if total > frameCount: + # detect motion in the image + motion = md.detect(gray) + + # check to see if motion was found in the frame + if motion is not None: + # unpack the tuple and draw the box surrounding the + # "motion area" on the output frame + (thresh, (minX, minY, maxX, maxY)) = motion + cv2.rectangle(frame, (minX, minY), (maxX, maxY), + (0, 0, 255), 2) + + # update the background model and increment the total number + # of frames read thus far + md.update(gray) + total += 1 + + # acquire the lock, set the output frame, and release the + # lock + with lock: + outputFrame = frame.copy() + +def generate(): + # grab global references to the output frame and lock variables + global outputFrame, lock + + # loop over frames from the output stream + while True: + # wait until the lock is acquired + with lock: + # check if the output frame is available, otherwise skip + # the iteration of the loop + if outputFrame is None: + continue + + # encode the frame in JPEG format + (flag, encodedImage) = cv2.imencode(".jpg", outputFrame) + + # ensure the frame was successfully encoded + if not flag: + continue + + # yield the output frame in the byte format + yield(b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + + bytearray(encodedImage) + b'\r\n') + +@app.route("/video_feed") +def video_feed(): + # return the response generated along with the specific media + # type (mime type) + return Response(generate(), + mimetype = "multipart/x-mixed-replace; boundary=frame") + +# check to see if this is the main thread of execution +if __name__ == '__main__': + # start a thread that will perform motion detection + t = threading.Thread(target=detect_motion, args=(32,)) + t.daemon = True + t.start() + + # start the flask app + app.run(host="0.0.0.0", port=8080, debug=False, + threaded=True, use_reloader=False) + +# release the video stream pointer +vs.stop() \ No newline at end of file