• 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     // Save the frame
00048     FCam::saveJPEG(frame, "/home/user/MyDocs/DCIM/example1.jpg"); 
00049     
00050     // Check that the pipeline is empty.
00051     assert(sensor.framesPending() == 0);
00052     assert(sensor.shotsPending() == 0);
00053 
00054     return 0;
00055 }
00056 
00057 
00058 
00059 
00060 void errorCheck() {
00061     // Make sure FCam is running properly by looking for DriverError.
00062     FCam::Event e;
00063     while (FCam::getNextEvent(&e, FCam::Event::Error) ) {
00064         if (e.data == FCam::Event::DriverMissingError) {
00065             printf("example1: FCam can't find its driver. Did you install "
00066                    "fcam-drivers on your platform, and reboot the device "
00067                    "after installation?\n(FCam error message: %s)\n", e.description.c_str());
00068             exit(1);
00069         }
00070         if (e.data == FCam::Event::DriverLockedError) {
00071             printf("example1: Another FCam program appears to be running "
00072                    "already. Only one can run at a time.\n"
00073                    "(FCam error message: %s)\n", e.description.c_str());
00074             exit(1);
00075         }
00076     }
00077 }

Generated on Thu Jul 22 2010 17:50:33 for FCam by  doxygen 1.7.1