Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "CapturePluginCmu.h"
00025
00026 #include <sstream>
00027
00028 namespace alvar {
00029 namespace plugins {
00030
00031 CaptureCmu::CaptureCmu(const CaptureDevice captureDevice)
00032 : Capture(captureDevice)
00033 , mCamera(new C1394Camera())
00034 , mChannels(-1)
00035 , mReturnFrame(NULL)
00036 {
00037 }
00038
00039 CaptureCmu::~CaptureCmu()
00040 {
00041 stop();
00042 delete mCamera;
00043 }
00044
00045 bool CaptureCmu::start()
00046 {
00047 if (isCapturing()) {
00048 return isCapturing();
00049 }
00050
00051 if (mCamera->CheckLink() != CAM_SUCCESS) {
00052 return false;
00053 }
00054
00055 int numberCameras = mCamera->GetNumberCameras();
00056 bool cameraSelected = false;
00057 for (int i = 0; i < numberCameras; i++) {
00058 mCamera->SelectCamera(i);
00059 LARGE_INTEGER uniqueId;
00060 mCamera->GetCameraUniqueID(&uniqueId);
00061 std::stringstream convert;
00062 convert << std::hex << uniqueId.HighPart << uniqueId.LowPart;
00063 if (captureDevice().id().compare(convert.str()) == 0) {
00064 cameraSelected = true;
00065 break;
00066 }
00067 }
00068
00069 if (!cameraSelected) {
00070 return false;
00071 }
00072
00073 if (mCamera->InitCamera(true) != CAM_SUCCESS) {
00074 return false;
00075 }
00076
00077
00078 if (mCamera->HasVideoMode(2, 4)) {
00079 if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
00080 if (mCamera->SetVideoMode(4) != CAM_SUCCESS) return false;
00081 mChannels = 3;
00082 }
00083 else if (mCamera->HasVideoMode(2, 1)) {
00084 if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
00085 if (mCamera->SetVideoMode(1) != CAM_SUCCESS) return false;
00086 mChannels = 3;
00087 }
00088 else if (mCamera->HasVideoMode(1, 4)) {
00089 if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
00090 if (mCamera->SetVideoMode(4) != CAM_SUCCESS) return false;
00091 mChannels = 3;
00092 }
00093 else if (mCamera->HasVideoMode(1, 1)) {
00094 if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
00095 if (mCamera->SetVideoMode(1) != CAM_SUCCESS) return false;
00096 mChannels = 3;
00097 }
00098 else if (mCamera->HasVideoMode(0, 4)) {
00099 if (mCamera->SetVideoFormat(0) != CAM_SUCCESS) return false;
00100 if (mCamera->SetVideoMode(4) != CAM_SUCCESS) return false;
00101 mChannels = 3;
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 }
00135 else if (mCamera->HasVideoMode(2, 5)) {
00136 if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
00137 if (mCamera->SetVideoMode(5) != CAM_SUCCESS) return false;
00138 mChannels = 1;
00139 }
00140 else if (mCamera->HasVideoMode(2, 2)) {
00141 if (mCamera->SetVideoFormat(2) != CAM_SUCCESS) return false;
00142 if (mCamera->SetVideoMode(2) != CAM_SUCCESS) return false;
00143 mChannels = 1;
00144 }
00145 else if (mCamera->HasVideoMode(1, 5)) {
00146 if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
00147 if (mCamera->SetVideoMode(5) != CAM_SUCCESS) return false;
00148 mChannels = 1;
00149 }
00150 else if (mCamera->HasVideoMode(1, 2)) {
00151 if (mCamera->SetVideoFormat(1) != CAM_SUCCESS) return false;
00152 if (mCamera->SetVideoMode(2) != CAM_SUCCESS) return false;
00153 mChannels = 1;
00154 }
00155 else if (mCamera->HasVideoMode(0, 5)) {
00156 if (mCamera->SetVideoFormat(0) != CAM_SUCCESS) return false;
00157 if (mCamera->SetVideoMode(5) != CAM_SUCCESS) return false;
00158 mChannels = 1;
00159 }
00160 else {
00161 return false;
00162 }
00163
00164 mCamera->GetVideoFrameDimensions(&mXResolution, &mYResolution);
00165 mReturnFrame = cvCreateImage(cvSize(mXResolution, mYResolution), IPL_DEPTH_8U, mChannels);
00166 mCamera->StartImageAcquisitionEx(6, 1, ACQ_START_VIDEO_STREAM);
00167 mIsCapturing = true;
00168
00169 return isCapturing();
00170 }
00171
00172 void CaptureCmu::stop()
00173 {
00174 if (isCapturing()) {
00175 mCamera->StopImageAcquisition();
00176 cvReleaseImage(&mReturnFrame);
00177 mIsCapturing = false;
00178 }
00179 }
00180
00181 IplImage *CaptureCmu::captureImage()
00182 {
00183 if (!isCapturing()) {
00184 return NULL;
00185 }
00186
00187 if (mCamera->AcquireImageEx(false, NULL) == CAM_SUCCESS) {
00188 unsigned long length = mReturnFrame->widthStep * mYResolution;
00189 memcpy(mReturnFrame->imageData, mCamera->GetRawData(&length), length);
00190 }
00191 return mReturnFrame;
00192 }
00193
00194 bool CaptureCmu::showSettingsDialog()
00195 {
00196 CameraControlDialog(NULL, mCamera, true);
00197 return true;
00198 }
00199
00200 std::string CaptureCmu::SerializeId()
00201 {
00202 return "CaptureCmu";
00203 }
00204
00205 bool CaptureCmu::Serialize(Serialization *serialization)
00206 {
00207 if (!mCamera) {
00208 return false;
00209 }
00210
00211 unsigned short value;
00212 if (serialization->IsInput()) {
00213 if (!serialization->Serialize(value, "Gain")) return false;
00214 mCamera->GetCameraControl(FEATURE_GAIN)->SetAutoMode(false);
00215 mCamera->GetCameraControl(FEATURE_GAIN)->SetValue(value);
00216
00217 if (!serialization->Serialize(value, "AutoExposure")) return false;
00218 mCamera->GetCameraControl(FEATURE_AUTO_EXPOSURE)->SetAutoMode(false);
00219 mCamera->GetCameraControl(FEATURE_AUTO_EXPOSURE)->SetValue(value);
00220
00221 if (!serialization->Serialize(value, "Shutter")) return false;
00222 mCamera->GetCameraControl(FEATURE_SHUTTER)->SetAutoMode(false);
00223 mCamera->GetCameraControl(FEATURE_SHUTTER)->SetValue(value);
00224
00225 if (!serialization->Serialize(value, "Brightness")) return false;
00226 mCamera->GetCameraControl(FEATURE_BRIGHTNESS)->SetAutoMode(false);
00227 mCamera->GetCameraControl(FEATURE_BRIGHTNESS)->SetValue(value);
00228
00229 if (!serialization->Serialize(value, "Gamma")) return false;
00230 mCamera->GetCameraControl(FEATURE_GAMMA)->SetAutoMode(false);
00231 mCamera->GetCameraControl(FEATURE_GAMMA)->SetValue(value);
00232 } else {
00233 mCamera->GetCameraControl(FEATURE_GAIN)->GetValue(&value);
00234 if (!serialization->Serialize(value, "Gain")) return false;
00235
00236 mCamera->GetCameraControl(FEATURE_AUTO_EXPOSURE)->GetValue(&value);
00237 if (!serialization->Serialize(value, "AutoExposure")) return false;
00238
00239 mCamera->GetCameraControl(FEATURE_SHUTTER)->GetValue(&value);
00240 if (!serialization->Serialize(value, "Shutter")) return false;
00241
00242 mCamera->GetCameraControl(FEATURE_BRIGHTNESS)->GetValue(&value);
00243 if (!serialization->Serialize(value, "Brightness")) return false;
00244
00245 mCamera->GetCameraControl(FEATURE_GAMMA)->GetValue(&value);
00246 if (!serialization->Serialize(value, "Gamma")) return false;
00247 }
00248 return true;
00249 }
00250
00251 CapturePluginCmu::CapturePluginCmu(const std::string &captureType)
00252 : CapturePlugin(captureType)
00253 {
00254 }
00255
00256 CapturePluginCmu::~CapturePluginCmu()
00257 {
00258 }
00259
00260 CapturePlugin::CaptureDeviceVector CapturePluginCmu::enumerateDevices()
00261 {
00262 CaptureDeviceVector devices;
00263
00264 C1394Camera camera;
00265 if (camera.CheckLink() != CAM_SUCCESS) {
00266 return devices;
00267 }
00268
00269 int numberCameras = camera.GetNumberCameras();
00270 for (int i = 0; i < numberCameras; i++) {
00271 camera.SelectCamera(i);
00272 LARGE_INTEGER uniqueId;
00273 camera.GetCameraUniqueID(&uniqueId);
00274 std::stringstream convert;
00275 convert << std::hex << uniqueId.HighPart << uniqueId.LowPart;
00276 std::stringstream description;
00277 char buffer[500];
00278 camera.GetCameraVendor(buffer, 500);
00279 description << buffer << " ";
00280 camera.GetCameraName(buffer, 500);
00281 description << buffer;
00282 CaptureDevice captureDevice(mCaptureType, convert.str(), description.str());
00283 devices.push_back(captureDevice);
00284 }
00285
00286 return devices;
00287 }
00288
00289 Capture *CapturePluginCmu::createCapture(const CaptureDevice captureDevice)
00290 {
00291 return new CaptureCmu(captureDevice);
00292 }
00293
00294 void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin)
00295 {
00296 capturePlugin = new CapturePluginCmu(captureType);
00297 }
00298
00299 }
00300 }