00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <math.h>
00004 #include <assert.h>
00005 #include <FCam/N900.h>
00006 #include <FCam/AutoExposure.h>
00007
00010
00011 namespace Plat = FCam::N900;
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 int main(int argc, char ** argv) {
00022
00023
00024 Plat::Sensor sensor;
00025
00026
00027 FCam::Shot stream1;
00028
00029 stream1.exposure = 50000;
00030 stream1.gain = 1.0f;
00031
00032
00033 stream1.image = FCam::Image(640, 480, FCam::UYVY);
00034
00035
00036 stream1.histogram.regions = 1;
00037 stream1.histogram.region[0] = FCam::Rect(0, 0, 640, 480);
00038
00039
00040 int cnt = 0;
00041 int stable_cnt = 0;
00042 float exposure;
00043 float lastExposure;
00044
00045 FCam::Frame::Ptr frame;
00046
00047 do {
00048
00049 lastExposure = exposure;
00050
00051
00052 sensor.stream(stream1);
00053
00054
00055 frame = sensor.getFrame();
00056 assert(frame->shot().id == stream1.id);
00057
00058
00059 autoExpose(&stream1, frame);
00060
00061
00062 exposure = stream1.exposure * stream1.gain;
00063
00064
00065 if (cnt++ > 0) {
00066 stable_cnt = fabs((exposure - lastExposure) / lastExposure) < 0.1f ?
00067 stable_cnt + 1 : 0;
00068 }
00069 } while (stable_cnt < 5);
00070
00071
00072 sensor.stopStreaming();
00073 printf("Processed %d frames until stable for 5 frames!\n", cnt);
00074 printf("Final exposure: %f us", exposure);
00075
00076
00077 while (sensor.shotsPending() > 0) frame = sensor.getFrame();
00078
00079
00080 if (argc > 1) FCam::saveJPEG(frame, argv[1]);
00081
00082
00083 assert(sensor.framesPending() == 0);
00084 assert(sensor.shotsPending() == 0);
00085 }