Thursday, November 18, 2010

Intel OpenCV Open Source Computer Vision Software

Face Tracking, Motion Tracking, OpenCV - Free Computer Vision Library



Was looking into how to do face tracking and possibly motion tracking. With face tracking I was hoping I could find a way to track facial expressions, ie the eyebrow position, mouth position, as is done with many CG characters nowadays. OpenCV is an open library by Intel that allows you to carry out various computer vision tasks. Facial tracking is one of the demos that comes with OpenCV.

How OpenCV's facial tracking works can be described in great detail


You can find out more about how OpenCV's facial tracking works here : http://www.cognotics.com/opencv/servo_2007_series/part_3/sidebar.html


Check out Intel's OpenCV library - computer vision


Check out the a wiki for more detailed information here : http://opencv.willowgarage.com/wiki/

Face Tracking OpenCV - Cool demo on youtube


http://www.youtube.com/watch?v=AUhFjG-WSPE

Tuesday, November 16, 2010

Mozilla's HTML 5 Audio API Draft

HTML 5 - Mozilla's Draft for the Audio API


Defining an Enhanced API for Audio (Draft Recommendation) by Mozilla



Was looking into writing a html 5 script that can generate tones given a frequency (ie 440 hz for 'A') . Alas, it seems out of my reach for now as Mozillas Audio Writing API does not appear to work in my version of firefox. Cmon people lets get moving!

https://wiki.mozilla.org/Audio_Data_API

Cool Examples



Toy Piano
Javascript text-to-speech engine

Let me know if any of these work for you, because they don' work for me :(

Monday, November 8, 2010

Site Launch

Sheet-Music-Tabs.com



New site has been launched. Lets watch the SEO value... lots of competition out there



Sheet-Music-Tabs.com

New! Speed of Flow tabs by The Rodeo Carburettor

Monday, September 13, 2010

Load Balancing Web Servers using ldirectord

Web Server Load Balancing



Summary



Using ldirectord to set up load balancing in apache, using debian linux as my distro, should also work on ubuntu or any other distro for that matter (bsd, red hat, etc). See below for links to the documentation. This setup is done using ldirectord's masq mode, which is basically ip masquerading function using iptables.

Let's Begin



Im just going to take a few mins to explain my load balancing set up. What we have is 1 router, the default gateway, connected to the internet, and also connecting to an internal network. Standard set up really.

What we want to do is set up load balancing with 2 (or more, our case we have 4) apache servers.

First step - download ldirectord



http://horms.net/projects/ldirectord/ (ldirectord) is a daemon that will route traffic to a certain host based on whatever load balancing algorithm you choose. Some examples of algorithms are round robin, where it selects the next host every time, or least connections, route to the host with the least number of open connections. There are a few other options that are covered in the ldirectord documentation (man page) and specifically for the algorithms is in the IPVSADM man page under -s (scheduler) located here (http://linux.die.net/man/8/ipvsadm)

Note that ldirectord is now a sub project of linux HA project called Heartbeat. It is available as a part of that package available here http://www.linux-ha.org/wiki/Main_Page

The reason for this is ldirectord is used as a part of that package. It is also useable on its own as I will show you.

Ldirectord set up



What we have to do next is set up ldirectord after we manage to get it compiled. Here is an example of a /etc/ha.d/ldirectord.cf:


# Global Directives
checktimeout=10
checkinterval=2
autoreload=no
logfile="local0"
quiescent=yes

# Virtual Server for HTTP
virtual=10.1.1.10:80
real=10.1.1.21:80 masq
real=10.1.1.22:80 masq
real=10.1.1.23:80 masq
real=10.1.1.12:80 masq
service=http
request="ldirectord.html"
receive="Test Page"
scheduler=wlc
protocol=tcp
checktype=negotiate


As you can see, we have set this ldirectord program up on the host located at 10.1.1.10 which is a physical machine. Using Heartbeat you can set up a virtual IP address and have 2 or more machines take over that address when the main one goes down, but that is for another article. We are strictly focusing on setting up ldirectord here.

Setting up the load balanced machines



