Welcome to the gaming social with XNA 3.0 CTP
07 May 08 10:45 PM | Coding4Fun | 3 Comments   

zune2-071003-1[1]Want to develop games for your Zune?  The XNA Game Studio 3.0 Community Technical Preview has been released

Dave Weller talks about a few hit points to pay attention to.

  1. You must use a Visual Studio 2008 SKU.  You don't need to uninstall Visual Studio 2005, but you have to have 2008 installed to use XNA 3.0
  2. The CTP currently does not support xbox 360 game development.  Only Zune and Windows.
  3. The CTP doesn't work with 64-bit machines ... yet.

Here is a direct link to XNA 3.0 CTP goodness.

Filed under:
Maker Faire 2008 – This weekend!
01 May 08 12:09 PM | Coding4Fun | 0 Comments   

300X250[1]Do you Make?  I do.  You should too.

As always, we’re attending Maker Faire.  This year we’re showing off some neat technology and if you’re in the Bay Area, I highly suggest coming down.  The Coding4Fun team will be down there and would love to hang out with you.

We have some awesome hardware software mash-ups we’ll be showing off this year and will be posting on the site later on.  Myself and Dan Fernandez will be doing some video coverage for Channel 8 and Channel 9 on MSDN.  And I believe some of the On10 team will be there too!

Scrape that screen with LINQ
29 April 08 03:27 PM | Coding4Fun | 2 Comments   

        Beth Massi has done something I know some of you C4F readers have been asking for.  Beth developed a quick and easy way to query a web site with LINQ to XML.  One of the commenter pointed out also you can do a HTML to XHTML conversion with this tool.

The trick to doing this is loading the HTML into an XElement, from there you strip out the unsupported XML entities, THEN LINQ the HTML to get the data you wanted.

Beth, the 15 minutes this took you just saved the Internet days of work on what I’d be would be a far more complex solution.

Filed under:
Teaching blog software new tricks
28 April 08 07:50 PM | Coding4Fun | 2 Comments   

wlw-cats[1] I'm a massive fan of Microsoft Live Writer when it comes to writing blogs.  Why you might ask?  Because it works with tons of blog engines.  The MSDN blogs are done with Community Server while others have personal blogs that range from SubText, WordPress, DasBlog, BlogEngine.NET and countless others.  So when I do blogging on my own blog and here, it pays to have a tool that takes care of uploading, images, formatting, spell checking, ....

Tim Heuer is a fan of SubText and Live Writer, so much so he altered SubText to get them to play better.  Tim did awesome updates to make SubText actually make it act more like WordPress when it comes to Live Writer.

Tim added in slugging and the ability to add in new categories while posting.  FYI:  A Slug is when the URI is different than the Title.  Most blog engines will make the title some part of the URI.  Tim didn't want this.

Filed under:
My robot can totally beat up your robot
25 April 08 01:54 PM | Coding4Fun | 1 Comments   

clip_image001

Microsoft launched a new contest called RoboChamp which is a simulated robotics competition. 

By using Robotics Developer Studio 2008, you have the ability to write code or use an xbox 360 controller.

If you need some help getting started, RoboChamps has a detailed instructions area.

More information:
Website – www.RoboChamps.com 
Channel 9 video – http://channel9.msdn.com/Showpost.aspx?postid=399952 
.NET Rocks Podcast – http://perseus.franklins.net/dotnetrocks_0336_marc_mercuri.wma
On10.net video – http://www.on10.net/blogs/tina/Robo-Champs-My-robot-is-bigger-then-your-robot/

Filed under:
LINQ, then what happened?
24 April 08 11:55 AM | Coding4Fun | 4 Comments   

linq[1] Kevin Hoffman sent in an email regarding a flippin sweet project on CodePlex called CLINQ.  It stands for continuous LINQ and is a .Net 3.5 extention.  As changes occur in the source of your query, the result set is continuously re-evaluated to maintain consistency and accuracy. It was designed specifically to allow you to do declarative queries that auto-update for WPF binding in rich GUIs.

The project is at http://www.codeplex.com/clinq

