CapturePluginCmu.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 "CapturePluginCmu.h"
25 
26 #include <sstream>
27 
28 namespace alvar {
29 namespace plugins {
30 
32  : Capture(captureDevice)
33  , mCamera(new C1394Camera())
34  , mChannels(-1)
35  , mReturnFrame(NULL)
36 {
37 }
38 
40 {
41  stop();
42  delete mCamera;
43 }
44 
46 {
47  if (isCapturing()) {
48  return isCapturing();
49  }
50 
51  if (mCamera->CheckLink() != CAM_SUCCESS) {
52  return false;
53  }
54 
55  int numberCameras = mCamera->GetNumberCameras();
56  bool cameraSelected = false;
57  for (int i = 0; i < numberCameras; i++) {
58  mCamera->SelectCamera(i);
59  LARGE_INTEGER uniqueId;
60  mCamera->GetCameraUniqueID(&uniqueId);
61  std::stringstream convert;
62  convert << std::hex << uniqueId.HighPart << uniqueId.LowPart;
63  if (captureDevice().id().compare(convert.str()) == 0) {
64  cameraSelected = true;
65  break;
66  }
67  }
68 
69  if (!cameraSelected) {
70  return false;
71  }
72 
73  if (mCamera->InitCamera(true) != CAM_SUCCESS) {
74  return false;
75  }
76 
77  // TODO: this needs to be parameterized somehow
78  if (mCamera->HasVideoMode(2, 4)) { // 1600x1200rgb
79  if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
80  if (mCamera->SetVideoMode(4) != CAM_SUCCESS) return false;
81  mChannels = 3;
82  }
83  else if (mCamera->HasVideoMode(2, 1)) { // 1280x960rgb
84  if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
85  if (mCamera->SetVideoMode(1) != CAM_SUCCESS) return false;
86  mChannels = 3;
87  }
88  else if (mCamera->HasVideoMode(1, 4)) { // 1024x768rgb
89  if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
90  if (mCamera->SetVideoMode(4) != CAM_SUCCESS) return false;
91  mChannels = 3;
92  }
93  else if (mCamera->HasVideoMode(1, 1)) { // 800x600rgb
94  if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
95  if (mCamera->SetVideoMode(1) != CAM_SUCCESS) return false;
96  mChannels = 3;
97  }
98  else if (mCamera->HasVideoMode(0, 4)) { // 640x480rgb
99  if (mCamera->SetVideoFormat(0) != CAM_SUCCESS) return false;
100  if (mCamera->SetVideoMode(4) != CAM_SUCCESS) return false;
101  mChannels = 3;
102  /* // TODO: also support YUV422
103  }
104  else if (mCamera->HasVideoMode(2, 3)) { // 1600x1200yuv422
105  if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
106  if (mCamera->SetVideoMode(3) != CAM_SUCCESS) return false;
107  mChannels = 2;
108  }
109  else if (mCamera->HasVideoMode(2, 0)) { // 1280x960yuv422
110  if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
111  if (mCamera->SetVideoMode(0) != CAM_SUCCESS) return false;
112  mChannels = 2;
113  }
114  else if (mCamera->HasVideoMode(1, 3)) { // 1024x768yuv422
115  if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
116  if (mCamera->SetVideoMode(3) != CAM_SUCCESS) return false;
117  mChannels = 2;
118  }
119  else if (mCamera->HasVideoMode(1, 0)) { // 800x600yuv422
120  if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
121  if (mCamera->SetVideoMode(0) != CAM_SUCCESS) return false;
122  mChannels = 2;
123  }
124  else if (mCamera->HasVideoMode(0, 3)) { // 640x480yuv422
125  if (mCamera->SetVideoFormat(0) != CAM_SUCCESS) return false;
126  if (mCamera->SetVideoMode(3) != CAM_SUCCESS) return false;
127  mChannels = 2;
128  }
129  else if (mCamera->HasVideoMode(0, 1)) { // 320x240yuv422
130  if (mCamera->SetVideoFormat(0) != CAM_SUCCESS) return false;
131  if (mCamera->SetVideoMode(1) != CAM_SUCCESS) return false;
132  mChannels = 2;
133  */
134  }
135  else if (mCamera->HasVideoMode(2, 5)) { // 1600x1200mono
136  if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
137  if (mCamera->SetVideoMode(5) != CAM_SUCCESS) return false;
138  mChannels = 1;
139  }
140  else if (mCamera->HasVideoMode(2, 2)) { // 1280x960mono
141  if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
142  if (mCamera->SetVideoMode(2) != CAM_SUCCESS) return false;
143  mChannels = 1;
144  }
145  else if (mCamera->HasVideoMode(1, 5)) { // 1024x768mono
146  if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
147  if (mCamera->SetVideoMode(5) != CAM_SUCCESS) return false;
148  mChannels = 1;
149  }
150  else if (mCamera->HasVideoMode(1, 2)) { // 800x600mono
151  if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
152  if (mCamera->SetVideoMode(2) != CAM_SUCCESS) return false;
153  mChannels = 1;
154  }
155  else if (mCamera->HasVideoMode(0, 5)) { // 640x480mono
156  if (mCamera->SetVideoFormat(0) != CAM_SUCCESS) return false;
157  if (mCamera->SetVideoMode(5) != CAM_SUCCESS) return false;
158  mChannels = 1;
159  }
160  else {
161  return false;
162  }
163 
164  mCamera->GetVideoFrameDimensions(&mXResolution, &mYResolution);
165  mReturnFrame = cvCreateImage(cvSize(mXResolution, mYResolution), IPL_DEPTH_8U, mChannels);
166  mCamera->StartImageAcquisitionEx(6, 1, ACQ_START_VIDEO_STREAM);
167  mIsCapturing = true;
168 
169  return isCapturing();
170 }
171 
173 {
174  if (isCapturing()) {
175  mCamera->StopImageAcquisition();
176  cvReleaseImage(&mReturnFrame);
177  mIsCapturing = false;
178  }
179 }
180 
182 {
183  if (!isCapturing()) {
184  return NULL;
185  }
186 
187  if (mCamera->AcquireImageEx(false, NULL) == CAM_SUCCESS) {
188  unsigned long length = mReturnFrame->widthStep * mYResolution;
189  memcpy(mReturnFrame->imageData, mCamera->GetRawData(&length), length);
190  }
191  return mReturnFrame;
192 }
193 
195 {
196  CameraControlDialog(NULL, mCamera, true);
197  return true;
198 }
199 
201 {
202  return "CaptureCmu";
203 }
204 
206 {
207  if (!mCamera) {
208  return false;
209  }
210 
211  unsigned short value;
212  if (serialization->IsInput()) {
213  if (!serialization->Serialize(value, "Gain")) return false;
214  mCamera->GetCameraControl(FEATURE_GAIN)->SetAutoMode(false);
215  mCamera->GetCameraControl(FEATURE_GAIN)->SetValue(value);
216 
217  if (!serialization->Serialize(value, "AutoExposure")) return false;
218  mCamera->GetCameraControl(FEATURE_AUTO_EXPOSURE)->SetAutoMode(false);
219  mCamera->GetCameraControl(FEATURE_AUTO_EXPOSURE)->SetValue(value);
220 
221  if (!serialization->Serialize(value, "Shutter")) return false;
222  mCamera->GetCameraControl(FEATURE_SHUTTER)->SetAutoMode(false);
223  mCamera->GetCameraControl(FEATURE_SHUTTER)->SetValue(value);
224 
225  if (!serialization->Serialize(value, "Brightness")) return false;
226  mCamera->GetCameraControl(FEATURE_BRIGHTNESS)->SetAutoMode(false);
227  mCamera->GetCameraControl(FEATURE_BRIGHTNESS)->SetValue(value);
228 
229  if (!serialization->Serialize(value, "Gamma")) return false;
230  mCamera->GetCameraControl(FEATURE_GAMMA)->SetAutoMode(false);
231  mCamera->GetCameraControl(FEATURE_GAMMA)->SetValue(value);
232  } else {
233  mCamera->GetCameraControl(FEATURE_GAIN)->GetValue(&value);
234  if (!serialization->Serialize(value, "Gain")) return false;
235 
236  mCamera->GetCameraControl(FEATURE_AUTO_EXPOSURE)->GetValue(&value);
237  if (!serialization->Serialize(value, "AutoExposure")) return false;
238 
239  mCamera->GetCameraControl(FEATURE_SHUTTER)->GetValue(&value);
240  if (!serialization->Serialize(value, "Shutter")) return false;
241 
242  mCamera->GetCameraControl(FEATURE_BRIGHTNESS)->GetValue(&value);
243  if (!serialization->Serialize(value, "Brightness")) return false;
244 
245  mCamera->GetCameraControl(FEATURE_GAMMA)->GetValue(&value);
246  if (!serialization->Serialize(value, "Gamma")) return false;
247  }
248  return true;
249 }
250 
251 CapturePluginCmu::CapturePluginCmu(const std::string &captureType)
252  : CapturePlugin(captureType)
253 {
254 }
255 
257 {
258 }
259 
261 {
262  CaptureDeviceVector devices;
263 
264  C1394Camera camera;
265  if (camera.CheckLink() != CAM_SUCCESS) {
266  return devices;
267  }
268 
269  int numberCameras = camera.GetNumberCameras();
270  for (int i = 0; i < numberCameras; i++) {
271  camera.SelectCamera(i);
272  LARGE_INTEGER uniqueId;
273  camera.GetCameraUniqueID(&uniqueId);
274  std::stringstream convert;
275  convert << std::hex << uniqueId.HighPart << uniqueId.LowPart;
276  std::stringstream description;
277  char buffer[500];
278  camera.GetCameraVendor(buffer, 500);
279  description << buffer << " ";
280  camera.GetCameraName(buffer, 500);
281  description << buffer;
282  CaptureDevice captureDevice(mCaptureType, convert.str(), description.str());
283  devices.push_back(captureDevice);
284  }
285 
286  return devices;
287 }
288 
290 {
291  return new CaptureCmu(captureDevice);
292 }
293 
294 void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin)
295 {
296  capturePlugin = new CapturePluginCmu(captureType);
297 }
298 
299 } // namespace plugins
300 } // namespace alvar
void stop()
Stops the camera capture.
Main ALVAR namespace.
Definition: Alvar.h:174
bool IsInput()
Method for checking if we are inputting or outputting. Can be used from your serializable class...
Definition: Util.h:448
CaptureDeviceVector enumerateDevices()
Enumerate capture devices currently available.
CaptureDevice captureDevice()
The camera information associated to this capture object.
Definition: Capture.h:70
bool start()
Starts the camera capture.
bool Serialize(Serialization *serialization)
Performs serialization of the class members and configuration.
unsigned long mXResolution
Definition: Capture.h:181
Capture * createCapture(const CaptureDevice captureDevice)
Create Capture class. Transfers onwership to the caller.
std::string mCaptureType
Definition: CapturePlugin.h:83
bool Serialize(int &data, const std::string &name)
Method for serializing &#39;int&#39; data element. Used from your serializable class.
Definition: Util.cpp:453
CaptureDevice holder for camera information.
Definition: CaptureDevice.h:44
bool showSettingsDialog()
Show the settings dialog of the camera.
void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin)
CapturePlugin interface that plugins must implement.
Definition: CapturePlugin.h:44
Camera * camera
CapturePluginCmu(const std::string &captureType)
Constructor.
CaptureCmu(const CaptureDevice captureDevice)
Constructor.
bool isCapturing()
Test if the camera was properly initialized.
Definition: Capture.h:85
std::string SerializeId()
The identification of the class for serialization.
Capture interface that plugins must implement.
Definition: Capture.h:46
IplImage * captureImage()
Capture one image from the camera.
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
Implementation of Capture interface for Cmu plugin.
This file implements a capture plugin based on Cmu.


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