|
@@ -2,15 +2,18 @@
|
|
"cells": [
|
|
"cells": [
|
|
{
|
|
{
|
|
"cell_type": "code",
|
|
"cell_type": "code",
|
|
- "execution_count": 76,
|
|
|
|
|
|
+ "execution_count": 1,
|
|
"metadata": {},
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"outputs": [],
|
|
"source": [
|
|
"source": [
|
|
"import cv2\n",
|
|
"import cv2\n",
|
|
"import os, json\n",
|
|
"import os, json\n",
|
|
"import numpy as np\n",
|
|
"import numpy as np\n",
|
|
|
|
+ "import time\n",
|
|
"\n",
|
|
"\n",
|
|
- "from controllers.situtils import FPSTimes"
|
|
|
|
|
|
+ "import nbimporter\n",
|
|
|
|
+ "from controllers.situtils import FPSTimes\n",
|
|
|
|
+ "from controllers.serial import MCSArduino"
|
|
]
|
|
]
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -22,14 +25,14 @@
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"cell_type": "code",
|
|
"cell_type": "code",
|
|
- "execution_count": 77,
|
|
|
|
|
|
+ "execution_count": 2,
|
|
"metadata": {},
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"outputs": [],
|
|
"source": [
|
|
"source": [
|
|
"is_light = True\n",
|
|
"is_light = True\n",
|
|
"#settings_filename = os.path.join('profiles', 'kate_postrack.json')\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', 'kate_aSIT_single.json')\n",
|
|
- "settings_filename = os.path.join('profiles', 'andrey_hippoSIT_test.json')\n",
|
|
|
|
|
|
+ "settings_filename = os.path.join('profiles', 'andrey_hippoSIT_prod.json')\n",
|
|
"\n",
|
|
"\n",
|
|
"with open(settings_filename) as json_file:\n",
|
|
"with open(settings_filename) as json_file:\n",
|
|
" cfg = json.load(json_file)"
|
|
" cfg = json.load(json_file)"
|
|
@@ -37,10 +40,12 @@
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"cell_type": "code",
|
|
"cell_type": "code",
|
|
- "execution_count": 78,
|
|
|
|
|
|
+ "execution_count": 3,
|
|
"metadata": {},
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"outputs": [],
|
|
"source": [
|
|
"source": [
|
|
|
|
+ "board = MCSArduino(cfg['experiment']['MCSArduinoPort'])\n",
|
|
|
|
+ "\n",
|
|
"# Define BGR colors\n",
|
|
"# Define BGR colors\n",
|
|
"BGR_COLOR = {\n",
|
|
"BGR_COLOR = {\n",
|
|
" 'red': (0,0,255),\n",
|
|
" 'red': (0,0,255),\n",
|
|
@@ -56,10 +61,11 @@
|
|
"cfg_pos = cfg['position']\n",
|
|
"cfg_pos = cfg['position']\n",
|
|
"\n",
|
|
"\n",
|
|
"cap = cv2.VideoCapture(cfg_cam['source'], cfg_cam['api']) if cfg_cam['api'] else cv2.VideoCapture(cfg_cam['source'])\n",
|
|
"cap = cv2.VideoCapture(cfg_cam['source'], cfg_cam['api']) if cfg_cam['api'] else cv2.VideoCapture(cfg_cam['source'])\n",
|
|
- "cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))\n",
|
|
|
|
|
|
+ "cap.set(cv2.CAP_PROP_FPS, cfg_cam['fps'])\n",
|
|
|
|
+ "time.sleep(1) # this helps to keep the FPS stable\n",
|
|
"cap.set(cv2.CAP_PROP_FRAME_WIDTH, cfg_cam['frame_width'])\n",
|
|
"cap.set(cv2.CAP_PROP_FRAME_WIDTH, cfg_cam['frame_width'])\n",
|
|
"cap.set(cv2.CAP_PROP_FRAME_HEIGHT, cfg_cam['frame_height'])\n",
|
|
"cap.set(cv2.CAP_PROP_FRAME_HEIGHT, cfg_cam['frame_height'])\n",
|
|
- "cap.set(cv2.CAP_PROP_FPS, cfg_cam['fps'])\n",
|
|
|
|
|
|
+ "\n",
|
|
"cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) \n",
|
|
"cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) \n",
|
|
"\n",
|
|
"\n",
|
|
"fps = FPSTimes()\n",
|
|
"fps = FPSTimes()\n",
|
|
@@ -76,17 +82,20 @@
|
|
" cv2.circle(mask, (cfg_pos['arena_x'], cfg_pos['arena_y']), cfg_pos['arena_radius'], BGR_COLOR['white'], -1)\n",
|
|
" cv2.circle(mask, (cfg_pos['arena_x'], cfg_pos['arena_y']), cfg_pos['arena_radius'], BGR_COLOR['white'], -1)\n",
|
|
" \n",
|
|
" \n",
|
|
" frame = cv2.bitwise_and(src1=frame, src2=mask)\n",
|
|
" frame = cv2.bitwise_and(src1=frame, src2=mask)\n",
|
|
- " cv2.putText(frame, 'LIGHT' if is_light else 'DARK', (10, 20), cv2.FONT_HERSHEY_DUPLEX, .5, BGR_COLOR['white'])\n",
|
|
|
|
- " cv2.putText(frame, '%.2f FPS' % fps.get_avg_fps(), (10, 40), cv2.FONT_HERSHEY_DUPLEX, .5, BGR_COLOR['white']) \n",
|
|
|
|
- " cv2.imshow('Press \"c\" to capture, \"q\" to quit', frame)\n",
|
|
|
|
- "\n",
|
|
|
|
|
|
+ " \n",
|
|
" k = cv2.waitKey(33)\n",
|
|
" k = cv2.waitKey(33)\n",
|
|
" if k == ord('c'):\n",
|
|
" if k == ord('c'):\n",
|
|
" f_name = cfg_pos['background_light'] if is_light else cfg_pos['background_dark']\n",
|
|
" f_name = cfg_pos['background_light'] if is_light else cfg_pos['background_dark']\n",
|
|
" cv2.imwrite(os.path.join('assets', f_name), frame)\n",
|
|
" cv2.imwrite(os.path.join('assets', f_name), frame)\n",
|
|
|
|
+ " if k == ord('l'):\n",
|
|
|
|
+ " board.switch_light()\n",
|
|
|
|
+ " is_light = not is_light\n",
|
|
|
|
+ " if k == ord('q'): # full quit\n",
|
|
" break\n",
|
|
" break\n",
|
|
- " if k == ord('q'):\n",
|
|
|
|
- " break \n",
|
|
|
|
|
|
+ " \n",
|
|
|
|
+ " cv2.putText(frame, 'LIGHT' if is_light else 'DARK', (10, 20), cv2.FONT_HERSHEY_DUPLEX, .5, BGR_COLOR['white'])\n",
|
|
|
|
+ " cv2.putText(frame, '%.2f FPS' % fps.get_avg_fps(), (10, 40), cv2.FONT_HERSHEY_DUPLEX, .5, BGR_COLOR['white']) \n",
|
|
|
|
+ " cv2.imshow('Press \"c\" to capture, \"q\" to quit', frame)\n",
|
|
"\n",
|
|
"\n",
|
|
"# When the background image is captured, release the capture\n",
|
|
"# When the background image is captured, release the capture\n",
|
|
"cap.release()\n",
|
|
"cap.release()\n",
|