loop to capture image