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.

Matlab Compiler tbb.dll errors

Even with a fresh install of Windows 7 x64 and Matlab R2013b, I was getting tbb.dll related errors after compiling M-scripts using Matlab Compiler deploytool. The exe would compile, but upon running it would issue various tbb.dll errors.

This problem happened across multiple PCs. To fix this problem, I followed this process:

1) download latest Intel Threaded Building Blocks from:

extract them to c:\tbb
2) install Intel TBB by starting Command Prompt with Run As Adminstrator, then type
cd c:\tbb\tbb*\bin
tbbvars intel64 all

Then I went back to Matlab deploytool and recompiled.

Safely ejecting USB flash thumb drives in Linux

In Windows, we use safely remove devices when removing USB drives, as typical inexpensive flash drives write data quite slowly (less than 5MB/sec). This is because by default, Windows “write caches”, that is, Windows uses RAM to temporarily store files — making the copy/write operation appear done faster than it actually is.

In Linux, the write caching is used as well, and you should verify writing to a flash drive is completed by typing sync at Terminal and waiting for the $ prompt to come back up. You can watch the writing progress with iotop or the graphical indicator-multiload. You then click the Eject icon next to the flash drive’s name in your File Manager (in Ubuntu, it’s nautilus)

Consider that your flash drive only writes at say 2MB/sec. to be “safe”. Then, writing a 1GB file will take 1000/2=500 seconds = 8.3 minutes!

Which format to use for sharing USB flash thumb drives and USB HDD

I have found that EXFAT is the most convenient format for sharing files between Mac/Linux/Windows/Android.
EXFAT is supported from Windows XP through Windows 8.1 and beyond.
EXFAT is supported on Mac OS X from 10.6.3 and newer [1].
EXFAT is supported on Linux from CentOS 5 and Ubuntu 10.04 and newer.
EXFAT is supported from at least Android 4 onward.

NTFS is not writeable on Mac OS X by default, in Mavericks I have read that one must either go into Terminal and use Homebrew or edit your /etc/fstab and make some manual changes. I.e. something not easy to do at a conference or casual meeting quickly. NTFS is NOT supported on Android.

FAT32 is also readable by Windows/Mac/Linux/Android, but is limited to 4GB file size. Sometimes I share large raw/compressed data files that are larger than this, especially if using a USB HDD. With many USB HDDs over 2TB, you would have to break up your HDD into multiple partitions for FAT32 — quite inconvenient. You could use FAT32 for a small USB flash drive. Note, I have found that when using a USB flash thumb drive to plug into a printer to “USB Direct Print” that single partition FAT32 is supported, but not EXFAT. So I keep a small USB drive formatted to FAT32 for this purpose.

In my opinion, EXFAT is the best choice for universal support on USB HDD
For USB flash thumb drives, I format most to EXFAT–keeping a small flash drive formatted to FAT32 in case I need to quickly use the USB port on a USB direct print printer (Dell, Brother, etc.)

Important note: As I was reminded in the comments by Bob Foss, there are a variety of devices such as in-car entertainment, printers, Agilent test equipment, etc. that require only a single FAT32 partition. Since USB drives are so small and inexpensive, I keep an old USB flash drive formatted to FAT32 for these special cases.

Also, for SD cards, many devices expect still expect FAT32, so you may need to use FAT32 for SD cards just for compatibility reasons.


Stop MATLAB high CPU usage on Idle (Windows/Mac/Linux)

For at least Matlab R2013a and R2013b, you may find that after opening the Matlab Help Browser (and even after closing just the Help Browser while keeping Matlab itself open), that Matlab uses 100% of one CPU core at about 25% duty cycle.

You can try pasting this command into Matlab (it will persist, you do NOT have to put this in startup.m).


Then restart Matlab, you should see the CPU is not hanging at 100% after closing the Help Browser. Matlab will remember this setting.

However, this simpler Help Browser is not as graphically nice as the default Java Help Browser; sometimes clickable links are broken in the help files. You can thus revert back to the default Java Help Browser by pasting into Matlab command line:


and restart Matlab. Matlab will remember this setting too.

Xrdp on Ubuntu 12.04 through 14.04

Note: ubuntu-2d was REMOVED from Ubuntu 12.10 onward. So for Xrdp on Ubuntu 12.10 and newer, observe the specific steps below.

For cases where you have to allow RDP users from Mac/Windows to connect to a linux machine, and for whatever reason you can’t install TightVNC on the Mac/Windows user PCs, you can try Xrdp, which creates an RDP server on port 3389 on the Linux PC.

sudo apt-get install xrdp

Now on ubuntu 12.04 we need to edit a configuration file

nano ~/.xsession

copy and paste [for Ubuntu 12.04 only]:

gnome-session --session=ubuntu-2d

[for Ubuntu 12.10 through 14.04]: copy and paste into ~/.xsession

