optimize facedetection with flags