Go to the documentation of this file.00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <assert.h>
00004 #include <FCam/N900.h>
00005 #include <FCam/AutoFocus.h>
00006
00009
00010 namespace Plat = FCam::N900;
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 int main(int argc, char ** argv) {
00021
00022
00023 Plat::Sensor sensor;
00024 Plat::Lens lens;
00025 sensor.attach(&lens);
00026
00027
00028 FCam::AutoFocus autoFocus(&lens);
00029
00030
00031 FCam::Shot stream1;
00032
00033 stream1.exposure = 50000;
00034 stream1.gain = 1.0f;
00035
00036
00037 stream1.image = FCam::Image(640, 480, FCam::UYVY);
00038
00039
00040 stream1.sharpness.enabled = true;
00041
00042
00043 int count = 0;
00044
00045
00046 sensor.stream(stream1);
00047
00048
00049 autoFocus.startSweep();
00050
00051
00052 FCam::Frame frame;
00053
00054 do {
00055
00056 frame = sensor.getFrame();
00057 assert(frame.shot().id == stream1.id);
00058
00059
00060
00061
00062 float diopters = frame["lens.focus"];
00063 printf("Lens focused at %2.0f cm\n", 100/diopters);
00064
00065
00066
00067
00068 int totalSharpness = 0;
00069 for (int y = 0; y < frame.sharpness().height(); y++) {
00070 for (int x = 0; x < frame.sharpness().width(); x++) {
00071 totalSharpness += frame.sharpness()(x, y);
00072 }
00073 }
00074 printf("Total sharpness is %d\n\n", totalSharpness);
00075
00076
00077 autoFocus.update(frame);
00078
00079
00080 count++;
00081 } while (!autoFocus.idle());
00082
00083 printf("Autofocus chose to focus at %2.0f cm\n\n", 100/lens.getFocus());
00084
00085
00086 if (argc > 1) FCam::saveJPEG(frame, argv[1]);
00087
00088
00089 sensor.stopStreaming();
00090 printf("Processed %d frames until autofocus completed!\n", count);
00091
00092
00093 while (sensor.shotsPending() > 0) frame = sensor.getFrame();
00094
00095
00096 assert(sensor.framesPending() == 0);
00097 assert(sensor.shotsPending() == 0);
00098 }