Category: Python

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 […]

Python GNU Find capability

I found myself wanting a recursive pattern search in Python like GNU Find. I made a simple implementation using os.walk and glob. https://github.com/scienceopen/hist-utils/blob/master/walktree.py It may be possible to add more features like min/max depth of recursion, just ask me if you’d like something more.

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 […]

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   […]

Python findpeaks

If you’re looking for a Python function that works like Matlab’s “findpeaks” checkout SciPy argrelmax. If you want to do a comparison in the same code, you can call Octave findpeaks using Oct2Py, or use the Matlab Python API in Matlab R2014b

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 […]

Python logging module versions to disk

I run Python massively in parallel with GNU Parallel across numerous remote PCs. I want to have the version numbers of the Python modules I’m using logged to disk. Here’s how I do so for Python 2.7 and 3.4

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 […]

Matplotlib ValueError on LogNorm plots

I was getting the error ValueError: Data has no positive values, and therefore can not be log-scaled. The issue is that I was setting vmin=0 in my pcolormesh() plot. By setting vmin=1 or some small positive value, your plots will work with norm=LogNorm() as expected.

Speed of Matlab vs. Python Numpy Numba

Here is a comparison on my Intel i7-2600 Sandy Bridge (3 year old) desktop PC. Python 3.4.2, Anaconda 2.1, iPython 2.2.0, Numpy 1.8.2 with Intel MKL import numpy as np A = np.matrix(np.random.randn(5000,5000)) B = np.matrix(np.random.randn(5000,5000)) %timeit A*B 1 loops, best of 3: 2.51 s per loop Matlab R2014b, also with Intel MKL A = […]