imagine there are many rectangular boxes with different sizes and there are rectangular holes in the middle of these boxes with different sizes. I want to measure the length and width of these holes (not the depth). What kind of sensors should I use? (please recommend me the cheapest way instead of 3D camera and so on.)
Depending on the material of your boxes, you might be able to use reflective optical sensors. The box would reflect(activating the sensor), whereas the hole would not. As the box passes by the sensor (or vice-versa) you could have a microprocessor monitoring the output of the sensor.