Equations

Wednesday, July 10, 2013

Network Mounting of Directories For Ubuntu Machines

In this post, I'm going to discuss how to mount a directory from a master machine in a network of machines running Ubuntu. 

1. In the master station, edit the hosts file (/etc/hosts) to include IP addresses of all hosts. Here is an example for 4 machines:
127.0.0.1     localhost
192.168.1.50  m0
192.168.1.51  m1
192.168.1.52  m2
192.168.1.53  m3
I will assume that the master machine is m0. So, in each of the slave machines you also need to include the master IP address,
127.0.0.1     localhost
192.168.1.50  m0
2. Install NFS (Network File System) which allows the sharing and sync of folders between a set of network connected hosts. You can do this by installing the nfs-server on the master machine,
sudo apt-get install nfs-server
And install the nfs-client on each slave machine,
sudo apt-get install nfs-client
3. Now, we will start the mounting process. You first should locate the folder you need to mount. Let's say that the folder is /helala. We first will ask the master machine to share this folder by editing the /etc/exports file and adding the following line
/helala *(rw,sync)
You can do this in one statement by issuing,
sudo echo  /mirror *(rw,sync) >> /etc/exports
4. We will go now to the other hosts and finalize the mounting by first creating a folder to host the remote shared directory (in my case /helala). Then, we can issue the following command on each slave host,
sudo mount m0:/helala /helala
Unfortunately, we need to run this command on every boot. A better approach is to edit the /etc/fstab file and add the following line,
m0:/helala     /helala    nfs
In this way, the mount will be performed on every boot. Now, you can issue the following command to remount all shared directories,
sudo mount -a

Friday, June 7, 2013

Frame Capture Issue with OpenCV under Windows 7

A serious issue that arises when using OpenCV under windows 7 is the use of opencv_highgui or openCVFrameGrabber for capturing frames from WebCam or a video file. In this case, OpenCv uses video for windows codec which isn’t always working well under windows 7.


A solution to this problem is to use VideoInputFrameGrabber for WebCam which uses DirectShow and FFmpegFrameGrabber with a version of FFmpeg codec to read video files.

Javacv code sample:

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(new File(video_file_path));
try {
    grabber.start();
    for (int i = 0; i < 10; i++) {
        opencv_core.IplImage currentFrame = grabber.grab();
        ......
    }
} catch (Exception ex) {
    .....
}

Building a DLL With JNI support under Windows (32bit versus 64bit)

Java provides us with JNI to link java projects with C++ code. I’m using Netbeans IDE which has a good C++ support With Cygwin tools and I needed to use a C++ implementation for multilabel graphcut optimization in one of my java projects.
The problem I encountered is the different settings needed to build a DLL library under 32bit and 64bit environments. Here is the settings I used to build under the different environments,

JNI:
Include: $jdk_home$/include ; $jdk_home$/include/win32

Win32bit:
I used the g++ compiler with the following options
-mno-cygwin -Wl,—add-stdcall-alias -shared -m32

Win64bit:
I used the x86_64-w64-mingw32-g++ compiler with the following options
-w -mno-cygwin -static -shared