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

examples/example1/example1.cpp

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <assert.h>
00004 
00005 // Select the platform
00006 #include <FCam/N900.h>
00007 namespace Plat = FCam::N900;
00008 
00011 /***********************************************************/
00012 /* A program that takes a single shot                      */
00013 /*                                                         */
00014 /* This example is a simple demonstration of the usage of  */
00015 /* the FCam API.                                           */
00016 /***********************************************************/
00017 
00018 void errorCheck();
00019 
00020 int main(int argc, char ** argv) {
00021 
00022     // Make the image sensor
00023     Plat::Sensor sensor;
00024     
00025     // Make a new shot
00026     FCam::Shot shot1;
00027     shot1.exposure = 50000; // 50 ms exposure
00028     shot1.gain = 1.0f;      // minimum ISO
00029 
00030     // Specify the output resolution and format, and allocate storage for the resulting image
00031     shot1.image = FCam::Image(2592, 1968, FCam::UYVY);
00032     
00033     // Order the sensor to capture a shot
00034     sensor.capture(shot1);
00035 
00036     // Check for errors 
00037     errorCheck();
00038 
00039     assert(sensor.shotsPending() == 1); // There should be exactly one shot
00040     
00041     // Retrieve the frame from the sensor
00042     FCam::Frame frame = sensor.getFrame();
00043 
00044     // This frame should be the result of the shot we made
00045     assert(frame.shot().id == shot1.id);
00046 
00047     // This frame should be valid too
00048     assert(frame.valid());
00049     assert(frame.image().valid());
00050     
00051     // Save the frame
00052     FCam::saveJPEG(frame, "/home/user/MyDocs/DCIM/example1.jpg"); 
00053     
00054     // Check that the pipeline is empty
00055     assert(sensor.framesPending() == 0);
00056     assert(sensor.shotsPending() == 0);
00057 
00058     return 0;
00059 }
00060 
00061 
00062 
00063 
00064 void errorCheck() {
00065     // Make sure FCam is running properly by looking for DriverError
00066     FCam::Event e;
00067     while (FCam::getNextEvent(&e, FCam::Event::Error) ) {
00068         printf("Error: %s\n", e.description.c_str());
00069         if (e.data == FCam::Event::DriverMissingError) {
00070             printf("example1: FCam can't find its driver. Did you install "
00071                    "fcam-drivers on your platform, and reboot the device "
00072                    "after installation?\n");
00073             exit(1);
00074         }
00075         if (e.data == FCam::Event::DriverLockedError) {
00076             printf("example1: Another FCam program appears to be running "
00077                    "already. Only one can run at a time.\n");
00078             exit(1);
00079         }        
00080     }
00081 }

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