Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ShowCamWxVideoSourceFactory.cpp
1 /*
2  * ShowCamWxVideoSourceFactory.cpp
3  *
4  * Created on: 11.02.2011
5  * Author: bravo
6  */
7 
8 #include <Tools/BIASShowCamWX/ShowCamWxVideoSourceFactory.hh>
9 
10 # include <Gui/VideoSource_Controller.hh>
11 #ifdef BIAS_HAVE_V4L
12 # include <VideoSource/VideoSource_V4L.hh>
13 #endif // BIAS_HAVE_V4L
14 
15 #ifdef BIAS_HAVE_DCAM
16 # include <Gui/VideoSource_Controller_XB3.hh>
17 # include <VideoSource/VideoSource_DCAM_BumbleBee.hh>
18 #endif // BIAS_HAVE_DCAM
19 
20 #ifdef BIAS_HAVE_PMD_PMDTec
21 # include <Gui/VideoSource_Controller_PMD.hh>
22 # include <VideoSource/VideoSource_PMD.hh>
23 #endif // BIAS_HAVE_PMD_PMDTec
24 
25 #ifdef BIAS_HAVE_PMD_PMDZess
26 # include <Gui/VideoSource_Controller_PMDZess.hh>
27 # include <VideoSource/VideoSource_PMDZess.hh>
28 #endif // BIAS_HAVE_PMD_PMDZess
29 
30 #ifdef BIAS_HAVE_SWISSRANGER
31 # include <Gui/VideoSource_Controller_SwissRanger.hh>
32 # include <VideoSource/VideoSource_SwissRanger.hh>
33 #endif
34 
35 #include <Gui/VideoSource_Controller_Kinect.hh>
36 
37 #ifdef BIAS_HAVE_KINECT
38 # include <VideoSource/VideoSource_Kinect.hh>
39 #endif
40 
41 #ifdef BIAS_HAVE_OPENNI
42 # include <VideoSource/VideoSource_OpenNI.hh>
43 #endif
44 
45 #ifdef BIAS_HAVE_KINECT2
46 # include <VideoSource/VideoSource_Kinect2.hh>
47 #endif
48 
49 #ifdef BIAS_HAVE_DSHOW
50 # include <VideoSource/VideoSource_DSHOW.hh>
51 #endif
52 
53 #ifdef BIAS_HAVE_UEYE
54 # include <VideoSource/VideoSource_uEye.hh>
55 #endif
56 
57 #include <sstream>
58 #include <VideoSource/VideoSource_Shm.hh>
59 #include <VideoSource/VideoSource_Net.hh>
60 
61 using namespace std;
62 
63 //redeclare static members
65 
66 namespace BIAS {
67 
68 ShowCamWxVideoSourceFactory::ShowCamWxVideoSourceFactory() {
69  Win32DCAMNumber_=0;
70 }
71 
72 ShowCamWxVideoSourceFactory::~ShowCamWxVideoSourceFactory() {
73 }
74 
75 VideoSource_Controller_Base* ShowCamWxVideoSourceFactory::
76 CreateController(CameraType type, VideoSource *cam, wxWindow *parent,
77  const std::string& title,
78  const wxPoint& pos,
79  const wxSize& size,
80  long style,
81  const wxString& name)
82 {
83  VideoSource_Controller_Base* controller = NULL;
84 
85  switch(type) {
86 #ifdef BIAS_HAVE_PMD_PMDZess
87  case PMDUSB:
88  controller = new VideoSource_Controller_PMDZess(cam, parent, "PMD Controller");
89  break;
90 #endif
91 #ifdef BIAS_HAVE_PMD_PMDTec
92  case PMD:
93  controller = new VideoSource_Controller_PMD(cam, parent, "PMD Controller");
94  break;
95 #endif
96 #ifdef BIAS_HAVE_SWISSRANGER
97  case SR:
98  controller = new VideoSource_Controller_SwissRanger(cam, parent, "SwissRanger Controller");
99  break;
100 #endif
101 #ifdef BIAS_HAVE_DCAM
102  case XB3:
103  controller = new VideoSource_Controller_XB3(cam, parent, "XB3 Controller");
104  break;
105  case DCAM:
106  controller = new VideoSource_Controller(cam, parent, "DCAM Controller");
107  break;
108 #endif
109 #ifdef BIAS_HAVE_V4L
110  case V4L:
111  controller = new VideoSource_Controller(cam, parent, "V4L");
112  double min, max;
113  dynamic_cast<VideoSource_V4L*>(cam)->GetBrightnessRange(min,max);
114  controller->SetBrightnessRange(min,max);
115  dynamic_cast<VideoSource_V4L*>(cam)->GetContrastRange(min,max);
116  controller->SetContrastRange(min,max);
117  break;
118 #endif
119  case KINECT:
120  controller = new VideoSource_Controller_Kinect(cam, parent, "Kinect (freenect) Controller");
121  break;
122  case OPENNI:
123  controller = new VideoSource_Controller_Kinect(cam, parent, "Kinect (openni) Controller");
124  break;
125  default: {
126  string thetitle = "Camera: "+title;
127  controller = new VideoSource_Controller(cam, parent, thetitle);
128  double min, max;
129  cam->GetBrightnessRange(min,max);
130  controller->SetBrightnessRange((unsigned)min,(unsigned)max);
131  cam->GetContrastRange(min,max);
132  controller->SetContrastRange((unsigned)min,(unsigned)max);
133  break;
134  }
135  }
136  return controller;
137 }
138 
139 VideoSource* ShowCamWxVideoSourceFactory::
140 CreateDCAM(bool firewireB, bool user_mode, int dcam_mode,
141  float fps, int Format7BpP, int Format7ColorMode,
142  Vector2<int> Format7LeftTop, Vector2<int> Format7WidthHeight)
143 {
144 
145 #ifdef BIAS_HAVE_DCAM
147  cam = new VideoSource_DCAM;
148  cam->SetDebugLevel(D_DCAM);
149  cam->SetFirewireB(firewireB);
150 
151  if(user_mode) {
152  dc1394video_mode_t mode = (dc1394video_mode_t)dcam_mode;
153 
154  // choose between normal mode and format 7
155  if (mode >= DC1394_VIDEO_MODE_FORMAT7_0) {
156  cam->SetFormat7(mode - DC1394_VIDEO_MODE_FORMAT7_MIN, Format7BpP,
157  (dc1394color_coding_t) Format7ColorMode);
158  cam->SetLeftTop(Format7LeftTop[0], Format7LeftTop[1]);
159  cam->SetSize(Format7WidthHeight[0], Format7WidthHeight[1]);
160  } else {
161  cam->SetModeAndFramerate(mode,fps);
162  }
163  }
164 
165  return cam;
166 #else
167  return NULL;
168 #endif
169 }
170 
171 VideoSource* ShowCamWxVideoSourceFactory::
172 CreatePMDZess(std::string bitfile)
173 {
174 #ifdef BIAS_HAVE_PMD_PMDZess
176  cam->SetBitFile(bitfile);
177  return cam;
178 #else
179  return NULL;
180 #endif
181 }
182 
183 VideoSource* ShowCamWxVideoSourceFactory::
184 CreateUEye()
185 {
186 #ifdef BIAS_HAVE_UEYE
187  VideoSource_uEye *cam = new VideoSource_uEye();
188  return cam;
189 #else
190  return NULL;
191 #endif
192 }
193 
194 VideoSource* ShowCamWxVideoSourceFactory::
195 CreateFromTypeIfSupported(int type)
196 {
197  return CreateFromTypeIfSupported((CameraType)type);
198 }
199 
200 VideoSource* ShowCamWxVideoSourceFactory::
201 CreateFromTypeIfSupported(CameraType type)
202 {
203  VideoSource* cam = NULL;
204  switch (type) {
205  case PMDSHM:
206 #ifdef BIAS_HAVE_TIFF
207 // cam = new VideoSource_ShmPMD;
208 #endif
209  case SHM: // SHM
210  cam = new VideoSource_Shm;
211  break;
212  case NET: // NET
213  cam = new VideoSource_Net;
214  break;
215  case SR:
216 #ifdef BIAS_HAVE_SWISSRANGER
217  cam = new VideoSource_SwissRanger;
218 #endif
219  break;
220  case KINECT:
221 #ifdef BIAS_HAVE_KINECT
222  cam = new VideoSource_Kinect;
223 #endif
224  break;
225  case OPENNI:
226 #ifdef BIAS_HAVE_OPENNI
227  cam = new VideoSource_OpenNI;
228 #endif
229  break;
230  case FREENECT2:
231 #ifdef BIAS_HAVE_KINECT2
232  cam = new VideoSource_Kinect2;
233 #endif
234  break;
235  default:
236  BIASERR("try specialized method for " << type << " camera");
237  break;
238  }
239  return cam;
240 }
241 
242 VideoSource* ShowCamWxVideoSourceFactory::
243 CreateV4L()
244 {
245  VideoSource *cam = NULL;
246 #ifdef BIAS_HAVE_V4L
247  cam = new VideoSource_V4L;
248 #endif
249 #ifdef BIAS_HAVE_DSHOW
250  cam = new VideoSource_DSHOW(false);
251  dynamic_cast<VideoSource_DSHOW*>(cam)->SetWaitForNew(true);
252 #endif
253  return cam;
254 }
255 
256 VideoSource* ShowCamWxVideoSourceFactory::
257 CreateBumbleBee()
258 {
259  VideoSource *cam = NULL;
260 
261 #ifdef BIAS_HAVE_DCAM
262 
263  cam = new VideoSource_DCAM_BumbleBee;
264  cam->SetDebugLevel(D_DCAM|D_DCAM_F7);
265 
266 #endif
267 
268  return cam;
269 }
270 
271 VideoSource* ShowCamWxVideoSourceFactory::
272 CreatePMD(string sourcePlugin,string procPlugin)
273 {
274  VideoSource* cam = NULL;
275 #ifdef BIAS_HAVE_PMD_PMDTec
276  cam = new VideoSource_PMD;
277  (dynamic_cast<VideoSource_PMD*>(cam))->SetSourcePlugin(sourcePlugin);
278  (dynamic_cast<VideoSource_PMD*>(cam))->SetProcessingPlugin(procPlugin);
279 #endif
280  return cam;
281 }
282 
283 int ShowCamWxVideoSourceFactory::
284 OpenDevice(int type, VideoSource* cam, std::string deviceName, int param)
285 {
286 
287  if (cam == NULL) return -1;
288 
289  switch (type) {
290 
291  case ShowCamWxVideoSourceFactory::XB3:
292  case ShowCamWxVideoSourceFactory::DCAM:
293  if (deviceName != "") {
294  cam->AddDebugLevel(D_DCAM);
295 
296  if (cam->OpenDevice(atoi(deviceName.c_str())) < 0)
297  return -1;
298  else{
299  cout<<"Camera number " << deviceName << " successfully opened"<<endl;
300  return 0;
301  }
302  } else {
303 #ifdef WIN32
304  // this does not work if not all cameras are dcam!
305  if (cam->OpenDevice(Win32DCAMNumber_++) < 0) {
306  cam->CloseDevice();
307  delete cam;
308  cam = NULL;
309  }
310 #else
311  // check if there are multiple cameras with no device name
312  if (cam->OpenDevice() < 0) {
313  delete cam;
314  cam = NULL;
315  }
316  return -2;
317 #endif // WIN32
318  }
319  break;
320  case ShowCamWxVideoSourceFactory::PMD: {
321 #ifdef BIAS_HAVE_PMD_PMDTec
322  VideoSource_PMD *pmd = dynamic_cast<VideoSource_PMD*>(cam);
323  if (pmd->OpenDevice()==0) {
324  pmd->SetFPNCalibrationOn(false);
325  return 0;
326  } else {
327  return -1;
328  }
329 #endif
330  break;
331  }
332  case ShowCamWxVideoSourceFactory::NET: {
333  VideoSource_Net *net = dynamic_cast<VideoSource_Net*>(cam);
334  if (net!=NULL) {
335  if (param == 0) {
336  return net->OpenDevice(deviceName.c_str());
337  } else {
338  return net->OpenDevice(deviceName, param);
339  }
340  }
341  break;
342  }
343  case ShowCamWxVideoSourceFactory::OPENNI: {
344  if (deviceName != "") {
345  return cam->OpenDevice(atoi(deviceName.c_str()));
346  } else {
347  return cam->OpenDevice();
348  }
349  break;
350  }
351  case ShowCamWxVideoSourceFactory::FREENECT2: {
352  if (deviceName != "") {
353  return cam->OpenDevice(atoi(deviceName.c_str()));
354  } else {
355  return cam->OpenDevice();
356  }
357  break;
358  }
359  default:
360  if (deviceName != "") {
361  cout<<"Opening device:"<<deviceName<<endl;
362  return (cam->OpenDevice(deviceName.c_str()));
363  } else {
364  cout<<"Opening device without device name."<<endl;
365  return cam->OpenDevice();
366  }
367  break;
368  }
369 
370 
371  return -1;
372 }
373 
374 int ShowCamWxVideoSourceFactory::InitImages(int type, VideoSource *cam, ImageBase *im1, ImageBase *im2, ImageBase *im3, ImageBase *im4) {
375 
376  switch (type) {
377 
378  case XB3:
379 #ifdef BIAS_HAVE_DCAM
380  if (dynamic_cast<VideoSource_DCAM_BumbleBee*>(cam) != NULL)
381  {
382  dynamic_cast<VideoSource_DCAM_BumbleBee*>(cam)->InitSingleImage(*im1);
383  dynamic_cast<VideoSource_DCAM_BumbleBee*>(cam)->InitSingleImage(*im2);
384  dynamic_cast<VideoSource_DCAM_BumbleBee*>(cam)->InitSingleImage(*im3);
385  cam->InitImage(*im4);
386  }
387 #endif
388  break;
389  case PMDUSB:
390 #ifdef BIAS_HAVE_PMD_PMDZess
391 // init 2D image for usb pmd cameras
392  if (dynamic_cast<VideoSource_PMDZess*>(cam) != NULL)
393  {
394  im1->Init((im2->GetWidth()+1)*3, im2->GetHeight()+1);
395  im1->SetColorModel(ImageBase::CM_Grey);
396  }
397 #endif // BIAS_HAVE_PMD_PMDZess
398  break;
399  case PMD:
400 #ifdef BIAS_HAVE_PMD_PMDTec
401  dynamic_cast<VideoSource_PMD*>(cam)->InitDepthImage(*im1);
402  dynamic_cast<VideoSource_PMD*>(cam)->InitModCoeffImage(*im2);
403  dynamic_cast<VideoSource_PMD*>(cam)->InitIntensityImage(*im3);
404 #endif
405  break;
406  case PMDSHM:
407 #ifdef BIAS_HAVE_PMD_PMDTec
408 // dynamic_cast<VideoSource_ShmPMD*>(cam)->GrabSingleDepth(*im1);
409 // dynamic_cast<VideoSource_ShmPMD*>(cam)->GrabSingleModCoeff(*im2);
410 #endif
411  break;
412  case KINECT:
413  case OPENNI:
414  dynamic_cast<VideoSource_Kinect_Base*>(cam)->InitDepthImage(*im1);
415  break;
416  #ifdef BIAS_HAVE_KINECT2
417  case FREENECT2:
418  dynamic_cast<VideoSource_Kinect2*>(cam)->InitImage(*im1);
419  dynamic_cast<VideoSource_Kinect2*>(cam)->InitDepthImage(*im2);
420  dynamic_cast<VideoSource_Kinect2*>(cam)->InitIrImage(*im3);
421  break;
422  #endif
423  default:
424  // nothing to do
425  break;
426  }
427  return 0;
428 }
429 
430 
431 }
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
virtual int InitImage(BIAS::ImageBase &Image)
int SetLeftTop(unsigned int left, unsigned int top)
set the topleft corner for partitial scan
represents Zess PMD camera driver interface TODO: include support for normal images (2DImg_)...
Defines a common interface to different devices.
void AddDebugLevel(const long int lv)
Definition: Debug.hh:355
Use the Kinect2 class to grab images from the Microsoft Kinect2.
virtual int OpenDevice(const char *serverName)
use given port and ip address to connect to videoserver
This class implements a video streaming client using shared memory to receive images from another app...
void SetModeAndFramerate(dc1394video_mode_t mode, float framerate)
Use OpenNI just like the ToF Cameras.
void SetSourcePlugin(std::string plugin)
only set the plugin to be opened at OpenDevice
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
virtual void GetBrightnessRange(double &min, double &max)
Support for SwissRanger usb cam.
This class VideoSource_DCAM implements access to IEEE1394 (Firewire, iLink) cameras following the DCa...
virtual void SetContrastRange(unsigned int min, unsigned int max)
int SetFPNCalibrationOn(bool on)
unsigned int GetWidth() const
Definition: ImageBase.hh:312
virtual void GetContrastRange(double &min, double &max)
This class extends VideoSource for the use of DirectShow devices you need Microsoft Windows SDK versi...
virtual void SetBrightnessRange(unsigned int min, unsigned int max)
int SetFormat7(int mode, int bpp, dc1394color_coding_t colorCoding=DC1394_COLOR_CODING_MONO8)
this a special function to by-pass all automatic initializations and Use only in conjuction with SetS...
Support for CamCube usb cam.
virtual int OpenDevice()
selects the first available device to open (e.g.
void SetDebugLevel(const long int lv)
Definition: Debug.hh:318
unsigned int GetHeight() const
Definition: ImageBase.hh:319
virtual int OpenDevice()
selects the first available device to open (e.g.
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
Definition: ImageBase.cpp:229
void SetBitFile(std::string file)
virtual int CloseDevice()
Use Kinect with the libfreenect drivers just like the ToF Cameras.
This class extends VideoSource for the use of IDS uEye devices.
This class extends VideoSource for the use of Video4Linux supported devices like framegrabber, USB cameras.
This class implements a video streaming client using TCP.
Use Kinect just like the ToF Cameras.
This is the base class for images in BIAS.
Definition: ImageBase.hh:102