Category Archives: tech

I crushed the GSVideo problematic frame error!

Nerd warning: This post really belongs on my nerd blog VXLabs.com, but as this blog has a rich tradition of popular processing posts, I’m posting it here.

Debugging

GSVideo is a brilliant library that you can use in processing to capture live video, on Windows, Linux and OSX, and it’s a huge improvement over the built-in capturing support. Unfortunately, a number of us (including some of the 123 students we got to build augmented reality music instruments this September) have been running into a problematic frame error crash that meant captures didn’t last for very long before unceremoniously crashing the application. Error info and stack trace look something like the following (edited for brevity):

# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c342eee, pid=1564, tid=2052
#
# JRE version: 6.0_20-b02
# Java VM: Java HotSpot(TM) Client VM (16.3-b01 mixed mode windows-x86 )
# Problematic frame:
# C  [msvcr71.dll+0x2eee]
#
---------------  T H R E A D  ---------------

Current thread (0x18db7000):  JavaThread "Animation Thread" [_thread_in_native, id=2052, stack(0x1bfd0000,0x1c020000)]

Stack: [0x1bfd0000,0x1c020000],  sp=0x1c01f8a0,  free space=13e1c01f384k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [msvcr71.dll+0x2eee]
C  1
J  java.nio.Bits.copyToByteArray(JLjava/lang/Object;JJ)V
j  java.nio.DirectIntBufferU.get([III)Ljava/nio/IntBuffer;+126
j  java.nio.IntBuffer.get([I)Ljava/nio/IntBuffer;+5
j  codeanticode.gsvideo.GSCapture.read()V+24
j  CathetAR.draw()V+22

Read more about it on this forum thread.

In any case, today I spent some hours I don’t really have and finally managed to crush it. Turns out, and some of you will probably not be surprised, that it was a threading problem. The capture event handler invokeEvent() and the read() call were being interleaved, and the buffer they were using is also not thread-safe. Doh. Some synchronization here and there, and an extra capture buffer, now I can’t get it to crash anymore.

Get the patch here, and a patched GSVideo.jar here. Both of these are for the GSVideo 20110203 test version. If you can’t patch and build it yourself, just copy my GSVideo.jar over the GSVideo.jar in your unpacked GSVideo 20110203 plugin directory (sub-directory library). Update: See below, GSVideo 0.8 has been released and now contains my patch. Rather get the 0.8 download!

Leave me a comment if this helps!

Update on 2011-03-06

Andres Colubri, author of GSVideo, has refined and integrated my patch. The next GSVideo release (0.8 and newer) should have this fix.

Update on 2011-03-15

Andres has just released GSVideo 0.8, which integrates my fix and many other improvements. Go read his 0.8 release post!

Processing + NyARToolkit + multiple marker tracking

For various reasons, I need to do multiple marker tracking in processing with NyARToolkit.  However, with the default NyAR4psg layer between these two, multiple marker tracking is downright hard, and when you get it working, it’s not quite what you expect. After a few days of Java hacking, during which I was very pleasantly surprised with eclipse, I am now pleased to present to you my modifications to the NyAR4psg that makes multiple marker tracking easy! See here:

Standard hiro and kanji markers tracked simultaneously with augmented reality sphere and cube. In the background some artwork by my daughter!

I’ve called it NyARMultiBoard, and you can use it instead of the default NyARBoard if you want to track multiple markers.

Download a ZIP file containing everything (source code, jar files) from this directory.  If you unpack this into your processing sketchbook/libraries directory, it should work out of the box.  It’s a drop-in replacement for NyAR4psg, so you don’t need to have that installed as well. There is an example to get you started in NyAR2/example/NyARMultiTest.  Note: This uses the GSVideo capturing stack as I explain here, you should easily be able to change it back to processing defaults (just change GSCapture to Capture).

Please let me know in the comments if this works (or doesn’t) for you!

I made this screencast to demonstrate the multiple marker tracking, assisted by TNR:

YouTube Preview Image

I also made this really bad screencast (old webcam + night time lighting + transcoding):

YouTube Preview Image

If you’re really into the details

I’ve just added two new classes NyARMultiBoard and NyARMultiBoardMarker to the default NyAR4psg distribution. Very importantly, NyARToolkit itself needs to be patched with one extra method in NyARDetectMarker, see the NyARMultiBoard comments.

Update on 20110304

I’ve fixed the problematic frame bug in gsvideo that many of you have been running into. See this post.

Update on 20110305

I’ve updated NyAR2 so it works with the P3D renderer as well, which is often faster for blitting the webcam image onto the display. The updated zip file is named NyAR2-20110305.zip, and it can be downloaded from the usual directory. My changes are based on NyAR4psg 0.3.0 and NyARToolkit 2.5.2.

Facebook Like, Share and Retweet buttons in your WordPress

Hey man, I’m really busy at the moment, but it took me unnecessarily long to get those really hip facebook like, facebook share and retweet buttons everywhere on my blog, so I thought I’d try and save you some time by dropping a quick note on how I did it.

Adding the Facebook Like button functionality wasted the most time, because there are far too many plugins and howtos that claim to work and don’t quite. I ended up using the Like plugin (official wordpress page and plugin website), because it has the best documentation that includes details on all the ways in which things can go wrong, and there are many.  I’m using the IFRAME option, also because that seems to work most of the time.  I had a hard time finding this plugin in the built-in directory, so I downloaded and installed it manually.

For the facebook share button, I use the Facebook Share (New) Button plugin, and for the retweet button, I’m using the Topsy Retweet Button plugin.  I installed both of them from the built-in “Plugins | Add New” directory.

In all three cases, I made use of the plugin options to have the buttons placed all over my blog, instead of manually editing the theme.

I hope that you enjoy your shiny buttons, and I look forward to seeing you for the next Weekly Head Voices!

P.S. feel free to click on my buttons, right below this post.

An Even More Ultimate Boot Disk!

In this short howto, I show you how to combine the Ultimate Boot CD (UBCD) with both Knoppix 6.2.1 and Ubuntu 10.04 onto a single USB stick to create An Even More Ultimate Boot Disk (EMUBD)!

UBCD is a bootable CD image that’s fantastic if you’re trying to save grandma’s PC from a certain death, as it contains a number of different bootable utilities for testing memory, testing and low-level repair of hard drives, partition repair, antivirus and so forth. It even contains Parted Magic, a compact linux distribution for fixing partitions, amongst others.

Knoppix is the swiss knife of live linux distributions, and Ubuntu 10.04 is probably the slickest distribution out there at the moment. Both of these can be ran live from your USB disc, so they don’t have to touch your hard drive.  However, both of them are also able to install to your hard disc if you so choose.

To me it seemed logical to combine all three of these elements onto the single USB flash drive that I carry on my keychain, as I know of many grandmas with broken PCs…

Let’s go!

  1. make sure the single FAT32 partition on your USB stick is bootable (use command ‘a’ in linux fdisk) and large enough (you’ll need just a bit less than 2G).
  2. mount your flash drive on a directory, henceforth referred to as FLASH_MNT.
  3. copy all files from the ubcd5 iso into a directory, henceforth referred to as CUSTOM_UBCD5.
  4. mount the ubuntu 10.04 i386 iso on a directory, henceforth referred to as LUCID_MNT
  5. mount the knoppix iso on a directory, henceforth referred to as KNOPPIX_MNT.
  6. copy necessary boot files from the ubuntu ISO to UBCD:
    mkdir CUSTOM_UBCD5/ubcd/custom/lucid
    cp LUCID_MNT/casper/vmlinuz LUCID_MNT/casper/initrd.lz CUSTOM_UBCD5/ubcd/custom/lucid
    
  7. copy ubuntu-10.04-desktop-i386.iso to your flash disk:
    mkdir /FLASH_MNT/isos
    cp ubuntu-10.04-desktop-386.iso /FLASH_MNT/isos/
    
  8. Knoppix can’t be booted directly from its iso like Ubuntu, so we have to copy the actual contents of the ISO to your flash:
    cp -r KNOPPIX_MNT/KNOPPIX to FLASH_MNT/
    cp -r KNOPPIX_MNT/boot/isolinux to FLASH_MNT/KNOPPIX/isolinux
    
  9. replace FLASH_MNT/KNOPPIX/isolinux/isolinux.cfg with the isolinux.cfg at the bottom of this post. (It’s the same file, except that “KERNEL linux” is replaced with “KERNEL /KNOPPIX/isolinux/linux”, “initrd=minirt.gz” with “initrd=/KNOPPIX/isolinux/minirt.gz”, F1, F2, F3 and DISPLAY paths all fixed, e.g. “F2 f2″ becomes “F2 /KNOPPIX/f2″ and finally all instances of “quiet” removed)
  10. Now replace CUSTOM_UBCD5/ubcd/custom/custom.cfg with the custom.cfg at the bottom of this post.
  11. copy all files from CUSTOM_UBCD5 to your usb flash disk:
    cp -r CUSTOM_UBCD5/* FLASH_MNT/
    
  12. Finally, make the whole thing bootable with the following invocation. It’s really important that you replace /dev/sdX1 with the correct device for your flash disk. To see what this is, type “mount” and see the device associated with your FLASH_MNT.
    cd FLASH_MNT
    sudo ./ubcd/tools/linux/ubcd2usb/syslinux -s -d /boot/syslinux /dev/sdX1
    

You’re done. You should now be able to boot with your EMUBD! Knoppix and Ubuntu can be found under “User defined”.

Here are those files that you’ll need. First FLASH_MNT/KNOPPIX/isolinux/isolinux.cfg:

DEFAULT knoppix
APPEND ramdisk_size=100000 lang=en vt.default_utf8=0 apm=power-off vga=0x311 initrd=/KNOPPIX/isolinux/minirt.gz nomce loglevel=0 tz=localtime
TIMEOUT 50
# TOTALTIMEOUT 20
# KBDMAP german.kbd
PROMPT 1
F1 /KNOPPIX/isolinux/boot.msg
F2 /KNOPPIX/isolinux/f2
F3 /KNOPPIX/isolinux/f3
DISPLAY /KNOPPIX/isolinux/boot.msg
LABEL adriane
KERNEL /KNOPPIX/isolinux/linux
APPEND ramdisk_size=100000 lang=en vt.default_utf8=0 apm=power-off vga=0x311 initrd=/KNOPPIX/isolinux/minirt.gz nomce loglevel=0 tz=localtime adriane
LABEL knoppix
KERNEL /KNOPPIX/isolinux/linux
APPEND ramdisk_size=100000 lang=en vt.default_utf8=0 apm=power-off vga=791 initrd=/KNOPPIX/isolinux/minirt.gz nomce loglevel=0 tz=localtime
LABEL fb1024x768
KERNEL /KNOPPIX/isolinux/linux
APPEND ramdisk_size=100000 lang=en vt.default_utf8=0 apm=power-off vga=791 xmodule=fbdev initrd=/KNOPPIX/isolinux/minirt.gz nomce loglevel=0 tz=localtime
LABEL fb1280x1024
KERNEL /KNOPPIX/isolinux/linux
APPEND ramdisk_size=100000 lang=en vt.default_utf8=0 apm=power-off vga=794 xmodule=fbdev initrd=/KNOPPIX/isolinux/minirt.gz nomce loglevel=0 tz=localtime
LABEL fb800x600
KERNEL /KNOPPIX/isolinux/linux
APPEND ramdisk_size=100000 lang=en vt.default_utf8=0 apm=power-off vga=788 xmodule=fbdev initrd=/KNOPPIX/isolinux/minirt.gz nomce loglevel=0 tz=localtime
LABEL memtest
KERNEL memtest
APPEND foo
LABEL dos
KERNEL memdisk
APPEND initrd=balder.img
LABEL failsafe
KERNEL /KNOPPIX/isolinux/linux
APPEND ramdisk_size=100000 lang=en vt.default_utf8=0 vga=normal atapicd nosound noapic nolapic noacpi pnpbios=off acpi=off nofstab noscsi nodma noapm nousb nopcmcia nofirewire noagp nomce nonetwork nodhcp xmodule=vesa initrd=/KNOPPIX/isolinux/minirt.gz

… and then CUSTOM_UBCD5/ubcd/custom/custom.cfg:

MENU INCLUDE /ubcd/menus/syslinux/defaults.cfg
UI /boot/syslinux/menu.c32

# option to be able to go back to the main menu
LABEL -
MENU LABEL ..
COM32 /boot/syslinux/menu.c32
APPEND /ubcd/menus/syslinux/main.cfg

# this clause will boot directly from the ubuntu iso
LABEL ubuntulive
MENU LABEL Ubuntu 10.04 i386 Desktop LIVE
LINUX /ubcd/custom/lucid/vmlinuz
INITRD /ubcd/custom/lucid/initrd.lz
APPEND boot=casper iso-scan/filename=/isos/ubuntu-10.04-desktop-i386.iso --

# and this one will chain into the knoppix boot setup
LABEL knoppix
MENU LABEL Knoppix 6.2.1 LIVE
CONFIG /KNOPPIX/isolinux/isolinux.cfg

Post scriptum

  • The instructions in this post are derived from the UBCD linux documentation and various forum posts.  Credits to their authors!
  • If you don’t want Knoppix on your bootable USB and you have a Windows computer, you could also use MultiBootISOS to add multiple ISOs to a USB boot disk.

Weekly Head Voices #15: Auto-tune my cloud.

In this 15th edition of my weekly head voices, I move yet more of my life into the cloud, discover (years after everyone else) the delightful auto-tune internet meme and finally go all backyard-psychological whilst staring into the distance, obviously defocused, and waxing on about the purpose of this weblog.

Before continuing, you might like to watch this clip explaining why you shall build a turtle fence (I’ll get back to the clip after my dropbox story):

YouTube Preview Image

Last week I completed, you guessed it, 21 GTD tasks spread over 10 projects. Once again, one more task than last week. The question is thus not if, but when I’m going to have to disappoint you. :)  Worth mentioning on the miscellany front is that I’ve started playing around with processing, a fantastic little system for programming visual effects and interaction, in preparation for a new first year course. My goal is to get the students irrevocably addicted to the coolness that is media processing! I’ll keep you up to date…

In a previous post, I was quite enthusiastic about Dropbox and its possibilities for collaboration. As some of you might now, I really like this whole living-in-the-cloud idea: I use GMail, Google Calendar and Google Documents quite extensively and I’m even paying for extra storage with the big G.  So, during the past week, I decided to bite the bullet some more and to move 12G more of my data right into the cloud, courtesy of a 50G Dropbox Pro account.  Up to now, I had a ridiculously complex synchronisation system keeping various subsets of my data up to date between a netbook, a laptop and three different servers. At the core of this system was unison, a brilliant multi-way open source synchronisation tool. In spite of this system mostly working, its complexity and the starkly contrasting It-Just-Works nature of Dropbox convinced me to give the simple solution a shot.

So far I can only report that I remain impressed: At one stage I manually copied a complete dropbox (12Gigs) from one already synced machine to a fresh target machine and started the Dropbox software on the target. It politely asked:

There is already a folder in your home folder called Dropbox. Do you want to merge all the existing files in that folder into your dropbox?

After clicking on the “HELL YEAH!” button (that’s how it felt, ok), the software went on indexing for a minute or two and then correctly claimed that everything was nicely synced up. Very much understated robustness, kudos to the developers. I’m going to test-drive this whole business for one month, and then let you know whether it’s going to be  a permanent fixture in my cloud-home.

Still wondering why you should build a turtle fence? Well, you can blame the Auto-Tune internet meme. Very shortly, auto-tune is an audio effect that corrects one voice to be perfectly in tune with backing music. In other words, a vocalist who can’t sing is in fact no problem at all, computer will fix! Initially it was used quite sparingly and its application was even sometimes kept a secret, until artists such as Cher and especially T-Pain turned it into an art form, in fact exaggerating the effect until it gave a decidedly unsubtle robotic voice effect. The effect has become so famous that it now gets to call itself an internet meme and is often parodied.  The turtle clip above is just one of a whole series (auto-tune the news, see them all!). In the clip below, internet scientists *ahem*, including the well-known Professor Weird Al Yankovic, take an in-depth look at this phenomenon:

YouTube Preview Image

Finally, back to the purpose of this weblog… Good blogs all seem to have some central theme, such as photography, environmental issues, science or pokemon. I seem to recall that I’d also seen this in more than one “how to become an A-list blogger” guides.  I don’t find it hard to believe that this is very important.  However, this blog has never had a central theme, it’s always been me blabbing about the various things that I find blab-worthy.  I’ve never been able to come up with something better, and it was definitely not for lack of trying.  The Weekly Head Voices, by focusing my blabbing into slightly more coherent episodes, have finally helped me to come to a conclusion.  Besides acting as a creative outlet, sitting down every week and carefully externalising a specific subset of my experiences with the express purpose of having it read by a small number of people, is an important ritual during which I am forced to distance myself from the events of the week, and to self-reflect.  By formally concluding the previous period in this way, one has the mental room to manoeuvre in preparation for the next. If you by any chance find any of it entertaining, or at least you just can’t look away, it’s a win-win situation!

In other words: Theme-schmeme! The voices in my head will continue to be the many and various topics of this weblog, thank you very much. :)

Have a great week kids!