Automated inspection of mechanical components by optical systems