Sense a rectangular hole

Hi, I'm working on a project right now where I need to be able to sense a rectangular hole in a "wall," and then calculate the center of that same hole. Imagine two vertical 2x4's spaced 2m apart and then 2 horizontal 2x4's between the vertical 2x4's spaced 1.5m apart for the "wall" in question; there isn't any drywall facing around this hole, just a 2x4 frame.

My question is, what kind of sensors do I need to be able to achieve my goal? Have any of you done this task and have sample code I can look at?

Thanks in Advanced

Something like a CNC touch-trigger probe like this DIY one:

Thanks for the suggestion, but I forgot to mention that I can't touch the "hole" at all. Any other ideas?

laser, measure reflection /not? is that an option?

Yeah, that can be an option. Do you know how to implement such a device?

in essence it is a distance sensor, price is higher than IR or ultrasonic distance sensors.

check - -

If you want it cheaper, you can use a narrow bundle ping))) sensor and scan an area - using 2 servo's just like a typical robot.

You will get a matrix of distances per direction, where a direction is described by the 2 angles of the servos. In that matrix you can find the "sudden" changes in distance and that is where the edges of the hole are. For a square you can search for the four corners and by averaging the points you get the mid-point. For a non symmetric shape you have to follow the contour of the edges and do some math to locate the middle.

but I forgot to mention that I can't touch the "hole" at all

I think there a few other things you forgot to mention. Please give us the details. Is this a class project? Do you have the specs. for the project that you can show us? Or are you building a house? What if the sensor determines that the area is not an exact rectangle? Is this to actually be used with lumber, or was that just an example? What media will it be used on?