CapturePluginPtgrey.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #include "CapturePluginPtgrey.h"
25 #include <../../FlyCapture2/include/Camera.h>
26 #include <../../FlyCapture2/include/Image.h>
27 #include <../../FlyCapture2/include/Error.h>
28 #include <../../FlyCapture2/include/BusManager.h>
29 
30 #include <sstream>
31 
32 using namespace std;
33 
34 namespace alvar {
35 namespace plugins {
36 
37 CapturePtgrey::CapturePtgrey(const CaptureDevice captureDevice)
38  : Capture(captureDevice)
39  , mCamera(new FlyCapture2::Camera)
40  , mImage(new FlyCapture2::Image)
41  , mChannels(-1)
42  , mReturnFrame(NULL)
43 {
44 }
45 
47 {
48  stop();
49  delete mCamera;
50  delete mImage;
51 }
52 
54 {
55  if (isCapturing()) {
56  return isCapturing();
57  }
58 
59  stringstream id(captureDevice().id());
60  id.setf(ios_base::hex, ios_base::basefield);
61  id >> mGUID.value[0]; id.get();
62  id >> mGUID.value[1]; id.get();
63  id >> mGUID.value[2]; id.get();
64  id >> mGUID.value[3];
65 
66  if (mCamera->Connect(&mGUID) != FlyCapture2::PGRERROR_OK) {
67  return false;
68  }
69 
70  FlyCapture2::VideoMode videoMode;
71  FlyCapture2::FrameRate frameRate;
72  if (mCamera->GetVideoModeAndFrameRate (&videoMode, &frameRate) != FlyCapture2::PGRERROR_OK) {
73  return false;
74  }
75 
76  if (videoMode == FlyCapture2::VIDEOMODE_640x480RGB) {
77  mChannels = 3;
78  mXResolution = 640;
79  mYResolution = 480;
80 
81  } else if (videoMode == FlyCapture2::VIDEOMODE_640x480Y8) {
82  mChannels = 1;
83  mXResolution = 640;
84  mYResolution = 480;
85 
86  } else if (videoMode == FlyCapture2::VIDEOMODE_800x600RGB) {
87  mChannels = 3;
88  mXResolution = 800;
89  mYResolution = 600;
90 
91  } else if (videoMode == FlyCapture2::VIDEOMODE_800x600Y8) {
92  mChannels = 1;
93  mXResolution = 800;
94  mYResolution = 600;
95 
96  } else if (videoMode == FlyCapture2::VIDEOMODE_1024x768RGB) {
97  mChannels = 3;
98  mXResolution = 1024;
99  mYResolution = 768;
100 
101  } else if (videoMode == FlyCapture2::VIDEOMODE_1024x768Y8) {
102  mChannels = 1;
103  mXResolution = 1024;
104  mYResolution = 768;
105 
106  } else if (videoMode == FlyCapture2::VIDEOMODE_1280x960RGB) {
107  mChannels = 3;
108  mXResolution = 1280;
109  mYResolution = 960;
110 
111  } else if (videoMode == FlyCapture2::VIDEOMODE_1280x960Y8) {
112  mChannels = 1;
113  mXResolution = 1280;
114  mYResolution = 960;
115 
116  } else if (videoMode == FlyCapture2::VIDEOMODE_1600x1200RGB) {
117  mChannels = 3;
118  mXResolution = 1600;
119  mYResolution = 1200;
120 
121  } else if (videoMode == FlyCapture2::VIDEOMODE_1600x1200Y8) {
122  mChannels = 1;
123  mXResolution = 1600;
124  mYResolution = 1200;
125 
126  } else {
127  return false;
128  }
129 
130  mReturnFrame = cvCreateImage(cvSize(mXResolution, mYResolution), IPL_DEPTH_8U, mChannels);
131  if (mCamera->StartCapture() != FlyCapture2::PGRERROR_OK) {
132  return false;
133  }
134  mIsCapturing = true;
135  return isCapturing();
136 }
137 
139 {
140  if (isCapturing()) {
141  mCamera->StopCapture();
142  cvReleaseImage(&mReturnFrame);
143  }
144 }
145 
147 {
148  if (!isCapturing()) {
149  return NULL;
150  }
151 
152  if (mCamera->RetrieveBuffer(mImage) == FlyCapture2::PGRERROR_OK) {
153  unsigned long length = mReturnFrame->widthStep * mYResolution;
154  memcpy(mReturnFrame->imageData, mImage->GetData(), length);
155  }
156  return mReturnFrame;
157 }
158 
160 {
161  return false;
162 }
163 
165 {
166  return "CapturePtgrey";
167 }
168 
170 {
171  return false;
172 }
173 
175  : CapturePlugin(captureType)
176 {
177 }
178 
180 {
181 }
182 
184 {
185  CaptureDeviceVector devices;
186 
187  FlyCapture2::BusManager bus;
188  if (bus.RescanBus() != FlyCapture2::PGRERROR_OK) {
189  return devices;
190  }
191 
192  unsigned int numberCameras = 0;
193  bus.GetNumOfCameras(&numberCameras);
194 
195  for (unsigned int i = 0; i < numberCameras; i++) {
196  FlyCapture2::PGRGuid guid;
197  bus.GetCameraFromIndex(i, &guid);
198  stringstream convert;
199  convert << hex << guid.value[0];
200  convert << "_" << hex << guid.value[1];
201  convert << "_" << hex << guid.value[2];
202  convert << "_" << hex << guid.value[3];
203  stringstream description;
204  FlyCapture2::Camera camera;
205  if (camera.Connect(&guid) != FlyCapture2::PGRERROR_OK) continue;
206  FlyCapture2::CameraInfo info;
207  if (camera.GetCameraInfo (&info) != FlyCapture2::PGRERROR_OK) continue;
208  description << info.vendorName << " ";
209  description << info.modelName;
210  CaptureDevice captureDevice(mCaptureType, convert.str(), description.str());
211  devices.push_back(captureDevice);
212  }
213 
214  return devices;
215 }
216 
218 {
219  return new CapturePtgrey(captureDevice);
220 }
221 
222 void registerPlugin(const string &captureType, alvar::CapturePlugin *&capturePlugin)
223 {
224  capturePlugin = new CapturePluginPtgrey(captureType);
225 }
226 
227 } // namespace plugins
228 } // namespace alvar
Main ALVAR namespace.
Definition: Alvar.h:174
std::string SerializeId()
The identification of the class for serialization.
Implementation of Capture interface for Ptgrey plugin.
void stop()
Stops the camera capture.
bool Serialize(Serialization *serialization)
Performs serialization of the class members and configuration.
IplImage * captureImage()
Capture one image from the camera.
CapturePluginPtgrey(const std::string &captureType)
Constructor.
CaptureDevice captureDevice()
The camera information associated to this capture object.
Definition: Capture.h:70
CaptureDeviceVector enumerateDevices()
Enumerate capture devices currently available.
unsigned long mXResolution
Definition: Capture.h:181
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
Definition: Camera.h:82
std::string mCaptureType
Definition: CapturePlugin.h:83
CaptureDevice holder for camera information.
Definition: CaptureDevice.h:44
bool start()
Starts the camera capture.
void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin)
CapturePlugin interface that plugins must implement.
Definition: CapturePlugin.h:44
Camera * camera
bool showSettingsDialog()
Show the settings dialog of the camera.
Capture * createCapture(const CaptureDevice captureDevice)
Create Capture class. Transfers onwership to the caller.
bool isCapturing()
Test if the camera was properly initialized.
Definition: Capture.h:85
This file implements a capture plugin based on Ptgrey.
Capture interface that plugins must implement.
Definition: Capture.h:46
void convert(const A &a, B &b)
Class for serializing class content to/from file or std::iostream.
Definition: Util.h:352
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
bool mIsCapturing
Definition: Capture.h:183
std::vector< CaptureDevice > CaptureDeviceVector
Vector of CaptureDevices.
Definition: CapturePlugin.h:60
unsigned long mYResolution
Definition: Capture.h:182


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Thu Jun 6 2019 19:27:23