The present invention provides a method and a system for inspecting a wafer. The system comprises an optical detection head, a wafer operation table, a wafer stack, a XY operation table and a vibration separator. The optical detection head comprises some lighters, an image collector, an objective lens and other optical componets. The system and the method can collect bright field image, dark field image, 3D image and redetection image. The collected image is converted to an image signal and is transmitted to a programmable controller for processing. The detection is performed in the wafer moving process. The collected image is compared with a reference picture for finding the defect on the wafer. The invention provides a process method used for generating an optimized reference image and an optimized process method for detecting the picture. The generation process of the reference picture is performed automatically.