Patent ID: 8169531

Claim:
A system for automatically focusing an optical lens of an image measuring machine, the system comprising a storage system storing a plurality of programs and a processor that executes one or more operations for the plurality of programs, the programs comprising: a driving module operable to drive a light-emitting device of the image measuring machine to emit light, and control the light to penetrate a glass sheet, so as to project a picture of the glass sheet onto an object, wherein the object is positioned on a work platform of the image measuring machine; a capturing module operable to move the optical lens along a Z-axis of the image measuring machine, so as to capture one or more digital images of the object; a computing module operable to compute a definition value of each captured digital image, wherein the definition value is computed as follows: G = ∑ i - 1 n ⁢ ∑ j = 1 n ⁢ (  P i , j - 1 - P i - 1 , j  +  P i - 1 , j - P i + 1 , j  ) S , wherein P i,j is a gray value of a pixel and S is a total of all the pixels of a captured digital image; and an obtaining module operable to obtain a focus position corresponding to a captured digital image having the highest definition value.