Filed under:
FFmpeg to transcode
16 April 08 03:13 PM | Coding4Fun | 1 Comments   

TarMonsterMorph-med[1]

Ever have a video file that you want to play in Silverlight or Flash but couldn't get it to play?  Fear not!  Arinhere on Code Project has done a release showing just how to do transcoding using FFMPEG in VB.Net.  Another individual made this work in c# too!

Filed under:
Webcam Based Laser Tracking for Human-Computer Interaction
10 April 08 05:47 PM | Coding4Fun | 11 Comments   
  In this article, we will put together a program which will allow us to move the mouse cursor on our computers with a laser pointer, and even generate mouse clicks using only a webcam for computer vision. One really cool use of this would be with a projector. With a projector, you could use this application and turn its projected image into an interactive screen, and even open files/menus by just pointing at them with a laser pointer!
http://ashishrd.blogspot.com

Difficulty: Intermediate
Time Required: 1-3 hours
Cost: Free
Software: Visual C# Express Editions,
Hardware: Webcam, Laser Pointer
Download:

I will be making use of Andrew Kirillov's motion detection code for image acquisition, and the AForge.NET framework, for certain image processing tasks. I'll start off by showing you how the image processing works for this program, and then I'll walk you through the important parts of the code. So, let's begin!

Image processing and laser tracking...

The laser tracking code works by finding the brightest pixel in the webcam's field of view. It is pretty much similar to the code I had written for my previous article - Laser Tracking Camera. However, since quick image processing is necessary for this program to work in real-time, I have modified the code a bit, and now it's much faster than before. The two image processing techniques I have used for optimization are - image cropping and image resizing.

Image cropping is basically just trimming off the edges of an image to keep unwanted things outside the camera's view. Image cropping also reduces the number of pixels in an image, and makes image processing fast. On the other hand, resizing images reduces the pixel resolution of an image. The pixel resolution of an image describes the resolution of an image with the set of two positive integer numbers, where the first number is the number of pixel columns (width), and the second is the number of pixel rows (height). (Examples: 320x 40, 640x480, 1024x768). An image from Wikipedia illustrates:

clip_image002[4]

The picture on the left is sampled at 20x20, and the image on the right is sampled at a higher pixel resolution, 100x100. Obviously, the higher resolution image has more detail. However, in image processing, while increased resolution results in greater information and detail, it comes at the price of memory and computing speed.
For cropping the video feed from a webcam, you can click-and-drag a selection rectangle around the area you would like to keep, and the program would remove everything else.
clip_image003[4]

The selection rectangle is a semi-transparent rubber band rectangle (picture above). A rubber band rectangle (aka focus rectangle), is a reversible rectangle that tracks with the mouse pointer while you move it around. This makes it easy to select the area you want to work on. If you are working with a projector, you can easily select its projected area, and the program would map its coordinates to the coordinates on your computer screen, and remove everything else.

Here's how you can make a rubber-band rectangle between two points (say x1,y1 and x2, y2):

//Compute width and height of rectangle
int width = Math.Abs(x2 - x1);
int height = Math.Abs(y2 - y1);                
//Decide x and y of rectangle
int x = 0, y = 0;
if (x1 < x2)
    x = x1;
else if (x1 > x2)
    x = x2;
if (y1 < y2)
    y = y1;
else if (y1 > y2)
    y = y2;
//Draw the rectangle
Rectangle rect = new Rectangle(x, y, width, height);
Graphics g = Graphics.FromImage(image);
g.FillRectangle(new SolidBrush(Color.FromArgb(60, 184, 184, 0)), rect); //Draws a semi-transparent rectangle using alpha blending
g.Dispose();


You will find this code in the ProcessFrame event in MotionDetector1.cs. Here, x1 and y1 are updated in the MouseDown event of the camera window, whereas x2 and y2 are updated in the MouseMove event.
After we know how big the selected area is, we can trim the edges by using the Bitmap.Clone method:

Bitmap tmpImage0 = image.Clone(new Rectangle(x, y, width, height), 
System.Drawing.Imaging.PixelFormat.Format24bppRgb);


