The present invention provides a mechanism for automatically setting the exposure time and gain of an electronic camera so that the acquired image has improved characteristics for the detection of a digital watermark. With the present invention the exposure time and gain of an electronic camera are set by first directing the camera at a test target with the camera's controls set to a default set of values (501). The system then calculates a histogram of the luminance values (503) of the pixels in the image. Next characteristic values from the histogram such as the peak value, the centroid value (505), the RMS value, the median value, etc. are calculated. One or more of the characteristic values of the histogram are then applied as an index or pointer to values of pre-established settings that are stored in a table. Values from the table are used to set the exposure time and/or gain (506) of the camera. In some embodiments, the variance of the luminance histogram is also measured and used to index data from the table.