test_ladybug_roi.cpp
Go to the documentation of this file.
00001 /*
00002  * test_ladybug_roi.cpp
00003  *
00004  *  Created on: Sep 2, 2010
00005  *      Author: petrito1@cmp.felk.cvut.cz
00006  */
00007 
00008 #include <opencv2/core/core.hpp>
00009 #include <opencv2/imgproc/imgproc.hpp>
00010 #include <opencv2/highgui/highgui.hpp>
00011 
00012 #include <signal.h>
00013 #include <sys/param.h>
00014 #include <sys/times.h>
00015 
00016 #include "CameraException.h"
00017 #include "Camera.h"
00018 #include "CameraContext.h"
00019 
00020 #include "LadybugVirtualCamera.h"
00021 
00022 #define IMAGE_SELECTION_REGISTER 0x1E88
00023 
00024 #define IMAGE_SELECTION_CAMERA0_CHANNEL0_MASK (1 << 23)
00025 #define IMAGE_SELECTION_CAMERA1_CHANNEL0_MASK (1 << 19)
00026 #define IMAGE_SELECTION_CAMERA2_CHANNEL0_MASK (1 << 15)
00027 #define IMAGE_SELECTION_CAMERA3_CHANNEL0_MASK (1 << 11)
00028 #define IMAGE_SELECTION_CAMERA4_CHANNEL0_MASK (1 << 7)
00029 #define IMAGE_SELECTION_CAMERA5_CHANNEL0_MASK (1 << 3)
00030 
00031 using std::string;
00032 
00033 using cv::Mat;
00034 
00035 using nifti::dc1394::Camera;
00036 using nifti::dc1394::CameraContext;
00037 using nifti::dc1394::CameraException;
00038 using nifti::dc1394::LadybugCamera;
00039 
00040 void sigintHandler(int sig);
00041 void printDuration(char* message, tms t1, long r1);
00042 
00043 namespace {
00044 bool halt = false;
00045 }
00046 
00047 int main(int argc, char **argv) {
00048 
00049   signal(SIGINT, sigintHandler);
00050 
00051   std::string winName = "ladybug_image";
00052   cv::namedWindow(winName);
00053 //  cv::startWindowThread();
00054   cvStartWindowThread();
00055 
00056   CameraContext context;
00057   LadybugCamera camera = context.getLadybugCamera(10095209);
00058   try {
00059     //  camera.resetBus();
00060     camera.reset();
00061     //  camera.setup();
00062     camera.setOperationMode(DC1394_OPERATION_MODE_1394B);
00063     camera.setIsoSpeed(DC1394_ISO_SPEED_800);
00064     camera.setVideoMode(DC1394_VIDEO_MODE_FORMAT7_0);
00065     int fullHeight = 7392;
00066     int imageHeight = fullHeight / 6;
00067     int cam = 0;
00068     //  camera.setFormat7Roi(DC1394_VIDEO_MODE_FORMAT7_0, DC1394_COLOR_CODING_RAW8, 9792, 0, 0, 1616, 7392);
00069     //  camera.setFormat7Roi(DC1394_VIDEO_MODE_FORMAT7_0, DC1394_COLOR_CODING_RAW8, 8192, 0, cam * imageHeight, 1616, imageHeight);
00070     //    camera.setFormat7Roi(DC1394_VIDEO_MODE_FORMAT7_0, DC1394_COLOR_CODING_RAW8, 9792, 0, 0, 1616, 2 * imageHeight);
00071     camera.setFormat7Roi(DC1394_VIDEO_MODE_FORMAT7_0, DC1394_COLOR_CODING_RAW8, 9792, 0, 0, 1616, imageHeight);
00072 
00073     //    camera.setControlRegister(IMAGE_SELECTION_REGISTER, (1 << 7) | (1 << 3));
00074     //    camera.setControlRegister(IMAGE_SELECTION_REGISTER, 0xf);
00075     //    camera.setControlRegister(IMAGE_SELECTION_REGISTER, (1 << 3));
00076     //    camera.setControlRegister(IMAGE_SELECTION_REGISTER, (1 << 7));
00077 
00078 //    camera.setImagesSelected(LadybugCamera::CAMERA_5);
00079 
00080     uint32_t imageSelectionValue = camera.getControlRegister(IMAGE_SELECTION_REGISTER);
00081     printf("Image selection presence: %u\n", (imageSelectionValue & (1 << 31)) >> 31);
00082 
00083     int iCamera = 0;
00084     int iBayerChannel = 0;
00085     for (int offset = 23; offset >= 0; offset--) {
00086       printf("Image selection: camera %d: bayer channel %d: %u\n", iCamera, iBayerChannel, (imageSelectionValue & (1
00087           << offset)) >> offset);
00088       iBayerChannel++;
00089       if (iBayerChannel > 3) {
00090         iCamera++;
00091         iBayerChannel = 0;
00092       }
00093     }
00094 
00095     printf("Format 7 color coding: %d.\n", camera.getFormat7ColorCoding());
00096     printf("Format 7 color filter: %d.\n", camera.getFormat7ColorFilter());
00097     printf("Format 7 frame interval: %f.\n", camera.getFormat7FrameInterval());
00098     printf("Format 7 packets per frame: %u.\n", camera.getFormat7PacketsPerFrame());
00099     printf("Format 7 packet size: %u.\n", camera.getFormat7PacketSize());
00100     printf("Format 7 recommended packet size: %u.\n", camera.getFormat7RecommendedPacketSize());
00101 
00102     camera.setupCapture();
00103     camera.startVideoTransmission();
00104 
00105     struct tms t1;
00106     long r1;
00107 
00108     int iFrame = 0;
00109     Mat frame;
00110     Mat small;
00111     while (!halt) {
00112       // Cycle through cameras.
00113       switch (iFrame % 50) {
00114       case 0:
00115         camera.setSelectedImages(LadybugCamera::CAMERA_0);
00116         break;
00117       case 10:
00118         camera.setSelectedImages(LadybugCamera::CAMERA_1);
00119         break;
00120       case 20:
00121         camera.setSelectedImages(LadybugCamera::CAMERA_2);
00122         break;
00123       case 30:
00124         camera.setSelectedImages(LadybugCamera::CAMERA_3);
00125         break;
00126       case 40:
00127         camera.setSelectedImages(LadybugCamera::CAMERA_4);
00128         break;
00129       }
00130 
00131       r1 = times(&t1);
00132       camera.captureColorMat(frame, true);
00133       printDuration("Frame capture:     ", t1, r1);
00134 
00135       r1 = times(&t1);
00136       cv::resize(frame, small, cv::Size(), 0.25, 0.25, CV_INTER_NN);
00137       printDuration("Image resize:      ", t1, r1);
00138 
00139       r1 = times(&t1);
00140       cv::imshow(winName, small);
00141       printDuration("Image display:     ", t1, r1);
00142 
00143       iFrame++;
00144     }
00145   } catch (...) {
00146   }
00147 
00148   camera.stopVideoTransmission();
00149   camera.stopCapture();
00150   camera.releaseAll();
00151 
00152 //  cv::destroyWindow(winName);
00153   cvDestroyWindow(winName.data());
00154 }
00155 
00156 void sigintHandler(int sig) {
00157   printf("Signal %d received. Halting...\n", sig);
00158   halt = true;
00159 }
00160 
00161 void printDuration(char* message, tms t1, long r1) {
00162   struct tms t2;
00163   long r2;
00164   r2 = times(&t2);
00165 
00166   printf("%s", message);
00167   printf("user = %1.2f, ", ((float) (t2.tms_utime - t1.tms_utime)) / HZ);
00168   printf("system = %1.2f, ", ((float) (t2.tms_stime - t1.tms_stime)) / HZ);
00169   printf("real = %1.2f\n", ((float) (r2 - r1)) / HZ);
00170 }
 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