For resizing the video feed by a certain factor, adjust the resize factor numeric up/down control. If you take a resize factor, say 2, then the program would divide the length and width of the webcam images by 2, and the resulting images would actually be 2^2 = 4x smaller. For example, if your webcam captures images of size 320 by 240, the total number of pixels in each image would be 320 x 240 = 76800.  If we resize these images by a factor of 2, the resulting 160 by 120 size images would contain only 160 x 120 = 19200 pixels (which is 4x less than 76800).

clip_image004[4]

Here's how we can resize an image by a given factor using the Resize filter in the AForge.Imaging library:

AForge.Imaging.Filters.Resize resize = new Resize(image.Width / resizeFactor, image.Height / resizeFactor, InterpolationMethod.NearestNeighbor);

Bitmap tmpImage1 = resize.Apply(tmpImage0);

Just keep in mind that the lesser you resize your images, the more tracking resolution you'd get while tracking lasers. However, since tracking resolution comes at the cost of memory and computing speed, pick a resize factor which works best for your computer and webcam. A resize factor of 2 or 3 usually works fine for me.
After we're done with cropping and resizing, the program can go through the pixels on the image and find the brightest pixel (I'm assuming this would be the laser dot):

for (int y = 0; y < 240; y++)
{
    for (int x = 0; x < 320; x++) 
    {
        byte red, green, blue;

        red = uBitmap.GetPixel(x, y).red;
        green = uBitmap.GetPixel(x, y).green;
        blue = uBitmap.GetPixel(x, y).blue;
        
        float brightness = (299 * red + 587 * green + 114 * blue) / 1000; 

        if (brightness > certainValue)
            // Do something
    }
}


Here, uBitmap, is an instance of the UnsafeBitmap class I had discussed in my previous article.

NOTE:
If you find brightness tracking unreliable in certain lighting conditions, change the above code to perform color detection instead of brightness detection by writing something like "if ((red > 220) && (green < 170) && (blue < 170))" instead of writing "if (brightness > certainValue)".
After our program has the x and y coordinates of the laser dot, it can compute its position on the screen:

//Get screen width and height
int screenWidth = Screen.GetBounds(this).Width;
int screenHeight = Screen.GetBounds(this).Height;
float cursorX, cursorY;
//Compute location of laser dot into camera coordinates cursorX = ((float)screenWidth / imageWidth) * x; cursorY = ((float)screenHeight / imageHeight) * y;
//Set cursor position Cursor.Position = new Point((int)cursorX, (int)cursorY);

Now that you know how the code works, lets move on to the next section, in which I will tell you how to use it.

Some notes on using the software

  • The program searches for the brightest pixel in the camera's field of view, so the lighting conditions of your room can affect its performance. Adjust the brightness threshold and lighting conditions so that nothing (except the laser) exceeds the brightness threshold. If this doesn't work, change the brightness detection code to perform color detection instead (as described earlier).

clip_image005[4]

  • If you want to reset video cropping to normal, just right-click anywhere in the camera window.
  • For clicking on something with a laser pointer, just turn off the laser when the mouse cursor is over the item you want to click on. Turning the laser off simulates a left button, single-click. You might also want to change your Folder Options to allow files/folders to be opened with single-clicks.
  • While selecting a resize factor, remember that computing speed would come at the cost of tracking resolution. Say, for example, if I use a resize factor of 1, I'd get pretty good tracking resolution, but my program would slow down to a crawl. On the other hand, if I pick a resize factor greater than 4 or 5, I'd get a decent frame rate, but horrible tracking resolution. These values could be different for you (depending on your webcam and computer). For my computer, a resize factor of 2 or 3 works fine and I get about 27-30 frames/second.


Conclusion


We have reached the end of this article, and I hope you enjoyed reading it. Now, here's some homework for you: Try implementing features like double clicking, right clicking and click-drag. If you've watched the video for this article, you must have noticed that I was drawing stuff on MS-Paint using this program. For accomplishing this, I had to modify my code to perform click-drag. If you can think of an easier, laser-based way to switch between different clicking modes, I think that would be very cool. So, use your ideas, and if you end up doing something cool, I'd love to hear about it. :) Have fun!

