One of my project contains 6mm defect size.How i will decide that certain megapixel of camera will be able to detect it.
you should start with a simple formula:
Resolution = (Object Size) / (Size of the detail to be inspected)
Size of the detail to be inspected is 6mm in your case. Object size is the FOV (Field of view), that is the size of the whole area, your camera is looking at. Let's say, you want to detect a 6mm defect within an area of 600mm x 600mm:
Resolution = 600mm / 6mm = 100pixels
This is the minimum resolution needed (in both directions). Since sensors normally are rectangular, rather than quadratic, the 100 pixels are the needed minimum sensor height.
BUT, this is only half of the truth. According to the Nyquist-Shannon sampling theorem, at least twice the frequency is required.
In our case twice the frequency means twice the number of pixels, so our formula becomes:
Resolution = (Object Size) / (Size of the detail to be inspected) * (Nyquist Factor)
The Nyquist Factor normally is 2 (according to the sampling theorem).
This is true for monochrome sensors! If you use a color sensor with bayer pattern, you'll need to de-bayer (interpolate) the raw image in order to get a full RGB image. This interpolation reduces your optical resolution. So for bayer sensors, you need to further increase the Nyquist Factor. Typical values are 3 or even 4.
Next you can use the Basler Lens Selector in order to find a suitable lens:
Select a camera that matches your resolution in pixels, enter width or height of your FOV, enter the distance between camera and object, click into the focal length field and you will get a focal length value.