|
@@ -0,0 +1,79 @@
|
|
|
+{
|
|
|
+ "cells": [
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 1,
|
|
|
+ "id": "843cf979",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "from controllers.situtils import FPSTimes"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 2,
|
|
|
+ "id": "73a265dc",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "from __future__ import print_function\n",
|
|
|
+ "import cv2 as cv\n",
|
|
|
+ "import time\n",
|
|
|
+ "\n",
|
|
|
+ "#backSub = cv.createBackgroundSubtractorMOG2()\n",
|
|
|
+ "backSub = cv.createBackgroundSubtractorKNN()\n",
|
|
|
+ "\n",
|
|
|
+ "capture = cv.VideoCapture(0, 700)\n",
|
|
|
+ "capture.set(cv.CAP_PROP_FPS, 20)\n",
|
|
|
+ "time.sleep(1)\n",
|
|
|
+ "capture.set(cv.CAP_PROP_FRAME_WIDTH, 1024)\n",
|
|
|
+ "capture.set(cv.CAP_PROP_FRAME_HEIGHT, 768)\n",
|
|
|
+ "capture.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc('M', 'J', 'P', 'G'))\n",
|
|
|
+ "\n",
|
|
|
+ "fps = FPSTimes()\n",
|
|
|
+ "\n",
|
|
|
+ "while True:\n",
|
|
|
+ " ret, frame = capture.read()\n",
|
|
|
+ " fps.count()\n",
|
|
|
+ " if frame is None:\n",
|
|
|
+ " break\n",
|
|
|
+ " \n",
|
|
|
+ " fgMask = backSub.apply(frame)\n",
|
|
|
+ " \n",
|
|
|
+ " cv.rectangle(frame, (10, 2), (100,20), (255,255,255), -1)\n",
|
|
|
+ " cv.putText(fgMask, str(capture.get(cv.CAP_PROP_POS_FRAMES)), (15, 15), cv.FONT_HERSHEY_SIMPLEX, 0.5 ,(255,255,255))\n",
|
|
|
+ " cv.putText(fgMask, '%.2f FPS' % fps.get_avg_fps(), (10, 40), cv.FONT_HERSHEY_DUPLEX, .5, (255,255,255)) \n",
|
|
|
+ "\n",
|
|
|
+ " #cv.imshow('Frame', frame)\n",
|
|
|
+ " cv.imshow('FG Mask', fgMask)\n",
|
|
|
+ " \n",
|
|
|
+ " keyboard = cv.waitKey(30)\n",
|
|
|
+ " if keyboard == 'q' or keyboard == 27:\n",
|
|
|
+ " capture.release()\n",
|
|
|
+ " break"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "metadata": {
|
|
|
+ "kernelspec": {
|
|
|
+ "display_name": "Python 3",
|
|
|
+ "language": "python",
|
|
|
+ "name": "python3"
|
|
|
+ },
|
|
|
+ "language_info": {
|
|
|
+ "codemirror_mode": {
|
|
|
+ "name": "ipython",
|
|
|
+ "version": 3
|
|
|
+ },
|
|
|
+ "file_extension": ".py",
|
|
|
+ "mimetype": "text/x-python",
|
|
|
+ "name": "python",
|
|
|
+ "nbconvert_exporter": "python",
|
|
|
+ "pygments_lexer": "ipython3",
|
|
|
+ "version": "3.8.8"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "nbformat": 4,
|
|
|
+ "nbformat_minor": 5
|
|
|
+}
|