On each of the load balanced machines (10.1.1.21, 22, 23, and 12) we need to set the default gateway to 10.1.1.10 (the ip address of the load balancer) Please adjust accordingly to your network. This can be done using the following command on debian linux and most other types

route add default gw 10.1.1.10


Next we have set up our ldirectord to check each machine by loading the page "ldirectord.html" shown above. So really it will be trying to access the page http://10.1.1.21/ldirectord.html. We have set up a regular expression as well above saying "Test Page". As long as this url returns this string somewhere, the host will be considered "up" by ldirectord. After we have set everything up, it should be good to go.

Running ldirectord



Please make sure your config file is in /etc/ha.d/ldirectord.cf because the script will be searching there for it. Next run ldirectord by typing

/usr/bin/perl /usr/sbin/ldirectord start


You should make a init.d script for this. After you have run ldirectord, typing

ipvsadm -L


should give you some information on its status.


s5:/etc/ha.d# ipvsadm -L
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP s5.np.local:www wlc
-> s4.np.local:www Masq 1 6 2245
-> s7.np.local:www Masq 1 5 2275
-> s3.np.local:www Masq 1 4 2563
-> s9.np.local:www Masq 1 6 2074


Here it shows that all hosts are up (their "Weight" is each 1) and have active connections running to them.

Setting up external routing



Now just have your router point all web traffic to 10.1.1.10:80 and you should have full load balancing. Note there are other problems such as how are you going to make sure they are all synchronized. You can use tools such as rsync, or use NFS to mount a share that contains all your files on each of the slave servers (our approach). The NFS approach seems to work nicely, however if you are hosting webservers for file transfers it may become a bottleneck so make sure your internet network is fast (1000 mbit) and tweaking NFS settings to your liking.

Thank you, your comments are welcome!

Parsing Wavefront .obj using Python

Wavefront OBJ File Format Parsing in Python






I thought I would share some simple parsing information about the wavefront .OBJ file format using python. The thing I like about this format is that it is stored in plain text, and easy to use if you are writing simple 3D game engines, or just 3D modeling programs.

You can use this parser to load wavefront files using python, and possibly to view the wavefront obj file.

Overview of the wavefront .OBJ file format



Based on http://en.wikipedia.org/wiki/Obj

Basically, our approach is to go line by line through the file. If the line starts with a "v", we are dealing with a vertex. If the line starts with a "vt" then we are dealing with a texture coordinate (u, v, optionally w). "n" means normal. "f" means its a face index. These are a bit special, but not too difficult to grasp. Our exported models that are from blender will all have normal vectors, and texture coordinates (make sure you specify the texture coordinates in blender or there will be none). The "f" lines will look like this:


f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3


where "v1" is the vertex array index, "vt1" is the texture coordinate index, and "vn1" is the normals array index. This particular face is a triangle. I recommend storing triangles, and quads in 2 different arrays. They can both reference your vertex/texture coordinate/normals array.

Very important note before we begin



The index format in the .OBJ Wavefront file format is 1 based, not 0 based. Thus, we should subtract 1 from the actual number in order to get a 0 based index, and make it compatible with python lists or any array type.


#do the loading of the obj file
def load_obj(filename) :
V = [] #vertex
T = [] #texcoords
N = [] #normals
F = [] #face indexies

fh = open(filename)
for line in fh :
if line[0] == '#' : continue

line = line.strip().split(' ')
if line[0] == 'v' : #vertex
V.append(line[1:])
elif line[0] == 'vt' : #tex-coord
T.append(line[1:])
elif line[0] == 'vn' : #normal vector
N.append(line[1:])
elif line[0] == 'f' : #face
face = line[1:]
if len(face) != 4 :
print line
#raise Exception('not a quad!')
continue
for i in range(0, len(face)) :
face[i] = face[i].split('/')
# OBJ indexies are 1 based not 0 based hence the -1
# convert indexies to integer
for j in range(0, len(face[i])) : face[i][j] = int(face[i][j]) - 1
F.append(face)

return V, T, N, F


Please not this program will give you string representations. You should loop through these arrays again and convert them to the proper format (int, float, etc).

