Main Page | Class List | File List | Class Members | Examples

lexp.cpp

This example shows how to take a long exposure with the SC1ModCam class.
/* * WARNING: * * This program needs to be run with root privileges in order to * access the parallel port! * */ #include <iostream> #include <fstream> using namespace std; #include "SC1ModCam.hpp" /* * This function isn't implemented in the class because you may want * to do different things with the errors depending on your environment. * * This does a good job of printing the message to STDERR and then quitting. * */ void die (string s, enum SC1ModCam::ERRCODE code); int main (void) { // String used for error handling string s; SC1ModCam cam; void * buf; // This check is needed here in case the initialization failed if (cam.error(&s) >= SC1ModCam::ERR_ERROR) die(s, cam.error()); // All of these calls are optional. The defaults // should work on just about any camera. if (!cam.set_resolution(640, 480)) die("Need PWCX module for this resolution!", SC1ModCam::ERR_ERROR); // This combination will cause the camera to expose for about // 6.4 seconds (32 / 5) cam.set_multiplier(32); cam.set_fps(5); if (cam.error(&s) != SC1ModCam::ERR_OK) die(s, cam.error()); // This function will block until the exposure finishes // and the buffer is ready. cam.take_photo(); // This way, warnings skip by if (cam.error(&s) >= SC1ModCam::ERR_ERROR) die(s, cam.error()); // Careful here! buf is freed when cam is destructed. buf = cam.get_buffer(); // Now just save it to disk. The image is in YUV 4:2:0 Planar // format, so you might want to rewrite it to a more universally // accepted format before writing it out. But ImageMagick works with // YUV420P files, so you can look at it with display(1). ofstream outfile ("outfile.yuv", ofstream::binary); outfile.write((const char *) buf, (streamsize) cam.get_buffer_size()); return 0; } void die (string s, enum SC1ModCam::ERRCODE code) { string toprint; switch (code) { case SC1ModCam::ERR_OK: toprint = "Success: "; break; case SC1ModCam::ERR_ERROR: toprint = "Error: "; break; case SC1ModCam::ERR_WARN: toprint = "Warning: "; break; case SC1ModCam::ERR_FATAL: toprint = "FATAL: "; break; default: toprint = "Huh?: "; break; } toprint += s; toprint += "\n"; cerr << toprint; exit(1); }
00001 /* 00002 * WARNING: 00003 * 00004 * This program needs to be run with root privileges in order to 00005 * access the parallel port! 00006 * 00007 */ 00008 00009 #include <iostream> 00010 #include <fstream> 00011 using namespace std; 00012 00013 #include "SC1ModCam.hpp" 00014 00015 /* 00016 * This function isn't implemented in the class because you may want 00017 * to do different things with the errors depending on your environment. 00018 * 00019 * This does a good job of printing the message to STDERR and then quitting. 00020 * 00021 */ 00022 00023 void die (string s, enum SC1ModCam::ERRCODE code); 00024 00025 int main (void) 00026 { 00027 // String used for error handling 00028 string s; 00029 SC1ModCam cam; 00030 void * buf; 00031 00032 // This check is needed here in case the initialization failed 00033 00034 if (cam.error(&s) >= SC1ModCam::ERR_ERROR) 00035 die(s, cam.error()); 00036 00037 // All of these calls are optional. The defaults 00038 // should work on just about any camera. 00039 00040 if (!cam.set_resolution(640, 480)) 00041 die("Need PWCX module for this resolution!", SC1ModCam::ERR_ERROR); 00042 00043 // This combination will cause the camera to expose for about 00044 // 6.4 seconds (32 / 5) 00045 cam.set_multiplier(32); 00046 cam.set_fps(5); 00047 00048 if (cam.error(&s) != SC1ModCam::ERR_OK) 00049 die(s, cam.error()); 00050 00051 // This function will block until the exposure finishes 00052 // and the buffer is ready. 00053 00054 cam.take_photo(); 00055 00056 // This way, warnings skip by 00057 if (cam.error(&s) >= SC1ModCam::ERR_ERROR) 00058 die(s, cam.error()); 00059 00060 // Careful here! buf is freed when cam is destructed. 00061 buf = cam.get_buffer(); 00062 00063 // Now just save it to disk. The image is in YUV 4:2:0 Planar 00064 // format, so you might want to rewrite it to a more universally 00065 // accepted format before writing it out. But ImageMagick works with 00066 // YUV420P files, so you can look at it with display(1). 00067 00068 ofstream outfile ("outfile.yuv", ofstream::binary); 00069 outfile.write((const char *) buf, (streamsize) cam.get_buffer_size()); 00070 00071 return 0; 00072 } 00073 00074 void die (string s, enum SC1ModCam::ERRCODE code) 00075 { 00076 string toprint; 00077 switch (code) 00078 { 00079 case SC1ModCam::ERR_OK: 00080 toprint = "Success: "; 00081 break; 00082 00083 case SC1ModCam::ERR_ERROR: 00084 toprint = "Error: "; 00085 break; 00086 00087 case SC1ModCam::ERR_WARN: 00088 toprint = "Warning: "; 00089 break; 00090 00091 case SC1ModCam::ERR_FATAL: 00092 toprint = "FATAL: "; 00093 break; 00094 00095 default: 00096 toprint = "Huh?: "; 00097 break; 00098 } 00099 00100 toprint += s; 00101 toprint += "\n"; 00102 00103 cerr << toprint; 00104 exit(1); 00105 }

Generated on Fri Jul 16 12:22:57 2004 for libsc1mod by doxygen 1.3.7