1. A method comprising: projecting a light pattern towards a target object; detecting light returned from the target object through an imaging lens arrangement with an imaging sensor to capture a first image during a first frame exposure time period, the imaging sensor having rows of photosensitive elements arranged in a matrix wherein each row of photosensitive elements is associated with a corresponding row-exposure-time period, and wherein the average position of the focus plane of the imaging lens arrangement in object space during a first row-exposure-time period associated with a first selected row is different from the average position of the focus plane of the imaging lens arrangement in object space during a second row-exposure-time period associated with a second selected row, with both the first row-exposure-time period and the second row-exposure-time period allocated within said first frame exposure time period; comparing a first part of the first image with a second part of the first image to determine the position of the focus plane of the imaging lens arrangement during at least part of said second frame exposure time period; detecting light returned from the target object through the imaging lens arrangement with the imaging sensor to capture a second image during a second frame exposure time period, wherein the position of the focus plane of the imaging lens arrangement during at least part of said second frame exposure time period is maintained at an optimized position as determined from processing the first image; and processing an image of a barcode in the second image to decode the barcode.