Browse Source

small fixes + MOG2 sandbox added

dianamaro 2 years ago
parent
commit
2b5b4399d9
3 changed files with 116 additions and 26 deletions
  1. 7 3
      background.ipynb
  2. 30 23
      hippoSIT.ipynb
  3. 79 0
      sandbox/MOG2.ipynb

+ 7 - 3
background.ipynb

@@ -31,8 +31,8 @@
    "source": [
     "is_light = True\n",
     "#settings_filename = os.path.join('profiles', 'kate_postrack.json')\n",
-    "#settings_filename = os.path.join('profiles', 'kate_aSIT_single.json')\n",
-    "settings_filename = os.path.join('profiles', 'andrey_hippoSIT_prod.json')\n",
+    "settings_filename = os.path.join('profiles', 'kate_aSIT_single.json')\n",
+    "#settings_filename = os.path.join('profiles', 'andrey_hippoSIT_prod.json')\n",
     "\n",
     "with open(settings_filename) as json_file:\n",
     "    cfg = json.load(json_file)"
@@ -40,7 +40,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -98,6 +98,10 @@
     "    cv2.imshow('Press \"c\" to capture, \"q\" to quit', frame)\n",
     "\n",
     "# When the background image is captured, release the capture\n",
+    "if board.is_light_off:\n",
+    "    board.switch_light()  # turn light back on\n",
+    "    time.sleep(0.1)\n",
+    "board.exit()\n",
     "cap.release()\n",
     "cv2.destroyAllWindows()"
    ]

File diff suppressed because it is too large
+ 30 - 23
hippoSIT.ipynb


+ 79 - 0
sandbox/MOG2.ipynb

@@ -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
+}