Linux (6) OpenCV (4) Deep Learning (3) MATLAB (3) Mac OS X (3) Windows (2) C# (1) Node JS (1)

2013年6月25日 星期二

Convert File Glob to Regular Expression

The tips of converting file glob to regular expression are extracted from following website
Thanks to Jan Borsodi for the good tutorial. The tips are as follows:

For people who have some knowledge with wildcards (also known as file globs or file globbing), I'll give a brief explanation on how to convert them to regular expressions. After reading this article, you probably have seen the similarities with wildcards. For instance:

matches any text which end with .jpg. You can also specify brackets with characters, as in:

matches any text which ends in .cpp or .hpp. Altogether very similar to regular expressions.
The * means match zero or more of anything in wildcards. As we learned, we do this is regular expression with the punctuation mark and the * quantifier. This gives:

Also remember to convert any punctuation marks from wildcards to be backslashified.
The ? means match any character but do match something. This is exactly what the punctuation mark does.
Square brackets can be used untouched since they have the same meaning going from wildcards to regular expressions.
These leaves us with:
  • Replace any * characters with .*
  • Replace any ? characters with .
  • Leave square brackets as they are.
  • Replace any characters which are metacharacters with a backslashified version.

would be converted to:


would convert to:

or alternatively:

2013年6月9日 星期日

Using MATLAB Local Parallel Computing Toolbox

MATLAB Parallel Computing Toolbox can automatically divide tasks of for loop and run multiple instances simultaneously. Just use the "parfor" keyword and MATLAB will do the rest work. However, we usually need to configure MATLAB to make this feature work. The configuration is located at:
Menu -> Parallel -> Manage Configurations...

The common two issues that prevent running parallel computing are:
1. Unresolved hostname
=> MATLAB use TCP/IP and hostname to connect to clients. Please make sure your hostname mapping is set in /etc/hosts. Use command !hostname in MATLAB to check your hostname

2. Data Location is not set
=> To set data exchange location, open Menu -> Parallel -> Manage Configurations..., select the local profile,  Property... -> set "Folder where Job data is stored (DataLocation)" to [your location] (e.g. /tmp/MATLAB)

Other problems include no license of Parallel Computing Toolbox, check it by typing command:
license checkout Distrib_Computing_Toolbox
Or problem of local mpiexec
If you are using R2010a or newer, you may experience issues with the new local mpiexec implementation. In that case, try the following command to disable this feature:
distcomp.feature( 'LocalUseMpiexec', false )
Refer to for more information

Moreover, MAC user may encounter the error below:
The class distcomp.typechecker has no property or method named 'getDefaultValue'.

Error in distcomp.configsection (line 50)
    obj.PropValue{i} = distcomp.typechecker.getDefaultValue(obj.Types{i});

This is a known bug of MATLAB with Java version. Please refer to MATLAB official site:

Bug 919688


Parallel Computing Toolbox code fails with Java Virtual Machine update 1.6.0_39


Running any Parallel Computing Toolbox code using a Java Virtual Machine (JVM) version of 1.6.0_39 or later might cause a NullPointerException to be thrown by the JVM. For example:....

Follow the instruction on MATLAB, download the JVM and update it. Be careful not to overwrite other files under MATLAB folder!

2013年6月7日 星期五

Running OpenCV Program on Linux Cluster without Installing Libraries

Computer Vision programs usually require heavy computing power and are time-consuming. Therefore, we usually need to run our programs on a larger clusters of machines. The problem is, we don't have the administration privilege to install libraries. This article discusses ways of running OpenCV program without installing libraries.

Supposed we have installed OpenCV on our local linux, the first thought is using a script to copying all shared libraries dependencies from local machine to target clusters. I used the great script "cpld" developed by Hemanth Copying shared library dependencies | Experiments on GNU/Linux:

# Author : Hemanth.HM
# Email : hemanth[dot]hm[at]gmail[dot]com
# License : GNU GPLv3

function useage()
    cat << EOU
Useage: bash $0 <path to the binary> <path to copy the dependencies>
exit 1

#Validate the inputs
[[ $# < 2 ]] && useage

#Check if the paths are vaild
[[ ! -e $1 ]] && echo "Not a vaild input $1" && exit 1
[[ -d $2 ]] || echo "No such directory $2 creating..."&& mkdir -p "$2"

#Get the library dependencies
echo "Collecting the shared library dependencies for $1..."
deps=$(ldd $1 | awk 'BEGIN{ORS=" "}$1\
~/^\//{print $1}$3~/^\//{print $3}'\
 | sed 's/,$/\n/')
echo "Copying the dependencies to $2"

#Copy the deps
for dep in $deps
    echo "Copying $dep to $2"
    cp "$dep" "$2"

echo "Done!"

However, the method will fail if the gcc complier on local machine is different from target cluster. Another method is to compile libraries on target machine.

1. Download OpenCV source code
2. Under the source folder, execute "mkdir release"
3. Run "cmake -D CMAKE_BUILD_TYPE=release .."
4. Verify the FFMPEG is suppored
5. make

P.S. In terms of FFMPEG, I used default libraries installed in the cluster to compile OpenCV. But while executing my program, I encounter the error of missing library "". In order to sovle this issue, I have to re-compile FFMPEG-1.2, which required to link to additional libraries "libavfiler" and "libswresample" in the Makefile. I copied all FFMPEG libraries to the execution folder. Although OpenCV is compiled with older FFMPEG version (.so.52), it works fine with newer FFMPEG libraries (.so.54).

After complied, all the libraries will be put in opencv/release/lib. But since we don't have root right to install files, the include header files are not ready. To handle this issue, we need to copy our local OpenCV headers to the target machine:

scp -r /usr/lcoal/opencv
scp -r /usr/lcoal/opencv2

To compile a program, we just need to assign the include and link paths of OpenCV in make file.

Finally, we need to export the library for dynamically link at runtime. (new FFMPEG are copied to current folder, so "." is also added to the PATH)
export LD_LIBRARY_PATH=.:opencv-2.4.5/release/lib