exec openbox

then exit nano

and in Ubuntu 12.10 through 14.04, type:
sudo apt-get install openbox
then type

sudo service xrdp restart

Note: For Ubuntu 12.10 and Ubuntu 13.04 ONLY, you can also use gnome-session-fallback. But gnome-session-fallback is BROKEN in Ubuntu 13.10. You can also use XFCE in any of these Ubuntu versions.

Note, if you use Openbox, you’ll just see a grey screen upon typing password at Xrdp login. Right-click mouse to open menu.

Note: If you just get a gray screen, trying editing
to just have


if [ -r /etc/default/locale ]; then
. /etc/default/locale

exec openbox

ImageJ-Win64 won’t start

Upon freshly downloading and extracting FIJI for Windows 7 64-bit, I found that typing at the Command Prompt:


would do nothing.

I found that typing (once)
ImageJ-Win64 –cp jars/javac.jar

fixed the problem–thereafter, I could just click on ImageJ-Win64 to start.


One-double-click SSH Tunnel with RDP (from Linux to a remote Windows PC)

Assuming you have a remotely located Windows PC, and you’re using a Linux PC, and there is a port-forwarding router on the remote end, say:
remote router WAN (internet-facing) address:
remote router forwarded port: 4321

remote PC RDP port: 3389
remote PC LAN address:

remote PC SSH login: MyPC
remote PC name: MyPCname
I have made the numbers above up–you must set them to be for your PC situation!

Type in Terminal:
ssh -f -p 4321 -L 3390: MyPC@ sleep 1;
xfreerdp -t 3390 -u MyPC -d MyPCname -x m --sec nla

You should then be asked for your SSH password (you must have an SSH server such as CopSSH running on the remote Windows PC).

You can create a simple double-click to connect BASH script file by creating a plain text file named something like “ConnectMyPC” and put into this file:

ssh -f -p 4321 -L 3390: MyPC@ sleep 1;
xfreerdp -t 3390 -u MyPC -d MyPCname -x m --sec nla

Then save and type chmod 755 ConnectMyPC to make your BASH script executable, and double-click to connect in one easy step.

Installing FFMPEG and FFPLAY on Windows

To install FFMPEG and FFPLAY on Windows (XP through 7) follow these steps:

1) download FFMPEG from
2) unzip the folders inside to c:\ffmpeg
3) set your PATH to include c:\ffmpeg\bin

You can now use the powerful FFMPEG from the Windows Command Prompt.

Note: if you don’t already have 7zip installed on Windows, download 7zip from:

One-click RDP over SSH tunnel with Windows machines at both ends

While you can use PuTTY for SSH tunneling and then manually launch Remote Desktop Connection, I find it more efficient to simply reuse techniques so convenient from Linux. Here is how to do one-click RDP over SSH tunnel using Windows on both ends using Cygwin.

Suppose your remote SSH server on the remote Windows PC is on port 22 at WAN address, and it has a firewall blocked (as it should be!) RDP server at Port 3389 (the standard Windows Remote Desktop port). You have a user “joe” setup on the remote PC for remote access. Then, do:

  1. In Cygwin, type nano ~/myRDP and type:
    ssh -f -p 22 -L 3391:localhost:3389 joe@ sleep 2;
    mstsc /v:localhost:3391
  2. Exit and save, then type chmod +x ~/myRDP
  3. In Windows, create a shortcut to:
    C:\cygwin\bin\mintty.exe -e /bin/bash -l -c '$HOME/myRDP'

Double clicking that windows shortcut should launch cygwin, make the SSH connection (you’ll be prompted for SSH password, or use a public key file) and then make the RDP connection over the SSH tunnel (where you will be prompted for the Windows password).


1) You can’t specify most Remote Desktop parameters on the MSTSC command line, but if you need to do this, you can save a .RDP profile file (here, we saved it to
) from Remote Desktop Connection and then load that specific profile by:

mstsc "c:\MyRDP\MyFirstPC.RDP" /v:localhost:3391

Note, we used Port 3391 for the local forwarding because Windows 7 uses Port 3390 for something else.

On Windows 7, you may find you have to specify an RDP file. Here’s an RDP template you can try–save this as the MyFirstPC.RDP file, after changing the 2nd to last line JoePC\Joe to match your Domain\Username:

screen mode id:i:1
use multimon:i:0
session bpp:i:24
connection type:i:1
disable wallpaper:i:0
allow font smoothing:i:0
allow desktop composition:i:0
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:1
disable cursor setting:i:0
full address:s:localhost:3391
autoreconnection enabled:i:1
authentication level:i:0
prompt for credentials:i:0
negotiate security layer:i:1
alternate shell:s:
shell working directory:s:
use redirection server name:i:0

Thanks to Chhavi Goenka for testing this on Windows 7 on a live system.