How to: Convert an OpenCV cv::Mat to an OpenGL texture

I’m working on using OpenCV to get Kinect sensor data via OpenNI, and needed a way to get a matrix (cv::Mat) into an OpenGL texture – so I wrote a function to do just that – woo! Apologies in advance for the terrible juggling ;-)

The function used to perform the sensor data to texture conversion is:

You can then use the above function like this:

There’s one very important issue to watch out for when using OpenCV and OpenNI together which I’ve commented in the code, but I’ll place here as well as it can be a real deal breaker:

There appears to be a threading issue with the OpenCV grab() function where if you try to grab the device before it’s ready to provide the next frame it takes up to 2 seconds to provide the frame, which it might do for a little while before crashing the XnSensorServer process & then you can’t get any more frames without restarting the application. This results in horrible, stuttery framerates and garbled sensor data.

I’ve found that this can be worked around by playing an mp3 in the background. No, really. I’m guessing the threading of the mp3 player introduces some kind of latency which prevents the grab() function being called too soon. Try it if you don’t believe me!

So just be aware that if you’re using a Kinect you have to be careful with the grab() function… The source code used to create the above video is provided in full after the jump, if you’re interested.

Cheers!

Continue reading How to: Convert an OpenCV cv::Mat to an OpenGL texture

How To: Convert VirtualPC .vhd hard drives to VirtualBox .vdi hard drives (or vice-versa)

Don’t bother – VirtualBox now natively supports .vhd drives – how handy is that? =D

But if you really wanted to, just use:

This will place the .vdi version of your drive in your current users VirtualBox folder, which is: ~/.VirtualBox

Relatedly, to go the other way (.vdi to .vhd) you could use:

Note: For this to work, you must not have the drive attached to any virtual machine, so if you already have it connected to a virtual machine, detach it first, mkay?

How To: Convert .WBFS Image Files to .ISO Images

Update: You can convert compressed ISO images (.ciso files) using this method, too…

If you need to translate a Wii DVD image from the newer .WBFS format (which has lovely sparce-file support) to an old-school .ISO image, well you can jolly well do so with Wii Backup Manager! Now, WBM is a really useful program so congrats to the author (xzxero) – but it uses non-standard GUI elements in that it uses what looks like the category list as a second main-menu, and this makes it a little non-intuitive to use. But in fairness to the author, the download page has a tutorial (which I didn’t find until after completing this post!). Still, it’s easy enough once you’ve figured that out. The entire conversion process goes like this:

1.) Grab yourself a copy of Wii Backup Manager. Version v0.3.5 beta 1 is the most recent version available at the time of writing, and although it’s Win32 only, it works fine in VirtualBox…

2.) Extract and launch it

Wii Backup Manager

3.) From the Files tab, click on what looks like the Add category title, select Files and go pick a .WBFS image from the navigation dialogue box

Wii Backup Manager - Add Files

4.) Still in the Files tab, tick the checkbox to the left of your .wbfs image, and then click on what looks like the Transfer category title and select ISO..

Wii Backup Manager - Transfer Files

5.) Pick where you want the converted .ISO file to be created and click the [OK] button

Wii Backup Manager - Place ISO

That’s it – job done! Transfer your ISO to your WBFS formatted USB drive and launch it as you normally would via USBLoaderGX or whatever your poison is… :)
Flattr this

How To: Easily Convert FLAC audio to MP3s in Linux

I grabbed a bunch of FLAC files the other day, and as nice as they sound, I don’t think ~30-40MB per track is acceptable, so I did a bit of research and stumbled across this great post on LinuxTutorialBlog.

Turns out there’s a dead simple GUI based tool called SoundConverter – which really is as simple as pointing it at a directory and configuring your transcoding preferences (mp3, ogg, file-naming etc). A swift sudo apt-get install soundcoverter and a couple of clicks later and the job’s done.

SoundConverter1SoundConverter2

If you really want a bash method, there’s a bunch of scripts and links in tfa, such as this one by Octavio Ruiz :

I’ve modded the LAME_OPTS line in the above script to use the -q 0 switch in lame (so it uses the highest quality algorithm it can), and changed the order of when the ${LAME_OPTS) options are passed to lame, which results in them actually being honoured. Which is nice. Should you have any specific encoding goals, you can always browse through the lame switches and mod it to your hearts content.

Sweet like chocolate =D

Note: To run the above script, just copy & paste into a file, maybe flac2mp3.sh or something, then chmod +x flac2mp3.sh to make it executable and run it on a folder like flac2mp3.sh MyFolderOfFLACFiles.