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.

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:

https://www.threadingbuildingblocks.org/download#stable-releases

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.

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
———–

ImageJ-Win64 won’t start

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

ImageJ-Win64.exe

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.

Reference:

https://groups.google.com/forum/?fromgroups=#!topic/fiji-users/1yNPbNM13l4

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: 1.2.3.4
remote router forwarded port: 4321

remote PC RDP port: 3389
remote PC LAN address: 192.168.1.10

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:192.168.1.10:3389 MyPC@1.2.3.4 sleep 1;
xfreerdp -t 3390 -u MyPC -d MyPCname -x m --sec nla 192.168.1.10

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:

#!/bin/bash
ssh -f -p 4321 -L 3390:192.168.1.10:3389 MyPC@1.2.3.4 sleep 1;
xfreerdp -t 3390 -u MyPC -d MyPCname -x m --sec nla 192.168.1.10

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, get the 64-bit “shared” version.
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

LabVIEW Shared Variables through Windows 7 Firewall

Getting the LabVIEW 2011 Shared Variable Server to work through Windows Firewall on Windows 7 x64 will require allowing the following programs to pass through the firewall:

C:\Windows\SysWOW64\lkads.exe
C:\Windows\SysWOW64\lktsrv.exe
c:\Program Files (x86)\National Instruments\Shared\Tagger\tagsrv.exe

Note: even when using LabVIEW 64-bit, the directory for tagsrv.exe is still under the x86 Program Files.
Note: For LabVIEW 32-bit, the lkads.exe and lktsrv.exe will be under c:\Windows\System32\

Also, you must allow the following ports through Windows Firewall:
TCP: 2343, 59110-59115
UDP: 2343, 6000-6010

For the TCP ports, you must open one port above 59110 per “per application,”–by opening 59110-59115, we assume that no more than 5 applications are running concurrently.