• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

examples/example3/example3.cpp

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 
00009 // Select the platform
00010 namespace Plat = FCam::N900;
00011 // namespace Plat = FCam::F2;
00012 
00013 /***********************************************************/
00014 /* Focus sweep                                             */
00015 /*                                                         */
00016 /* This example demonstrates moving the lens during an     */
00017 /* exposure via the use of Lens::FocusAction. It also      */
00018 /* shows how to use the metadata tagged by the devices.    */
00019 /* Because the lens on the N900 zooms slightly when it     */
00020 /* focuses, you'll also get a zoom-blur effect.            */
00021 /***********************************************************/
00022 int main(int argc, char ** argv) {
00023 
00024     // Devices
00025     Plat::Sensor sensor;
00026     Plat::Lens lens;
00027 
00028     // Attach the lens to the sensor
00029     sensor.attach(&lens); 
00030     
00031     // First focus near with maximal speed
00032     lens.setFocus(lens.nearFocus(), lens.maxFocusSpeed());
00033     while (lens.focusChanging()); // Wait to be done
00034     
00035 
00036     // Now make a shot that will sweep the lens
00037     FCam::Shot shot1;
00038     
00039     FCam::Lens::FocusAction sweep(&lens);
00040     // Set the parameters of this action
00041     sweep.time = 0;
00042     sweep.focus = lens.farFocus();
00043     sweep.speed = lens.maxFocusSpeed()/4;
00044     // Calculate how long it takes to move the lens to the desired
00045     // location in microseconds
00046     float duration = 1000000.0f *
00047         (lens.nearFocus() - lens.farFocus()) / sweep.speed;
00048 
00049     printf("The lens will sweep from near to far in %f milliseconds\n",
00050            duration / 1000.0);
00051 
00052     // Set the shot parameter accordingly
00053     shot1.exposure = duration;
00054     shot1.gain = 1.0f;
00055     // Use a lower resolution to minimize rolling shutter effects
00056     shot1.image = FCam::Image(640, 480, FCam::UYVY);
00057 
00058     // Attach the action to the shot
00059     shot1.addAction(sweep);
00060     
00061     // Order the sensor to capture the shot
00062     sensor.capture(shot1);
00063     assert(sensor.shotsPending() == 1); // There should be exactly one shot
00064     
00065     // Retrieve the frame
00066     FCam::Frame frame = sensor.getFrame();
00067     assert(frame.shot().id == shot1.id); // Check the source of the request
00068    
00069     // Print out some metadata
00070     const FCam::Lens::Tags lensTags(frame);
00071     printf("Aperture        : %.4f\n", lensTags.aperture);
00072     printf("Initial focus   : %.4f\n", lensTags.initialFocus);
00073     printf("Final focus     : %.4f\n", lensTags.finalFocus);   
00074     
00075     // Save the resulting file
00076     FCam::saveJPEG(frame, "/home/user/MyDocs/DCIM/example3.jpg");
00077 
00078     assert(sensor.framesPending() == 0);
00079     assert(sensor.shotsPending() == 0);
00080 }

Generated on Fri Sep 24 2010 15:52:59 for FCam by  doxygen 1.7.1