ladybug_test.cpp
Go to the documentation of this file.
00001 /*
00002  * ladybug_test.cpp
00003  *
00004  *  Created on: Aug 24, 2010
00005  *      Author: petrito1@cmp.felk.cvut.cz
00006  *
00007  * Executable for tracking corrupt images.
00008  * Corrupt images are detected using mean difference between two successive images.
00009  * The reason is most probably a HW configuration:
00010  * http://www.ptgrey.com/support/kb/index.asp?a=4&q=188
00011  */
00012 
00013 #include <GL/glew.h>
00014 #include <GL/glut.h>
00015 
00016 #include <opencv2/core/core.hpp>
00017 #include <opencv2/highgui/highgui.hpp>
00018 
00019 #include <signal.h>
00020 #include <sys/param.h>
00021 #include <sys/times.h>
00022 
00023 #include "CameraException.h"
00024 #include "Camera.h"
00025 #include "CameraContext.h"
00026 
00027 #include "LadybugVirtualCamera.h"
00028 
00029 using std::string;
00030 
00031 using cv::Mat;
00032 
00033 using nifti::dc1394::Camera;
00034 using nifti::dc1394::CameraContext;
00035 using nifti::dc1394::CameraException;
00036 
00037 using nifti::ladybug::LadybugVirtualCamera;
00038 
00039 void sigintHandler(int sig);
00040 void printDuration(char* message, tms t1, long r1);
00041 
00042 namespace {
00043 bool halt = false;
00044 }
00045 
00046 int main(int argc, char **argv) {
00047 
00048   if (argc < 3) {
00049     return -1;
00050   }
00051 
00052   signal(SIGINT, sigintHandler);
00053   glutInit(&argc, argv);
00054 
00055   CameraContext context;
00056 
00057   Camera camera = context.getCamera();
00058   //  camera.resetBus();
00059   //  camera.reset();
00060 //  camera.setup();
00061 
00062   printf("Format 7 color coding: %d.\n", camera.getFormat7ColorCoding());
00063   printf("Format 7 color filter: %d.\n", camera.getFormat7ColorFilter());
00064   printf("Format 7 frame interval: %f.\n", camera.getFormat7FrameInterval());
00065   printf("Format 7 packets per frame: %u.\n", camera.getFormat7PacketsPerFrame());
00066   printf("Format 7 packet size: %u.\n", camera.getFormat7PacketSize());
00067   printf("Format 7 recommended packet size: %u.\n", camera.getFormat7RecommendedPacketSize());
00068 
00069   camera.setupCapture();
00070   camera.startVideoTransmission();
00071 
00072   LadybugVirtualCamera ladybug;
00073   ladybug.initialize(true);
00074   ladybug.loadMesh(argv[1]);
00075   ladybug.loadAlphamask(argv[2]);
00076   ladybug.setViewport(1200, 800);
00077   ladybug.setHorizontalFov(120);
00078   ladybug.setVerticalFov(80);
00079 
00080   struct tms t1;
00081   long r1;
00082 
00083   int iFrame = 0;
00084   Mat frame1, frame2;
00085   while (!halt) {
00086     r1 = times(&t1);
00087     camera.captureColorMat(frame2, true);
00088     printDuration("Frame capture:     ", t1, r1);
00089 
00090     // Compare two following images for differences.
00091     if (frame1.rows > 0 && frame1.cols > 0) {
00092 
00093       r1 = times(&t1);
00094       double diff = std::abs(cv::mean(frame1 - frame2).val[0]);
00095       printf("Absolute mean difference: %lf\n", diff);
00096       printDuration("Calculating difference:  ", t1, r1);
00097 
00098       if (diff > 25.0) {
00099         r1 = times(&t1);
00100         char imagePath[128];
00101         sprintf(imagePath, "image_%02d_composite.jpg", iFrame);
00102         cv::imwrite(string(imagePath), frame2);
00103         printDuration("Writing composite: ", t1, r1);
00104       }
00105     }
00106 
00107     //    r1 = times(&t1);
00108     //    vcam.setImages(composite);
00109     //    printDuration("Setting images:    ", t1, r1);
00110 
00111     //    Mat view;
00112     //    r1 = times(&t1);
00113     //    vcam.renderView(view);
00114     //    printDuration("Rendering view:    ", t1, r1);
00115 
00116     //    r1 = times(&t1);
00117     //    sprintf(imagePath, "image_%02d_view.jpg", iFrame++);
00118     //    cv::imwrite(string(imagePath), view);
00119     //    printDuration("Writing view:      ", t1, r1);
00120 
00121     iFrame++;
00122     frame1 = frame2;
00123   }
00124 
00125   camera.stopVideoTransmission();
00126   camera.stopCapture();
00127   camera.releaseAll();
00128 }
00129 
00130 void sigintHandler(int sig) {
00131   printf("Signal %d received. Halting...\n", sig);
00132   halt = true;
00133 }
00134 
00135 void printDuration(char* message, tms t1, long r1) {
00136   struct tms t2;
00137   long r2;
00138   r2 = times(&t2);
00139 
00140   printf("%s", message);
00141   printf("user = %1.2f, ", ((float) (t2.tms_utime - t1.tms_utime)) / HZ);
00142   printf("system = %1.2f, ", ((float) (t2.tms_stime - t1.tms_stime)) / HZ);
00143   printf("real = %1.2f\n", ((float) (r2 - r1)) / HZ);
00144 }
 All Classes Namespaces Files Functions Variables Typedefs Defines


omnicamera
Author(s): Tomas Petricek / petrito1@cmp.felk.cvut.cz
autogenerated on Tue Dec 10 2013 14:26:53