|
@@ -2,13 +2,13 @@
|
|
|
"cells": [
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 3,
|
|
|
+ "execution_count": 1,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
"import numpy as np\n",
|
|
|
"import threading\n",
|
|
|
- "import time, os\n",
|
|
|
+ "import time, os, json\n",
|
|
|
"import cv2\n",
|
|
|
"import matplotlib.pyplot as plt\n",
|
|
|
"import multiprocessing as mp\n",
|
|
@@ -29,6 +29,7 @@
|
|
|
" 'arena_x': 512,\n",
|
|
|
" 'arena_y': 384,\n",
|
|
|
" 'arena_radius': 350,\n",
|
|
|
+ " \"max_fps\": 50,\n",
|
|
|
" 'file_path': 'test_position_log.csv'\n",
|
|
|
" }\n",
|
|
|
" \n",
|
|
@@ -59,14 +60,21 @@
|
|
|
" print('Position tracker stopped')\n",
|
|
|
" \n",
|
|
|
" def update(self):\n",
|
|
|
+ " next_frame = time.time() + 1.0/self.cfg['max_fps']\n",
|
|
|
+ " \n",
|
|
|
" while not self.stopped:\n",
|
|
|
" frame = self.video_stream.read()\n",
|
|
|
" if frame is None:\n",
|
|
|
" time.sleep(0.05)\n",
|
|
|
" continue\n",
|
|
|
" \n",
|
|
|
+ " if time.time() < next_frame:\n",
|
|
|
+ " time.sleep(0.001)\n",
|
|
|
+ " continue\n",
|
|
|
+ " \n",
|
|
|
" self.count() # count FPS\n",
|
|
|
" self.detect_position(frame)\n",
|
|
|
+ " next_frame += 1.0/self.cfg['max_fps']\n",
|
|
|
"\n",
|
|
|
" if self.status.value == 2:\n",
|
|
|
" with open(self.cfg['file_path'], 'a') as f:\n",
|
|
@@ -110,14 +118,14 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 14,
|
|
|
+ "execution_count": 3,
|
|
|
"metadata": {},
|
|
|
"outputs": [
|
|
|
{
|
|
|
"name": "stdout",
|
|
|
"output_type": "stream",
|
|
|
"text": [
|
|
|
- "Webcam stream 960.0:720.0 at 20.00 FPS started\n",
|
|
|
+ "Webcam stream 1024.0:768.0 at 20.00 FPS started\n",
|
|
|
"Camera released\n",
|
|
|
"Position tracker stopped\n"
|
|
|
]
|
|
@@ -127,16 +135,19 @@
|
|
|
"#import nbimporter\n",
|
|
|
"#from camera import WebcamStream\n",
|
|
|
"\n",
|
|
|
+ "with open(os.path.join('..', 'settings_light.json')) as json_file:\n",
|
|
|
+ " cfg = json.load(json_file)\n",
|
|
|
+ "\n",
|
|
|
"# controller status: 1 - detecting, 2 - detecting + logging\n",
|
|
|
"status = mp.Value('i', 1)\n",
|
|
|
"\n",
|
|
|
"# let's use a webcam stream\n",
|
|
|
- "vs = WebcamStream(WebcamStream.default_cfg)\n",
|
|
|
+ "vs = WebcamStream(cfg['camera'])\n",
|
|
|
"vs.start() # stream runs in a separate thread\n",
|
|
|
"\n",
|
|
|
"# init controller\n",
|
|
|
- "pt_cfg = PositionTracker.default_cfg\n",
|
|
|
- "pt_cfg['background_file'] = os.path.join('..', 'assets', 'background.png')\n",
|
|
|
+ "pt_cfg = cfg['position']\n",
|
|
|
+ "pt_cfg['background_file'] = os.path.join('..', 'assets', 'background_light.png')\n",
|
|
|
"pt = PositionTracker(status, vs, pt_cfg)\n",
|
|
|
"pt.start()\n",
|
|
|
"\n",
|