This project is read-only.

Has anyone used Touchless with XNA?

Dec 12, 2008 at 2:41 AM
Hi all,
I'm planning to make a simple XNA game which uses touchless to allow a player to move their character.
Using the tutorial video, I've managed to get touchless working in a simple C# application. I'm having a bit of trouble getting started with XNA, however.
In C#, The webcam output is displayed in a Windows Form PictureBox, which allows the user to click it to set a marker. Obviously tthis Form object doesn't exist when using XNA, so I have tried to work around it.

Basically, I have saved a default_marker.bmp image which shows a marker. As I know the location of the marker in that image, I attempted to create a new marker using the following:


Line 57 - bitmap =

new Bitmap(@"C:\Project\Prototypes\Sprite_Movement_Prototype\Sprite_Movement_Prototype\Content\default_marker.bmp");


Line 58 - marker = _touch.AddMarker(

"marker",bitmap, new System.Drawing.Point(35 58), 10);



Unfortunately when doing so, the following exception is thrown:


System.AccessViolationException was unhandled
  Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
       at TouchlessLib.TouchlessMgr.GetMarkerAppearance(Bitmap image, Point center, Single radius, HSV binCounts)
       at TouchlessLib.TouchlessMgr.GetMarkerAppearance(Bitmap image, Point center, Single radius)
       at TouchlessLib.TouchlessMgr.AddMarker(String name, Bitmap image, Point center, Single radius)
       at Sprite_Movement_Prototype.Game1.Initialize() in C:\Project\Prototypes\Sprite_Movement_Prototype\Sprite_Movement_Prototype\Game1.cs:line 58
       at Microsoft.Xna.Framework.Game.Run()
       at Sprite_Movement_Prototype.Program.Main(String[] args) in C:\Project\Prototypes\Sprite_Movement_Prototype\Sprite_Movement_Prototype\Program.cs:line 14


It seems as if it doesn't like me referring directly to a Bitmap. Does anyone have any idea what could be throwing this exception? Does anyone know what I can use as an alternative to Form PictureBox in xna?

If anyone could point me in the right direction I'd be extremely greatful - currently have a splitting headache over this one!

Dec 12, 2008 at 5:45 AM
Jonathan, thank you very much for reporting this bug, I'm sorry that it caused you frustration.
I've just submitted a fix (change #26831). Grab updated binaries and/or source from our source repository.
Alternately, workaround this bug by using a 32bpp Rgb/Argb image. I suspect default_marker.bmp is 24bppRgb.

Since you expressed interest in adding run-time marker adding, here's some tips on XNA:
If you'd like to draw Touchless' images you can make Texture2Ds and draw some sprites:
You'll likely find more concise tutorials by searching online; and maybe someone else can offer more info.
If you're stuck on getting that to work, I have some old code I can update and send you that uses XNA.

Keep us updated on your game!
- Mike
Dec 12, 2008 at 3:02 PM
Hi Mike,
First of all - wow, thanks for the unbelievably quick reply and fix, very much appreciated.
You're right - the bmp I was using was 24bit. Upon converting it to 32bit, it now works without error and I can see that the xna project is picking up the movement of the marker. Brilliant!

Next step is to get the webcam feed to appear in game. I'll keep you posted :).

Thanks again,
Dec 13, 2008 at 12:58 AM
Hi all,
Thought you might be interested in my latest XNA/Touchless video: .
This project is really fun to work on. The main thing I need to do is some better lighting in my room so that the markers show up better!
Jan 14, 2010 at 9:43 PM

Hey guys, do either of you have any source code for implementing touchless and xna? I'm starting to experiment with computer vision in general. I really like this touchless library so far. Very cool stuff. I imagine I could have a lot of fun if I could get it running within xna. Anything you can send my way would be helpful. Thanks!