About the Author

Ashish Derhgawen is an IT student, currently living in New Delhi, India. He has been coding since fourth grade. Some of his other interests are harmonica playing, wildlife and cricket. When he’s not at school, he spends his time working on unusual projects related to robotics, webcams, and electronics besides others. You can reach Ashish through his blog at http://ashishrd.blogspot.com.

Deepzoom application in 15 minutes
09 April 08 12:01 PM | Coding4Fun | 3 Comments   

Dan Waters has created a quick Deepzoom tutorial.  Here is his DeepZoom application in a working environment.  If you want access to his source code, check out the full post.

Filed under:
Capturing that darn webcam stream
06 April 08 11:50 AM | Coding4Fun | 0 Comments   

dinosaur-webcam[1] Ever wanted to do capture a webcam data stream and save it to a WMV file?  The UberDemo blog over at the MSDN blogs shows you how to accomplish just this.  They had to create a Cirque du Soleil demo for MIX '08 and shows the basics on how to do this.  They do note this isn't a production quality sample but shows some value on how to do everything.

Now the demo does have some installation requirements and installation steps so be warned.

Filed under:
Burn baby burn
02 April 08 11:24 AM | Coding4Fun | 2 Comments   

Over at Code Project, Eric Haddan created a very nice API to burn CDs and DVDs.  He uses the IMAPI v2.0 to be able to do this complex ability.  Eric talks about some of the issues he had to accomplish this with .Net along with how he solved it.  In the article also he talks about the classes and interfaces he created to be able to burn media.

burnmedia[1]

Filed under:
Software License breakdown
31 March 08 04:48 PM | Coding4Fun | 1 Comments   

gpd_plate2[1] Always wonder what is the difference between the GPL, the Ms-PL, Creative Commons, and the MIT software licenses are?  Over at the Code Project, they have a extremely easy to understand breakdown of software licenses.

  • Provides copyright protection
  • Can be used in commercial applications
  • Bug fixes / extensions must be released to the public domain
  • Provides an explicit patent license
  • Can be used in closed source applications
  • Is a viral licence

In addition, Wikipedia has another great listing of software licenses

Filed under:
You need 20 pieces of flare for your application
27 March 08 11:52 AM | Coding4Fun | 1 Comments   

 FluidKit is a great open-source kit for WPF applications.  One of the new features in the kit is called ElementFlow which recreates some effects from another company who's logo may or may not be an Apple.

In addition to just the element flow stuff, FluidKit has a few other cool tricks up its sleeve.

  • ImageButton
  • DragDropManager
  • GlassWindow
  • BalloonDecorator
  • ItemSkimmingPanel + SkimmingContextAdorner
  • PennerDoubleAnimation
  •  coverFlow

    Filed under:
    Code Faster: Activate Snippet Power
    26 March 08 07:11 AM | Coding4Fun | 0 Comments   

    The VB Team has a great article on snippets.  Well, first off, what exactly is a snippet?  It is a bit of code you constantly use over and over again.  A great example is a property.  If I start typing "Pro"

    Then I'll get:

    The green fields are called "snippet replacements" and are what you're suppose to verify.

    The article has additional information regarding snippets.  While you may be saying to yourself, this is worthless, it vastly reduces the amount of typing you have to do and tells you where you need to update!

    Filed under:
    Silverlight - Everything you wanted to know
    25 March 08 09:38 AM | Coding4Fun | 3 Comments   

    Dave "DaveDev" Isbitski posted a video over on Channel9 outlining a lot of things you'll need to know about Silverlight.

    His video includes:

    • What it is
    • Where to get the software and tools to code in it
    • What been updated in Silverlight 2.0 project styles compared to 1.1
    • How to use DeepZoom Composer to create your own content
    • How to code in panning and zooming
    • And finally create your own cool application using both Deep Zoom and other media elements
    Filed under:
    More Posts Next page »
    Page view tracker