Please leave your comments

Thursday, August 26, 2010

Compiling boost C++ development libraries in OSX

Compiling boost c++ libraries and development headers for Mac OSX



Hi Everyone,

So I am starting to play with OpenCL. And as you all know I do love python. I have been playing with pyOpenCL package for awhile and wanted to get it set up on my Mac using OSX.

It depends on an installation of Boost C++ Libraries http://www.boost.org/

first we set up a directory, and in a terminal we need to download the boost files:


wget http://downloads.sourceforge.net/project/boost/boost/1.44.0/boost_1_44_0.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F1.44.0%2F

bzip2 -d boost_1_44_0.tar.bz2

tar -xvf boost_1_44_0.tar

cd boost_1_44_0


Configuration and Compilation



Great now we have extracted it, lets attempt to configure, compile, and install this package. Since I have build many applications on my MacOSX, I already have lots of build tools/libraries installed (eg. gcc, xorg, wine).

I was able to compile by typing at the console:


sh bootstrap.sh

./bjam


And then I waited... Its a shame there is no configure and make so I could use "make -j 4" and utilize all 4 of my cores for compiling. Maybe bjam has that option, I am not sure and too lazy to look into the documentation. Also I believe that is a bit out of the scope of this post for now.

After waiting for it to finish, we install the libraries by typing


sudo ./bjam install


And then we wait some more...

Finally after it is installed we can continue to try and install pyOpenCL.

Note: openCL unfortunately is not supported on my mac (Mac OS X 10.5.8 Leopard) and no amount of wishing will make it so :( However hopefully you are able to install this package (pyOpenCL) using Linux or Windows, or even Snow Leopard. Good luck!

Thursday, July 29, 2010

Using Canvas in Firefox and Safari for Graphics in your Browser

Using the Canvas Tag


About the Canvas Tag



The canvas tag is a 2d "canvas" that can be used to draw various vector shapes. It has a fully integrated javascript API. It somewhat resembles the graphical aspects of flash. Since adobe and flash have taken some flack lately, we begin to wonder what is the future of web graphics programming APIs? Apple seems to be in a space where they want to drop support for flash. (See iPad discussions). A lot of people are behind this movement. Another example is android, which does support flash, however many people are reporting that performance is bad.

Why Not Use the Canvas Tag?



Well, we can't replace flash with canvas. Flash has many other aspects such as full networking libraries, native video playback, audio, etc. Some of these things are coming along as separate modules for each browser but since there is no unified front on these modules, it seems to be lagging behind in terms of features, and even being available in the first place.

Another problem is we are not seeing much support for canvas using internet explorer (one of the most widely used browsers at the moment). Firefox, Safari, Chrome and Opera all fully support it.

Personally I would like to see canvas more widely used. And I think market forces may give it a bit of a push in the near future.

Demonstration of using the canvas tag. Works in Firefox and Safari



Hi Everyone,

Today I am going to demonstrate the use of the canvas tag in order to output graphics. Here is our template we will use in order to get started. This is a short script that will draw a circle at coordinates 200, 200 with a radius of 50. Below that is this code at work. It should be drawing a large blue circle if its working properly.



<html>
<head>
<title>Canvas Test</title>

<script type="application/javascript">
var ctx = null;

function draw() {
//get our canvas element
var canvas = document.getElementById("canvas");
//create our context
ctx = canvas.getContext("2d");
//set out fill color, red = 0, green = 0, blue = 200, alpha = 0.5
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
//begin our arc
ctx.beginPath();
//draw an arc, starting at 200, 200. 50 radius, angle starts at 0, and continues to 360 degrees (a cicle), and uses counter clockwise (false)
ctx.arc(200, 200, 50, 0, (Math.PI/180)*360, false);
//end our path
ctx.closePath();
//fill in the result
ctx.fill();


}
</script>

</head>

<body onload="draw()">
<style>
canvas,
body {
margin: 0px;
padding: 0px;
}
canvas {
border: solid 1px;
}
</style>
<canvas width="800" height="600" id="canvas"></canvas>
</body>
</html>


Here is the example at work:



Please leave your comments below!