Go to the documentation of this file.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 #include <FCam/AutoWhiteBalance.h>
00008
00011
00012 namespace Plat = FCam::N900;
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 int main(int argc, char ** argv) {
00023
00024
00025 Plat::Sensor sensor;
00026
00027
00028 FCam::Shot stream1;
00029
00030 stream1.exposure = 33333;
00031 stream1.gain = 1.0f;
00032
00033
00034
00035
00036
00037
00038 stream1.image = FCam::Image(640, 480, FCam::UYVY);
00039
00040
00041 stream1.histogram.enabled = true;
00042 stream1.histogram.region = FCam::Rect(0, 0, 640, 480);
00043
00044
00045 int count = 0;
00046 int stableCount = 0;
00047 float exposure;
00048 float lastExposure;
00049
00050 FCam::Frame frame;
00051
00052 do {
00053
00054 sensor.stream(stream1);
00055
00056
00057 frame = sensor.getFrame();
00058 assert(frame.shot().id == stream1.id);
00059
00060 printf("Exposure time: %d, gain: %f\n", frame.exposure(), frame.gain());
00061
00062
00063 exposure = frame.exposure() * frame.gain();
00064
00065
00066
00067 autoExpose(&stream1, frame);
00068
00069
00070
00071 autoWhiteBalance(&stream1, frame);
00072
00073
00074
00075
00076 if (count++ > 0) {
00077 if (fabs((exposure - lastExposure)) / lastExposure < 0.05f) {
00078 stableCount++;
00079 } else {
00080 stableCount = 0;
00081 }
00082 }
00083
00084
00085 lastExposure = exposure;
00086
00087 } while (stableCount < 5);
00088
00089
00090 if (argc > 1) FCam::saveJPEG(frame, argv[1]);
00091
00092
00093 sensor.stopStreaming();
00094 printf("Processed %d frames until stable for 5 frames!\n", count);
00095
00096
00097 while (sensor.shotsPending() > 0) frame = sensor.getFrame();
00098
00099
00100 assert(sensor.framesPending() == 0);
00101 assert(sensor.shotsPending() == 0);
00102 }