CapturePluginPtgrey.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
00003  *
00004  * Copyright 2007-2012 VTT Technical Research Centre of Finland
00005  *
00006  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
00007  *          <http://www.vtt.fi/multimedia/alvar.html>
00008  *
00009  * ALVAR is free software; you can redistribute it and/or modify it under the
00010  * terms of the GNU Lesser General Public License as published by the Free
00011  * Software Foundation; either version 2.1 of the License, or (at your option)
00012  * any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful, but WITHOUT
00015  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00017  * for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with ALVAR; if not, see
00021  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
00022  */
00023 
00024 #include "CapturePluginPtgrey.h"
00025 #include <../../FlyCapture2/include/Camera.h>
00026 #include <../../FlyCapture2/include/Image.h>
00027 #include <../../FlyCapture2/include/Error.h>
00028 #include <../../FlyCapture2/include/BusManager.h>
00029 
00030 #include <sstream>
00031 
00032 using namespace std;
00033 
00034 namespace alvar {
00035 namespace plugins {
00036 
00037 CapturePtgrey::CapturePtgrey(const CaptureDevice captureDevice)
00038     : Capture(captureDevice)
00039     , mCamera(new FlyCapture2::Camera)
00040     , mImage(new FlyCapture2::Image)
00041     , mChannels(-1)
00042     , mReturnFrame(NULL)
00043 {
00044 }
00045 
00046 CapturePtgrey::~CapturePtgrey()
00047 {
00048     stop();
00049     delete mCamera;
00050     delete mImage;
00051 }
00052 
00053 bool CapturePtgrey::start()
00054 {
00055     if (isCapturing()) {
00056         return isCapturing();
00057     }
00058     
00059     stringstream id(captureDevice().id());
00060     id.setf(ios_base::hex, ios_base::basefield);
00061     id >> mGUID.value[0]; id.get();
00062     id >> mGUID.value[1]; id.get();
00063     id >> mGUID.value[2]; id.get();
00064     id >> mGUID.value[3];
00065 
00066     if (mCamera->Connect(&mGUID) != FlyCapture2::PGRERROR_OK) {
00067         return false;
00068     }
00069 
00070     FlyCapture2::VideoMode videoMode;
00071     FlyCapture2::FrameRate frameRate;
00072     if (mCamera->GetVideoModeAndFrameRate (&videoMode, &frameRate) != FlyCapture2::PGRERROR_OK) {
00073         return false;
00074     }
00075     
00076     if (videoMode == FlyCapture2::VIDEOMODE_640x480RGB) {
00077       mChannels = 3;
00078       mXResolution = 640;
00079       mYResolution = 480;
00080     
00081     } else if (videoMode == FlyCapture2::VIDEOMODE_640x480Y8) {
00082       mChannels = 1;
00083       mXResolution = 640;
00084       mYResolution = 480;
00085     
00086     } else if (videoMode == FlyCapture2::VIDEOMODE_800x600RGB) {
00087       mChannels = 3;
00088       mXResolution = 800;
00089       mYResolution = 600;
00090     
00091     } else if (videoMode == FlyCapture2::VIDEOMODE_800x600Y8) {
00092       mChannels = 1;
00093       mXResolution = 800;
00094       mYResolution = 600;
00095     
00096     } else if (videoMode == FlyCapture2::VIDEOMODE_1024x768RGB) {
00097       mChannels = 3;
00098       mXResolution = 1024;
00099       mYResolution = 768;
00100     
00101     } else if (videoMode == FlyCapture2::VIDEOMODE_1024x768Y8) {
00102       mChannels = 1;
00103       mXResolution = 1024;
00104       mYResolution = 768;
00105     
00106     } else if (videoMode == FlyCapture2::VIDEOMODE_1280x960RGB) {
00107       mChannels = 3;
00108       mXResolution = 1280;
00109       mYResolution = 960;
00110     
00111     } else if (videoMode == FlyCapture2::VIDEOMODE_1280x960Y8) {
00112       mChannels = 1;
00113       mXResolution = 1280;
00114       mYResolution = 960;
00115     
00116     } else if (videoMode == FlyCapture2::VIDEOMODE_1600x1200RGB) {
00117       mChannels = 3;
00118       mXResolution = 1600;
00119       mYResolution = 1200;
00120     
00121     } else if (videoMode == FlyCapture2::VIDEOMODE_1600x1200Y8) {
00122       mChannels = 1;
00123       mXResolution = 1600;
00124       mYResolution = 1200;
00125     
00126     } else {
00127         return false;
00128     }
00129 
00130     mReturnFrame = cvCreateImage(cvSize(mXResolution, mYResolution), IPL_DEPTH_8U, mChannels);
00131     if (mCamera->StartCapture() != FlyCapture2::PGRERROR_OK) {
00132         return false;
00133     }
00134     mIsCapturing = true;
00135     return isCapturing();
00136 }
00137 
00138 void CapturePtgrey::stop()
00139 {
00140     if (isCapturing()) {
00141         mCamera->StopCapture();
00142         cvReleaseImage(&mReturnFrame);
00143     }
00144 }
00145 
00146 IplImage *CapturePtgrey::captureImage()
00147 {
00148     if (!isCapturing()) {
00149         return NULL;
00150     }
00151 
00152     if (mCamera->RetrieveBuffer(mImage) == FlyCapture2::PGRERROR_OK) {
00153         unsigned long length = mReturnFrame->widthStep * mYResolution;
00154         memcpy(mReturnFrame->imageData, mImage->GetData(), length);
00155     }
00156     return mReturnFrame;
00157 }
00158 
00159 bool CapturePtgrey::showSettingsDialog()
00160 {
00161     return false;
00162 }
00163 
00164 string CapturePtgrey::SerializeId()
00165 {
00166     return "CapturePtgrey";
00167 }
00168 
00169 bool CapturePtgrey::Serialize(Serialization *serialization)
00170 {
00171     return false;
00172 }
00173 
00174 CapturePluginPtgrey::CapturePluginPtgrey(const string &captureType)
00175     : CapturePlugin(captureType)
00176 {
00177 }
00178 
00179 CapturePluginPtgrey::~CapturePluginPtgrey()
00180 {
00181 }
00182 
00183 CapturePlugin::CaptureDeviceVector CapturePluginPtgrey::enumerateDevices()
00184 {
00185     CaptureDeviceVector devices;
00186 
00187     FlyCapture2::BusManager bus;
00188     if (bus.RescanBus() != FlyCapture2::PGRERROR_OK) {
00189         return devices;
00190     }
00191 
00192     unsigned int numberCameras = 0;
00193     bus.GetNumOfCameras(&numberCameras);
00194     
00195     for (unsigned int i = 0; i < numberCameras; i++) {
00196         FlyCapture2::PGRGuid guid;
00197         bus.GetCameraFromIndex(i, &guid);
00198         stringstream convert;
00199         convert << hex << guid.value[0];
00200         convert << "_" << hex << guid.value[1];
00201         convert << "_" << hex << guid.value[2];
00202         convert << "_" << hex << guid.value[3];
00203         stringstream description;
00204         FlyCapture2::Camera camera;
00205         if (camera.Connect(&guid) != FlyCapture2::PGRERROR_OK) continue;
00206         FlyCapture2::CameraInfo info;
00207         if (camera.GetCameraInfo (&info) != FlyCapture2::PGRERROR_OK) continue;
00208         description << info.vendorName << " ";
00209         description << info.modelName;
00210         CaptureDevice captureDevice(mCaptureType, convert.str(), description.str());
00211         devices.push_back(captureDevice);
00212     }
00213 
00214     return devices;
00215 }
00216 
00217 Capture *CapturePluginPtgrey::createCapture(const CaptureDevice captureDevice)
00218 {
00219     return new CapturePtgrey(captureDevice);
00220 }
00221 
00222 void registerPlugin(const string &captureType, alvar::CapturePlugin *&capturePlugin)
00223 {
00224     capturePlugin = new CapturePluginPtgrey(captureType);
00225 }
00226 
00227 } // namespace plugins
00228 } // namespace alvar


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Sun Oct 5 2014 22:16:26