Sensor to scan 2d surface

Hey,
Im trying to find a cheap solution to scan my 2d surface but I can only find tutorials about 3d room scanning..
for example if i have a surface with nails in it it should tell me the coordinates of the nails.
Thanks for any help !

Take a photo and process it with Matlab on a PC. Here is a tutorial with rice grains.

Thanks a lot !

If the surface isn't flat, its not 2D