optimize image capture while loop at image_capture.c