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

    http://opencv.org/downloads.html

    download OpenCV for Windows, version 2.4

  2. Extract to a directory of your choice, let’s say c:\opencv and copy the file
    c:\opencv\build\python\2.7\x64\cv2.pyd
    to
    c:\Anaconda\Lib\site-packages\

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

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.

Summary:
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.

References:
[1] https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/fsck_exfat.8.html

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).

com.mathworks.mlwidgets.html.HtmlComponentFactory.setDefaultType('HTMLRENDERER');

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:

com.mathworks.mlwidgets.html.HtmlComponentFactory.setDefaultType('HTMLPANEL');

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
/etc/xrdp/startwm.sh
to just have

----------
#!/bin/sh

if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG LANGUAGE
fi

exec openbox
———–

Windows 8.1 on Virtualbox 4.2

You will need to have at least VirtualBox version 4.2.16, or you will get error like:
Windows 8.1 preview installation fails: Your PC needs to restart | Please hold down the power button | Error Code 0x000000C4

And when setting up the VM, be sure to select Windows 8.1, not just Windows 8 !

Also, I recommend to select a “Fixed”, NOT “dynamic” hard drive for Windows 8, as the disk performance is quite slow when using Dynamic sized HDD. (this is also true for Windows XP & Windows 7, but moreso for Windows 8 )