Archive

Archive for the ‘tech’ Category

mencoder webcam floating point exception solution

October 23rd, 2009 Kyle Williams No comments

I’ve spent most of the afternoon trying to figure out how I could use MEncoder to record video and audio from my webcam and kept running into a “floating point exception” problem. In scouring the internet I realised that many people seem to be having the exact same problem. It turns out that the problem is due to a bug in MEncoder and is simply fixed by installing the latest version.

I use Kubuntu Jaunty so the problem for me lay in the version of Mencoder that comes packaged with it. To fix the problem all I did was follow these instruction for adding a thrid party repository for newer builds of MPlayer/MEncoder and then installed the latest MEncoder using apt-get.

sudo apt-get install mplayer mencoder

Thereafter I was able to capture video and audio from my webcam using the following command:

mencoder tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0:forceaudio:adevice=/dev/dsp -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o webcam.avi

Categories: (k)ubuntu, linux, open source, tech Tags:

boldproject: bold translator overview

October 2nd, 2009 Kyle Williams No comments

A few weeks ago I wrote a post which introduced the BOLD Project. Well, a lot has happened since then and this post gives an overview of the translation system which I am building.

BOLD Translator Overview

BOLD Translator Overview

The translator is split into three parts:

  1. The preprocessor
  2. The user input
  3. The matcher

The Preprocessor

The preprocessor is called as soon as an image is inserted into the repository. The preprocessor works by first segmenting the Bushman words in the dictionary. It does this by exploiting the known fact that every Bushman word on a page is underlined by a solid black line. Once the Bushman words have been segmented, specific features are extracted from them and these features are stored in inverted files. Once the features have been extracted then the orifinal image, the segmented words and the inverted files are all stored in the repository.

The User Input

The user who is accessing the Bleek & Lloyd notebooks uses a tool to select a specific word on a page which then becomes known as the key. The same features which were extracted from each word in the preprocessor are extracted from the key. These features along with the key image will be used later for matching.

The Matcher

The matcher starts by taking the features belonging to the key and finding images with the same features in the inverted files. For each feature match, the score of the image which matched increases. At the end of all the feature comparisons, the images with the highest scores are returned. At this stage there may be some images with the same or similar scores, so to resolve this clash the matcher performs a more intensive comparison between the key and the images with the highest score. Based on the result of this comparison, the most likely match is returned.

So that’s how the BOLD Translator works. Ultimately it is a framework which means that it will be designed such that anyone can adapt it and make use of it by plugging their own algorithms into each of the specific parts. In the next day or two I will blog about the actual work that has been done on the system up to now as well as show some of the results that the translator returns at this point.

boldproject: introducing the bold project

September 9th, 2009 Kyle Williams No comments

BOLD LogoThe BOLD (Bushman On-Line Dictionary) Project is an honours project being worked on by myself and two colleagues, Sanvir Manilal and Lebogang Molwantoa and is supervised by Dr. Suleman. Together we are creating an online visual dictionary based on about 40 000 scanned images of dictionary pages which form part of the Bleek & LLoyd Collection. The dictionary pages contain an English word and the bushman translation(s) of the word. The goal of the project is to create a useable on-line visual dictionary which researchers around the world can make use of to find out more about bushman culture and bushman language.

The project has been split into three separate parts:

Part 1: Archive Management – Lebogang Molwantoa

This part involves the setting up and building of the archive, including developing administrative tools for managing the repository.

Part 2: Searching and Browsing – Sanvir Manilal

This part involves the way in which end users interact with and make use of the dictionary.

Part 3: Image Based Translation – Kyle Williams

This part involves using the Bushman dictionary to translate Bushman words in the existing Bleek & Lloyd Collection on the fly.

I’ll make use of this blog to provide updates on how development is going, as well as to document techniques I develop – with the idea being that:

  1. I document them for my own use
  2. They’re out there for use by other people who may be working on similar projects.

Wish us luck!

A page from the bushman dictionary

A page from the bushman dictionary*

* This image is not available under the same CC license as the rest of this blog. For more information about this image please visit http://lloydbleekcollection.cs.uct.ac.za

netbeans jtable automatic expansion

November 1st, 2007 Kyle Williams 1 comment

HOWTO get a NetBeans JTable to automatically expand when it runs out of space. That is, add new rows whenever needed.

Step 1:
Create a normal JTable in NetBeans

Step 2:
Add a PropertyChangeEvent handler to the table via the inspector window.
Right click jTable1 -> Events -> PropertyChange -> propertyChange
This should take you to the source.

Step 3:
Add the following to the PropertyChangeEvent handler:

private void jTable1PropertyChange(java.beans.PropertyChangeEvent evt) {

int last = jTable1.getRowCount(); //count the number of rows already in the table

if (jTable1.getValueAt(last-1,0) == null){ //check if there’s anything in the first column of last row
//first column of last row is empty, so do nothing
}

else{ //last row was not empty

Object o[][] = new Object[jTable1.getRowCount()+1][jTable1.getColumnCount()]; //create a new 2D object with size the same as the table+1

for (int i = 0; i < jTable1.getRowCount(); i++){ //loop through the rows
for (int j = 0; j < jTable1.getColumnCount(); j++){ //loop through the columns
o[i][j] = jTable1.getValueAt(i,j); //populate the new Object with values from the table
}
}

for (int k = 0; k < jTable1.getColumnCount(); k++){
o[jTable1.getRowCount()][k] = null; //add a null row to the new object
}

//set the tables new model with “o” as the first parameter – o is the new object
jTable1.setModel(new javax.swing.table.DefaultTableModel(
o, new String [] {
“Firstname”, “Surname”, “Birthday”
}
)

//Create the rest of the table model – copied from generated code

{
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class
};

public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
}
}

And that’s it – your table should now automatically expand when necessary.
The same logic can be applied to deleting rows when they’re not needed.

Below is an complete program which shows automatic table expansion in action. It can be downloaded, compiled and executed independently.

Source: TableExpandGUI.java

Categories: programming, tech Tags:

fill mysql table with dates using java

November 1st, 2007 Kyle Williams No comments

I had the problem of needing to populate a MySQL table with dates between openingDate and closingDate, using Java and JDBC Connector/J.
Well, after a while I figured out how to do it and thought I’d share it with you.

Step 1: See how many dates will need to be entered

ResultSet rs = statement.executeQuery(”SELECT DATEDIFF(’2007-07-01′, ‘2006-07-01′);”);
rs.next();
int days = rs.getInt(1);

The MySQL DATEDIFF query calculates the value of date1 – date2, in this case (2007-07-01 – 2006-07-01) which evaluates to 365.
The days variable takes the value of the first column returned by the ResultSet object, which is the result of the DATEDIFF query.

Step 2: Insert the days into the database

for (int i = 0; i <= days; i++){
int j = statement.executeUpdate(”INSERT INTO MyTable VALUES (’2006-07-01′ + INTERVAL ” + i + ” DAY);”);
}

This statement will need to be customized to suit your table but essentially what it does is takes the first date specified, and add 1 day for each count in the day variable.

At the end you have a table filled with dates!

Categories: programming, tech Tags: