This provides a simple interface, via OpenCV, for configuring and utilizing a camera device, using Python
camera was created for the CogWorks 2017 summer program, in the Beaver Works Summer Institute at MIT. It was developed by Ryan Soklaski, the lead instructor of CogWorks 2017.
We will need to install OpenCV with the Python bindings so that we can access laptop cameras via our Python code. Follow the instructions for Windows and Mac.
Requires: Anaconda + Python 3.{2-6}, numpy, python-opencv
conda install -c conda-forge opencvInstalling python-opencv:
- Download the appropriate (32-bit or 64-bit) wheel package from
- Navigate to the directory containing this .whl file, and simply run
pip install <whl-file-name>
If you have multiple conda envs, make sure that the appropriate one is active when running the pip-install!
Requires: Anaconda + Python 3 (Tested on 3.{5-6}) + Homebrew
Installing opencv3:
-
Ensure that Anaconda's python executable is the one being used (i.e.
which pythonshould yield/path/to/anaconda/bin/python) -
Update homebrew with
brew update -
Install homebrew-science formulae with
brew tap homebrew/science- This command allows opencv3 to be installed through homebrew
-
Install opencv3 with homebrew using
brew install opencv3 --with-python3 --without-python --without-numpy --with-ffmpeg -
Create a symbolic link of the compiled python binding to your Anaconda's site-package with the following commands for Python 3.5 and 3.6. These paths need to be adjusted if you are installing opencv-python to a conda env other than root.
- (Python 3.5)
ln -s /usr/local/opt/opencv3/lib/python3.5/site-packages/cv2.cpython-35m-darwin.so /path/to/anaconda/lib/python3.5/site-packages/cv2.so - (Python 3.6)
ln -s /usr/local/opt/opencv3/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so /path/to/anaconda/lib/python3.6/site-packages/cv2.so
- (Python 3.5)
Clone Camera, navigate to the resulting directory, and run
python setup.py developPlease see the camera tutorial notebookin this repo for details of how to configure your camera.
%matplotlib notebook
from camera import take_picture
import matplotlib.pyplot as plt
img_array = take_picture()
fig,ax = plt.subplots()
ax.imshow(img_array)