{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center>\n",
    "    <tr>\n",
    "    <td><img src=\"ontario-tech-univ-logo.png\" width=\"25%\"></img></td>\n",
    "    </tr>\n",
    "</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# OpenCV + Python setup \n",
    "\n",
    "Faisal Qureshi   \n",
    "Professor    \n",
    "Faculty of Science    \n",
    "Ontario Tech University    \n",
    "Oshawa ON Canada    \n",
    "http://vclab.science.ontariotechu.ca"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Copyright information\n",
    "\n",
    "&copy; Faisal Qureshi"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## License\n",
    "\n",
    "<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\"><img alt=\"Creative Commons Licence\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc/4.0/88x31.png\" /></a><br />This work is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\">Creative Commons Attribution-NonCommercial 4.0 International License</a>."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Outline\n",
    "\n",
    "- Python OpenCV programming environmentt\n",
    "- Image loading and display\n",
    "- Movie loading and display"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Python\n",
    "\n",
    "It is now possible to use Python for rapid computer vision system development and experimentation in lieu of a software package, such as Matlab.  You will need to install a number of python scientific packages - Numpy, Scipy, Matplotlib, Image, Notebook - plus rely upon OpenCV python bindings to use Python for computur vision system development.  It is easier to setup your system to use Python for computer vision than it sounds."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data\n",
    "\n",
    "You can find sample images and videos [here](data/)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Installation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Linux (Preferred)\n",
    "\n",
    "The following steps assumes that you are using Ubuntu linux distribution.  To see if you have Python3 installed, use the following command:\n",
    "\n",
    "#### Setting up Python3 and pip\n",
    "\n",
    "~~~bash\n",
    "$ python3 --version\n",
    "~~~\n",
    "\n",
    "If Python3 is not found, you can install it as follows:\n",
    "\n",
    "~~~bash\n",
    "$ sudo apt-get update\n",
    "$ sudo apt-get install python3\n",
    "~~~\n",
    "\n",
    "Next you will need pip3 to install the packages needed for this course.  You can see if pip3 is already installed by using the following command:\n",
    "\n",
    "~~~bash\n",
    "$ command -v pip3\n",
    "~~~\n",
    "\n",
    "If pip3 is not installed, you can install it using the following command:\n",
    "\n",
    "~~~bash\n",
    "$ sudo apt-get install python3-pip\n",
    "~~~\n",
    "\n",
    "In any case, it is a good idea to upgrade pip3 to the latest version.  This can be done using the following command:\n",
    "\n",
    "~~~bash\n",
    "$ python3 -m pip install --upgrade pip\n",
    "~~~\n",
    "\n",
    "#### Installing Python packages\n",
    "\n",
    "Now that pip3 is installed, you need to install the packages needed for this course.  You can do so by using the `requirements.txt` file available [here](data/requirements.txt).  You will use the following command to install the packages:\n",
    "\n",
    "~~~bash\n",
    "$ pip3 install -r requirements.txt\n",
    "~~~\n",
    "\n",
    "You are set.\n",
    "\n",
    "##### Problem installing from `requirements.txt`\n",
    "\n",
    "If you have trouble installing packages from `requirements.txt` file, you can always install packages one by one.  For example, the following command will install `numpy`\n",
    "\n",
    "~~~bash\n",
    "$ pip3 install numpy\n",
    "~~~\n",
    "\n",
    "##### Aside\n",
    "\n",
    "It is always a good idea to install Python packages in a separate virtual environment.  Check out these [Python developments notes](https://github.com/faisalqureshi/python-dev-notes) for more details."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Windows (if you must)\n",
    "\n",
    "Your best bet is to use Anaconda Python Distribution [https://www.anaconda.com](https://www.anaconda.com).  Follow the instructions provided [here](https://conda.io/projects/conda/en/latest/user-guide/index.html) to set up the compute environment as needed."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OSX (if you must)\n",
    "\n",
    "I prefer to use [Homebrew](https://brew.sh/) package manager for OSX.  I use homebrew to install Python3 and pip3.  Once these are installed, use pip3 to install the packages that you need to set up the compute environment."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tasks\n",
    "\n",
    "Assuming that your python+opencv installation completed without any errors, test your installation by completing the exercises in the following Jupyter notebook.\n",
    "\n",
    "1. Create a folder `lab0`\n",
    "2. Copy `00-setup-workbook.ipynb` to this folder \n",
    "3. Within this folder run `jupter lab`.  At this point a browser window should open up pointing to http://localhost:8888/lab URL.\n",
    "4. Complete the exercises in `00-setup-workbook.ipynb` notebook.\n",
    "5. Save the notebook as an HTML and submit."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Other useful software packages"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SimpleCV\n",
    "\n",
    "You may also want to look at [http://simplecv.org/](http://simplecv.org/).  Although it is quite limited."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### C/C++ with OpenCV and VLFeat\n",
    "\n",
    "A time will come when you will find that your programs are too slow.  You will be amazed how large images and videos actually are.  These are many orders of magnitude larger than text files.  At that time Python, Matlab or Octave will not serve your purpose.  You will have to rely upon something more efficient, such as C/C++, for example.  In order to use C/C++ for computer vision system development, you will need to rely upon existing computer vision and image processing libraries, such as [OpenCV](http://opencv.org/) or [VLFeat](http://www.vlfeat.org/).  It is best if you set up your system to use one of these libraries.  This will especially be useful for your course project. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center>\n",
    "    <tr>\n",
    "    <td><img src=\"ontario-tech-univ-logo.png\" width=\"25%\"></img></td>\n",
    "    </tr>\n",
    "</center>"
   ]
  },
  {
   "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.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
