Importing old OpenCV modules from OpenCV 2 in Python on Windows

Some of the legacy modules like Horn Schunck Optical Flow in OpenCV 2.4 are located in “cv” instead of “cv2″ .

To be cross-platform compatible, instead of doing

import cv,cv2

I suggest doing

import cv2
from cv2 import cv


Further, in Windows running Anaconda Python 2.7 (or whatever Python 2.7 you choose), OpenCV is not installable through conda.

To install OpenCV 2.4 for Python on Windows, do the following:

  1. From

    download OpenCV for Windows, version 2.4

  2. Extract to a directory of your choice, let’s say c:\opencv and copy the file

If you’re using CPython instead of Anaconda, copy to that directory instead.

Writing multipage TIFF with Python

You can use the freeimage plugin to SciPy as one method to write multipage TIFF images. You can also use tifffile or libtiff.

On Windows you might see the error:
RuntimeError: Could not find a FreeImage library

On Linux you might see the error:
freeimage had a problem: Could not find a FreeImage library in any of…

To fix this on Windows, download the FreeImge DLL from

Then extract the file
to the following directory (assuming you’re using Anaconda Python)

To fix this on Linux, type
sudo apt-get install libfreeimage3

Example code (assuming you have image stored in C-ordered 3-D array images):

from import freeimage_plugin as freeimg

or try this example test code


OpenCV cv.CalcOpticalFlowHS Horn-Schunck smoothness lambda parameter

More details to come, but I was comparing the performance of OpenCV to Matlab Computer Vision Toolbox for the dense estimates of optical flow given by the Horn Schunck algorithm. I was getting a very different result with OpenCV vs. Matlab for the Optical Flow Estimation. It seemed that OpenCV was washing out fine details in the optical flow. After carefully comparing Matlab Computer Vision and OpenCV outputs for Horn Schunck optical flow, I found that the default lambda/smoothness parameter of 1.0 for cv.CalcOpticalFlowHS is not the same as what Matlab calls 1.0.

I need to quantify this further, but for now I found that in OpenCV cv.CalcOpticalFlowHS setting lambda=0.001 gives results that are much more like Matlab–I can see the fine details. This is just a rough guess, if I have time I’ll quantify it in my forthcoming article on segmenting terabtyes of aurora borealis video in an hour!

PySide in Anaconda3

When using Matplotlib in Anaconda 3, and if you’re trying to use QT4Agg, you may get the error message
ImportError: No module named 'PySide'

To fix this, you can try (using your Anaconda3 pip)
pip install pyside
This will take several minutes and may require the prerequisites:

sudo apt-get install libxext-dev python-qt4 qt4-dev-tools build-essential



Miniconda Python on Intel Edison

Since the Intel Edison is a 32-bit CPU, we use the 32-bit version. But first, we need to install GNU Tar because Busybox tar doesn’t have some needed tar options, and it’s not compatible with GNU tar archives (!).

Since original writing, AlexT_Intel has put GNU tar in the opkg repository, so you can just do:

opkg install tar
opkg install bash

tar xvf tar*
cd tar*

The ./configure takes almost a minute on a desktop PC, so it will take a few minutes on the Edison. Likewise for the make step.
You’ll see the tar binary at ~/tar-1.28/src/tar
nano ~/.bashrc
add the line
alias tar='/home/root/tar-1.28/src/tar'

Now let’s get Miniconda


Finally run the install (all typed on one line)

BASH_ENV=/home/root/.bashrc bash

when install is complete, since Edison normally uses Dash shell, we create

echo "export PATH=/home/root/miniconda/bin:$PATH" >> ~/.profile

Then reopening a Terminal window to the Edison and type

Python 2.7.9 |Continuum Analytics, Inc.| (default, Dec 15 2014, 10:34:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2

And you can use all the very easy to use conda goodness of Miniconda to trivially install packages like Numpy, SciPy, OpenCV, etc. on the Intel Edison.

conda update conda
conda install numpy scipy astropy


Travis CI SciPy requirements.txt

I have noticed that currently Travis CI has SciPy 0.9.0. That’s fine for most of my things (except savgol_filter which is new in 0.14.0)

When I put SciPy>=0.9.0 in requirements.txt, even though Travis gets SciPy 0.9.0 from
apt-get install scipy
Travis still tries to pip install SciPy latest version.

It’s been suggested by many to just use MiniConda with some boilerplate in .travis.yml. You can see what I’m currently using