{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "BGR_COLOR = {\n",
    "    'red': (0,0,255),\n",
    "    'green': (127,255,0),\n",
    "    'blue': (255,127,0),\n",
    "    'yellow': (0,127,255),\n",
    "    'black': (0,0,0),\n",
    "    'white': (255,255,255)\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "class FPSTimes:\n",
    "    \n",
    "    def __init__(self, buffer=100):\n",
    "        self.frame_times = []\n",
    "        self.buffer = buffer\n",
    "        \n",
    "    def count(self):\n",
    "        self.frame_times.append(time.time())\n",
    "        if len(self.frame_times) > self.buffer:\n",
    "            self.frame_times.pop(0)\n",
    "        \n",
    "    def get_time_diffs(self):\n",
    "        return np.diff(np.array(self.frame_times))\n",
    "        \n",
    "    def get_avg_fps(self):\n",
    "        diffs = self.get_time_diffs()\n",
    "        if len(diffs) > 0:\n",
    "            return (1.0/diffs).mean()\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
