BrickIt is an app that's a couple of years old, but I've just seen a demonstration of it in use, and it's pretty amazing. It can scan a photo of your pile of thousands of random Lego bricks, identify each one, suggest building projects, send you step-by-step instructions, and even tell you where in your pile each brick required for your chosen project is.
Here is a cheerful video demonstrating its use.
Now we need an app that sets off an alarm when you're barefoot and about to step on a stray lego piece.