First, define these basic terms for your situation:
See the following images for reference:
Follow two main steps to pick the minimum required camera resolution and to determine the correct focal length for your application.
The resolution of an image is the number of pixels in the image. This is in two dimensions; for example 640X480. The calculations can be done for each dimension separately; but, for simplicity, this is often reduced to one dimension.
To make an accurate measurement on the image, you need to use a minimum of two pixels per smallest feature that you want to detect. To do the calculation for the minimum sensor resolution, multiply two (pixels/smallest feature) times the size (in real-world units) of the field of view divided by the size of the smallest feature as shown in the following equation:
Calculate sensor resolution:
The equation can be modified to solve for any other variable so long as three variables are known.
Sensor size refers to the physical size of the sensor, and is typically not noted on specification sheets. The best way to determine sensor size is to look at the pixel size on the sensor and multiply by the resolution.
Calculate sensor size:
Sensor format refers to the physical size of the sensor, but is not dependent on the pixel size. This specification is used to determine what lens the camera is compatible with. In order for a lens to be compatible with a camera, the format of the lens needs to be greater than or equal to the sensor format. If a lens with a smaller format is use, the image experiences vignetting; this causes regions of the sensor outside of the lens format area to be dark.
Generally, lenses have fixed focal lengths. Also, it is common that the working distance is flexible, so for simple calculations start out with a ratio of working distance to focal length. This will allow you to use specific lens focal lengths to determine the working distance needed. If the working distance is limited, then, by inverting this ratio, we get the ratio of focal length to working distance. This will allow you to use a range of working distance options to get a focal length range. Then once a lens is selected you can recalculate the exact working distance needed.
These calculations are based on the following equation:
Calculate Focal Length:
Lenses are manufactured with a limited number of standard focal lengths. Common lens focal lengths include 6 mm, 8 mm, 12.5 mm, 25 mm, and 50 mm. Once you choose a lens whose focal length is closest to the focal length required by your imaging system, you need to adjust the working distance to get the object under inspection in focus.
Note: Lenses with short focal lengths (less than 12 mm) produce images with a significant amount of distortion. If your application is sensitive to image distortion, try to increase the working distance and use a lens with a higher focal length. If you cannot change the working distance, you are somewhat limited in choosing a lens.
For your Basler camera feel free to use the Basler Lens Selector tool.