Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_DCAM.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include <dc1394/control.h>
26 
27 #include "VideoSource_DCAM.hh"
28 #include "sys/time.h"
29 #include "unistd.h"
30 #include <sys/stat.h>
31 
32 // Number of DMA buffers was previously limited to 1 which resulted
33 // in deadlocks, hence the number was increased (esquivel, 05/09/2012)
34 #define NUM_DMA_BUFFERS 10
35 
36 using namespace BIAS;
37 using namespace std;
38 
40 
41 int
42 BIAS::ScanBus(std::stringstream &ss)
43 {
44  VideoSource_DCAM *cam;
45  int ncams = 0;
46 
47  dc1394camera_list_t *camsList;
48  dc1394error_t err;
49 
50  dc1394_t *d = dc1394_new();
51  err = dc1394_camera_enumerate(d, &camsList);
52  ncams = (int) camsList->num;
53 
54  if (err != DC1394_SUCCESS)
55  {
56  BIASERR("Scanning bus failed");
57  }
58 
59  if (ncams > 0)
60  {
61  cam = new VideoSource_DCAM();
62  //cam.SetDebugLevel(0);
63  for (int i = 0; i < ncams; i++)
64  {
65  cam->SetSize(0, 0);
66  cam->OpenDevice(camsList->ids[i].guid & 0x00000FFF);
67  if (ss)
68  {
69  ss << "0" << " " << (camsList->ids[i].guid & 0x00000FFF) << " "
70  << cam->GetWidth() << " " << cam->GetHeight() << " 0"
71  << " 0" << endl;
72  }
73  cam->CloseDevice();
74  }
75  delete cam;
76  }
77  else
78  {
79  dc1394_free(d);
80  BIASERR("No cameras found on bus ");
81  return -1;
82  }
83  dc1394_free(d);
84  return ncams;
85 }
86 
87 int
88 BIAS::ScanBus(vector<CameraInfo> &camInfos)
89 {
90  camInfos.clear();
91  int ncams = 0;
92 
93  dc1394camera_t *cams;
94  dc1394camera_list_t *camsList;
95  dc1394error_t err;
96 
97  dc1394_t *d = dc1394_new();
98  err = dc1394_camera_enumerate(d, &camsList);
99  ncams = (int) camsList->num;
100 
101  if (err != DC1394_SUCCESS)
102  return 0;
103 
104  for (int i = 0; i < ncams; i++)
105  {
106  CameraInfo camInfo;
107  cams = dc1394_camera_new(d, camsList->ids[i].guid);
108  // dc1394_reset_camera(cams);
109 
110  camInfo.camid = (camsList->ids[i].guid & 0x00000FFF);
111  string m(cams->model);
112  string v(cams->vendor);
113  camInfo.model = m;
114  camInfo.vendor = v;
115  camInfo.guid = camsList->ids[i].guid;
116 
117  bool setFirewireManual = false;
118 
119  unsigned int vendor = (camsList->ids[i].guid) >> 40;
120  unsigned int model = (camsList->ids[i].guid >> 12) & 0xFF;
121 
122  // we have a scorpion cam. firewire b detection doesnt work correctly
123  if ((model == 0xf5 || model == 0x28) && vendor == 0x00b09d)
124  {
125  setFirewireManual = true;
126  }
127  else if (m == "Firefly MV FFMV-03MTM")
128  {
129  setFirewireManual = true;
130  }
131 
132  if (cams->bmode_capable == DC1394_TRUE && !setFirewireManual)
133  {
134  camInfo.b_capable = true;
135  }
136  else
137  {
138  camInfo.b_capable = false;
139  }
140 
141  dc1394video_modes_t modes;
142  vector<dc1394video_mode_t> modesVector;
143  vector<vector<float> > framesVector;
144  unsigned MaxWidth_, MaxHeight_, UnitWidth_, UnitHeight_, MinBpP_;
145  unsigned MaxBpP_, BestBpP_;
146 
147  dc1394_video_get_supported_modes(cams, &modes);
148  for (unsigned int j = 0; j < modes.num; j++)
149  {
150 
151  modesVector.push_back(modes.modes[j]);
152 
153  if (modes.modes[j] < DC1394_VIDEO_MODE_EXIF)
154  {
155  vector<float> innerFramesVector;
156  dc1394framerates_t framerates;
157  float fr;
158  dc1394_video_get_supported_framerates(cams, modes.modes[j],
159  &framerates);
160  for (unsigned int l = 0; l < framerates.num; l++)
161  {
162  dc1394_framerate_as_float(framerates.framerates[l], &fr);
163  innerFramesVector.push_back(fr);
164  }
165  framesVector.push_back(innerFramesVector);
166  }
167 
168  else if (modes.modes[j] > DC1394_VIDEO_MODE_EXIF)
169  {
170 
171  dc1394_format7_get_max_image_size(cams, modes.modes[j],
172  &MaxWidth_, &MaxHeight_);
173  dc1394_format7_get_unit_size(cams, modes.modes[j], &UnitWidth_,
174  &UnitHeight_);
175  dc1394_format7_get_packet_parameters(cams, modes.modes[j],
176  &MinBpP_, &MaxBpP_);
177  dc1394_format7_get_recommended_packet_size(cams, modes.modes[j],
178  &BestBpP_);
179 
180  for (int k = 0; k < 8; k++)
181  {
182  if (modes.modes[j] == DC1394_VIDEO_MODE_FORMAT7_0 + k)
183  {
184  camInfo.f7_modes.push_back(
185  (dc1394video_mode_t) (DC1394_VIDEO_MODE_FORMAT7_0 + k));
186  camInfo.f7_MinBpP.push_back(MinBpP_);
187  camInfo.f7_MaxBpP.push_back(MaxBpP_);
188  camInfo.f7_maxHeight.push_back(MaxHeight_);
189  camInfo.f7_maxWidth.push_back(MaxWidth_);
190  camInfo.f7_unitHeight.push_back(UnitHeight_);
191  camInfo.f7_unitWidth.push_back(UnitWidth_);
192  camInfo.f7_bestBpP.push_back(BestBpP_);
193  // cout << "Format7 Mode" << k << ": Size = "
194  // << MaxWidth_ << " x " << MaxHeight_ << endl;
195  // cout << "Format7 Mode" << k << ": Unit = "
196  //<< UnitWidth_ << " x " << UnitHeight_ << endl;
197  // cout << "Format7 Mode" << k
198  //<< ": Bytes per Packet = " << MinBpP_ << " - "
199  //<< MaxBpP_ << endl;
200  }
201  }
202  }
203  }
204 
205  camInfo.framerates = framesVector;
206  camInfo.videoModes = modesVector;
207 
208  // here we scan for the best mode and framerate...
209  dc1394color_coding_t colorCoding;
210  // search for best mode
211  int y;
212  for (y = modes.num - 1; y >= 0; y--)
213  {
214  if (modes.modes[y] < DC1394_VIDEO_MODE_EXIF)
215  {
216  camInfo.bestMode = modes.modes[y];
217  // get color from video mode
218  dc1394_get_color_coding_from_video_mode(cams, modes.modes[y],
219  &colorCoding);
220  // dont set mono16 as default for compatibility reasons
221  if (colorCoding != DC1394_COLOR_CODING_MONO16)
222  {
223  break;
224  }
225  }
226  }
227 
228  cout << "Best Mode: " << camInfo.bestMode << endl;
229 
230  // calc best framerate
231  camInfo.bestFramerate = framesVector[y][framesVector[y].size() - 1];
232 
233  camInfos.push_back(camInfo);
234 
235  dc1394_camera_free(cams);
236  }
237  dc1394_camera_free_list(camsList);
238  dc1394_free(d);
239  return ncams;
240 }
241 
243 {
244  camid = 0;
245  // IEEE1394Card_ = Card;
246  //SetDebugLevel(D_DCAM);
247  TransmissionTime_ = 0;
248  UserTopLeft_ = false;
249  UseBinning_ = false;
250  Shift16_ = 0;
251  IsControllable_ = true;
252  SelectedCam_ = 0;
253  // New Default: Use DMA
254  UseDMA_ = true;
255  bEnsureLatestFrame_ = false;
256 
257  DcamMode_ = DC1394_VIDEO_MODE_160x120_YUV444;
258  DcamFormat_ = 0;
259  DcamFps_ = DC1394_FRAMERATE_30;
260  FramesPerSecond_ = 0.0;
261  ForceF7_ = false;
262  DirectF7_ = false;
263  f7ColorCoding_ = DC1394_COLOR_CODING_RAW8;
265  Width_ = 0;
266  Height_ = 0;
267  BytesPerPacket_ = 0;
268  ColorChannels_ = 0;
269 
270  TryFirewireB_ = true;
271  UserMode_ = false;
272 
273  dcbus = NULL;
274  camera = NULL;
275  cameraList = NULL;
276 
277  InstancesTotal_++;
278 
279  minContrast_ = 0; //?
280  maxContrast_ = 40;
281  minGain_=0; //db
282  maxGain_ = 56;
283  minShutter_ = 0; //ms
284  maxShutter_ = 400;
285 
286  // create new file for cam infos
287  // ofstream fout( "cams.info" );
288  //fout.close();
289 
290 #ifdef BIAS_HAVE_PTHREADS
291  pthread_mutex_init(&grabMutex_, NULL);
292 #endif
293 }
294 
296 {
297  InstancesTotal_--;
298  if (Active_)
299  {
300  PostGrab();
301  dc1394_camera_free(camera);
302  dc1394_free(dcbus);
303  }
304 }
305 
306 void
308  dc1394video_mode_t mode, int width, int height, unsigned int& minbpp,
309  unsigned int& maxbpp)
310 {
311  dcbus = dc1394_new();
312  err = dc1394_camera_enumerate(dcbus, &cameraList);
313  numCamsOnBus = cameraList->num;
314  if (numCamsOnBus < 1)
315  {
316  BIASDOUT(D_DCAM,"There is no cam to open");
317  }
318  else
319  {
320  if (camid == 0)
321  {
322  camera = dc1394_camera_new(dcbus, cameraList->ids[camid].guid);
323  SelectedCam_ = 0;
324  ID_ = (camera->guid & 0x00000FFF);
325  }
326  else
327  {
328  for (unsigned int i = 0; i < numCamsOnBus; i++)
329  {
330  camera = dc1394_camera_new(dcbus, cameraList->ids[i].guid);
331  ID_ = (camera->guid & 0x00000FFF);
332  if (ID_ == camid)
333  {
334  SelectedCam_ = i;
335  break;
336  }
337  //dc1394_reset_bus(camera);
338  //dc1394_camera_free(camera);
339  }
340  }
341  dc1394_format7_set_image_position(camera, mode, 0, 0);
342  dc1394_format7_set_image_size(camera, mode, width, height);
343  dc1394_format7_get_packet_parameters(camera, mode, &minbpp, &maxbpp);
344  }
345 }
346 
347 void
349 {
350  camid = manualcamid_;
351 
352 }
353 
354 
355 int
357 {
358  BIASDOUT(D_DCAM,"VideoSource_DCAM::OpenDevice("<< camid <<")");
359  dcbus = dc1394_new();
360  if (dcbus == NULL)
361  {
362  BIASERR("dc1394_new() failed.");
363  return -1;
364  }
365  err = dc1394_camera_enumerate(dcbus, &cameraList);
366  if (err != DC1394_SUCCESS)
367  {
368  BIASERR("dc1394_camera_enumerate() failed.");
369  return -2;
370  }
371 
372  numCamsOnBus = cameraList->num;
373 
374  if (numCamsOnBus < 1)
375  {
376  BIASERR("There is no cam to open");
377  return -3;
378  }
379  else
380  {
381  BIASDOUT(D_DCAM,"Found " << numCamsOnBus << " cams");
382 
383  if (camid == 0)
384  {
385  camera = dc1394_camera_new(dcbus, cameraList->ids[camid].guid);
386  SelectedCam_ = 0;
387  ID_ = (camera->guid & 0x00000FFF);
388  }
389  else
390  {
391  bool foundCamWithId = false;
392 
393  for (unsigned int i = 0; i < numCamsOnBus; i++)
394  {
395 
396  camera = dc1394_camera_new(dcbus, cameraList->ids[i].guid);
397  ID_ = (camera->guid & 0x00000FFF);
398 
399  BIASDOUT(D_DCAM,"List guid" << cameraList->ids[i].guid << "masked" << (cameraList->ids[i].guid & 0x00000FFF) << endl);
400  BIASDOUT(D_DCAM,"ID of the new device" << camera->guid << " cams" << "masked:" << ID_ << endl);
401 
402  // ofl: camid is between 0 and numCamsOnBus but ID_ is the guid, an arbitrary int
403  // this new check should always be true
404  //if((camera->guid & 0x00000FFF) == (cameraList->ids[i].guid & 0x00000FFF))
405  if (ID_ == camid)
406  {
407  SelectedCam_ = i;
408  foundCamWithId = true;
409  break;
410  }
411  else {
412  dc1394_camera_free(camera);
413  }
414  //dc1394_reset_bus(camera);
415  }
416  // cam not found
417  if (!foundCamWithId)
418  {
419  return -4;
420  }
421  }
422  }
423  //dc1394_cleanup_iso_channels_and_bandwidth(camera);
425  QueryCam();
426 
427  return InitCam();
428 
429 }
430 
431 int
433 {
434  return OpenDevice(camid);
435 }
436 
437 void
438 VideoSource_DCAM::SetModeAndFramerate(dc1394video_mode_t mode, float framerate)
439 {
440  DcamMode_ = mode;
441  if (DcamMode_ == 84)
442  {
444  cout << "SMAFR ColorModel:" << GetColorModel() << endl;
445  }
446  SetFPS(framerate);
447  UserMode_ = true;
448 }
449 
450 int
451 VideoSource_DCAM::SetFormat7(int mode, int bpp, dc1394color_coding_t colorCoding)
452 {
453  f7ColorCoding_ = colorCoding;
454  DcamMode_ = (dc1394video_mode_t) (DC1394_VIDEO_MODE_FORMAT7_MIN + mode);
455  BytesPerPacket_ = bpp;
456  DirectF7_ = true;
457  return 0;
458 }
459 
460 int
462 {
463  // release cam and clean up
464  if (Active_)
465  {
466  PostGrab();
467  }
468  return 0;
469 }
470 
471 void
473 {
474  TryFirewireB_ = on;
475 }
476 
477 /*
478  int VideoSource_DCAM::UsePort(int channel)
479  {
480  //IEEE1394Card_ = channel;
481  return 0;
482  }
483  */
484 
485 int
487 {
488 
489 #ifdef BIAS_HAVE_PTHREADS
490  pthread_mutex_lock(&grabMutex_);
491 #endif
492 
493  BIASDOUT(D_DCAM,"VideoSource_DCAM::GrabSingle("<<SelectedCam_<<")");
494  // assert(! image.IsEmpty());
495  if (image.IsEmpty())
496  {
497  BIASERR("VideoSource_DCAM::GrabSingle(): Given Image is empty, use InitImage()");
498  //return -1;
499  }
500 
501  if (!Active_)
502  {
503  BIASERR("VideoSource_DCAM::GrabSingle(): VideoSource Object not active, use PreGrab()");
504  return -1;
505  }
506  if (Grabbing_)
507  {
508  BIASERR("VideoSource_DCAM::GrabSingle(): VideoSource Object is already grabbing()");
509  return -1;
510  }
511  Grabbing_ = true;
512 
513  dc1394video_frame_t * frame;
514  err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
515  if (err != DC1394_SUCCESS)
516  {
517  BIASERR("VideoSource_DCAM::GrabSingle(): unable to capture from camera:"<< CamModel_);
518  Grabbing_ = false;
519  return -1;
520  }
522  {
523  while(frame && err == DC1394_SUCCESS) {
524  // cout << "Grabbing again for latest frame:" << endl;
525  err = dc1394_capture_enqueue(camera, frame);
526  err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_POLL, &frame);
527  }
528  }
529 
530  image.CopyIn_NoInit((unsigned char *) frame->image);
531  // set time in micro seconds
532  image.SetTime(0, frame->timestamp);
533  image.UpdateMetaData();
534 
535  err = dc1394_capture_enqueue(camera, frame);
536 
537  image.InvalidateUID();
538  image.SetUID(UUID::GenerateUUID());
539 
540  Grabbing_ = false;
541 
542 #ifdef BIAS_HAVE_PTHREADS
543  pthread_mutex_unlock(&grabMutex_);
544 #endif
545 
546  return 0;
547 }
548 
549 #ifdef BUILD_IMAGE_USHORT
550 int
552 {
553 #ifdef BIAS_HAVE_PTHREADS
554  pthread_mutex_lock(&grabMutex_);
555 #endif
556 
557  BIASDOUT(D_DCAM,"VideoSource_DCAM::GrabSingle("<<SelectedCam_<<")");
558  // assert(! image.IsEmpty());
559  if (image.IsEmpty())
560  {
561  BIASERR("VideoSource_DCAM::GrabSingle(): Given Image is empty, use InitImage()");
562  //return -1;
563  }
564 
565  if (!Active_)
566  {
567  BIASERR("VideoSource_DCAM::GrabSingle(): VideoSource Object not active, use PreGrab()");
568  return -1;
569  }
570  if (Grabbing_)
571  {
572  BIASERR("VideoSource_DCAM::GrabSingle(): VideoSource Object is already grabbing()");
573  return -1;
574  }
575  Grabbing_ = true;
576 
577  dc1394video_frame_t * frame;
578  err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
579  if (err != DC1394_SUCCESS)
580  {
581  BIASERR("VideoSource_DCAM::GrabSingle(): unable to capture from camera:"<< CamModel_);
582  Grabbing_ = false;
583  return -1;
584  }
585 
586  unsigned int numbytes = image.GetSize();
587  // byte-wise pointer
588  unsigned char *idata = (unsigned char *) image.GetImageData();
589  unsigned char *buf = (unsigned char *) frame->image;
590 
591  for (unsigned int i = 0; i < numbytes; i += 2)
592  {
593  idata[i] = buf[i + 1];
594  idata[i + 1] = buf[i];
595  // the significant bits used by point grey are the 16-Shift16_ upper bits
596  // cast pixel pointer to unsigned short and apply shift
597  *(unsigned short *) (&idata[i]) = (*(unsigned short *) (&idata[i]))
598  >> Shift16_;
599  }
600  image.SetTime(0, frame->timestamp);
601  image.UpdateMetaData();
602 
603  err = dc1394_capture_enqueue(camera, frame);
604 
605  image.InvalidateUID();
606  image.SetUID(UUID::GenerateUUID());
607 
608  Grabbing_ = false;
609 
610 #ifdef BIAS_HAVE_PTHREADS
611  pthread_mutex_unlock(&grabMutex_);
612 #endif
613  return 0;
614 }
615 #endif
616 
617 void
619 {
620  //quadlet_t r12F8 = 0x80000001;//activate only timestamp, read Tech Reference
621  // SetCameraControlRegister(IEEE1394Handle_[IEEE1394Card_],
622  // DcamNodes_[SelectedCam_], 0x12f8, r12F8);
623 }
624 
625 int
627 {
628  BIASDOUT(D_DCAM,"VideoSource_DCAM::PreGrab("<<SelectedCam_<<")");
629 
631  if (InitCam() < 0)
632  return -1;
633 
634  // dc1394_video_set_one_shot(camera, DC1394_OFF);
635  // have the camera start sending us data
636  printf("Start transmission\n");
637  if (dc1394_video_set_transmission(camera, DC1394_ON) != DC1394_SUCCESS)
638  {
639  fprintf(stderr, "Unable to start camera iso transmission\n");
640  Active_ = false;
641 
642  }
643  else
644  {
645  Active_ = true;
646  }
647  dc1394switch_t isoOn;
648  dc1394_video_get_transmission(camera, &isoOn);
649  cout << "Iso on: " << isoOn << endl;
650  return 0;
651 }
652 
653 int
655 {
656  int res = 0;
657  if (Active_ == true)
658  {
659  BIASDOUT(D_DCAM,"VideoSource_DCAM::PostGrab("<<SelectedCam_<<")");
660  Active_ = false;
661  if (dc1394_video_set_transmission(camera, DC1394_OFF) != DC1394_SUCCESS)
662  {
663  cout << "Couldn't stop the camera?" << endl;
664  }
665  dc1394_capture_stop(camera);
666 
667  }
668  return res;
669 }
670 
671 int
673 {
674  BIASDOUT(D_DCAM,"VideoSource_DCAM::QueryCam("<<SelectedCam_<<")");
675 
676  // Query the cam for available modes
677  err = dc1394_video_get_supported_modes(camera, &CameraModes_);
678 
679  if (err != DC1394_SUCCESS)
680  {
681  BIASDOUT(D_DCAM,"Could not query cam for modes");
682  return -1;
683  }
684  float fr;
685  // Query for framerates but not for format 7
686  for (unsigned int i = 0; i < CameraModes_.num; i++)
687  {
688  dc1394video_mode_t mode = CameraModes_.modes[i];
689  if (mode < DC1394_VIDEO_MODE_EXIF)
690  {
691  err = dc1394_video_get_supported_framerates(camera, mode,
692  &CameraFramerates_[DC1394_VIDEO_MODE_MAX - mode]);
693 
694  // cout << "Framerates for Mode " << mode << ": ";
695  for (unsigned int j = 0; j < CameraFramerates_[DC1394_VIDEO_MODE_MAX
696  - mode].num; j++)
697  {
698  dc1394_framerate_as_float(CameraFramerates_[DC1394_VIDEO_MODE_MAX
699  - mode].framerates[j], &fr);
700  // cout << fr << " ";
701  }
702  // cout << endl;
703  }
704  }
705  // Query for Format 7
706  for (unsigned int i = 0; i < CameraModes_.num; i++)
707  {
708  dc1394video_mode_t mode = CameraModes_.modes[i];
709  if (mode > DC1394_VIDEO_MODE_EXIF)
710  {
711  dc1394_format7_get_max_image_size(camera, mode, &MaxWidth_,
712  &MaxHeight_);
713  dc1394_format7_get_unit_size(camera, mode, &UnitWidth_, &UnitHeight_);
714  dc1394_format7_get_packet_parameters(camera, mode, &MinBpP_, &MaxBpP_);
715  // for(int k = 0; k<8;k++){
716  // if(mode == DC1394_VIDEO_MODE_FORMAT7_0+k){
717  // cout << "Format7 Mode" << k << ": Size = " << MaxWidth_
718  // << " x " << MaxHeight_ << endl;
719  // cout << "Format7 Mode" << k << ": Unit = " << UnitWidth_
720  // << " x " << UnitHeight_ << endl;
721  // cout << "Format7 Mode" << k << ": Bytes per Packet = "
722  // << MinBpP_ << " - " << MaxBpP_ << endl;
723  // }
724  // }
725  }
726  }
727  // get camera features
728  dc1394_feature_get_all(camera, &DcamFeatures_);
729  return 0;
730 }
731 
732 int
734 {
735  /*
736  cout <<"Camera: "<<SelectedCam_<<" UID:"
737  <<(DcamInfo_.euid_64 & 0x00000FFF)<<endl;
738 
739  // Die Ergebnisse des Querys in eine Datei schreiben
740  //ofstream fout( "cams.info" );
741  // fout << dc1394_print_feature_set(&DcamFeatures_);
742 
743  // Allgemeine Kamerainfos (UID, Vendor and Model)
744  dc1394_print_camera_info(&DcamInfo_);
745 
746  // Firewire B kompatibel
747  if(DcamSpeed_ > 2)
748  cout <<"Firewire B capable"<< endl;
749  else
750  cout <<"Firewire A" << endl;
751 
752  // Operating Mode der Cam
753  unsigned int op_mode_;
754  dc1394_get_operation_mode(IEEE1394Handle_[IEEE1394Card_],
755  DcamNodes_[SelectedCam_],
756  &op_mode_);
757  cout << "Operation mode: ";
758  if(op_mode_ == 1)
759  cout << "DC1394_OPERATION_MODE_1394B" << endl;
760  else
761  cout << "DC1394_OPERATION_MODE_LEAGACY" << endl;
762 
763  //
764 
765  // Features der Cam und deren Einstellungen
766  // dc1394_print_feature_set(&DcamFeatures_);
767 
768 
769 
770  cout <<"Supported Formats: ";
771  for (int i=0; i<NUM_FORMATS; i++)
772  if (SupportedFormats_[i])
773  cout <<"Format"<<i<<" ";
774  cout <<endl;
775 
776  cout <<"Supported Modes:"<<endl;
777  for (int i=0; i<NUM_FORMATS; i++)
778  if (SupportedFormats_[i]) {
779  cout <<"Format"<<i<<": ";
780  for (int j=0; j<NUM_FORMAT1_MODES; j++)
781  if (SupportedModes_[i][j])
782  cout <<"Mode"<<j<<" ";
783 
784  cout <<endl;
785 
786  }
787 
788  cout <<"Supported Framerates:"<<endl;
789  for (int format=0; format < NUM_FORMATS-1; format++) {
790  // int fps;
791  quadlet_t fps;
792 
793  cout <<" Format"<<format<<": ";
794  for (int i=0; i<NUM_FORMAT1_MODES; i++){
795  if ((fps = SupportedFramerates_[format][i]) >0) {
796  cout <<"Mode"<<i<<": ";
797  for (int f=0; f<NUM_FRAMERATES; f++)
798  if (fps & (0x1 << (31-f) ))
799  cout <<1.875 *(0x1<<f)<<" ";
800 
801  }
802  }
803 
804  cout <<endl;
805  }
806 
807  */
808  return 0;
809 
810 }
811 
812 int
814 {
815  cout << "VideoSource_DCAM::SelectDefault(" << SelectedCam_ << ")" << endl;
816  dc1394color_coding_t colorCoding;
817  // search for best mode
818  for (int i = CameraModes_.num - 1; i >= 0; i--)
819  {
820  if (CameraModes_.modes[i] < DC1394_VIDEO_MODE_EXIF)
821  {
822  DcamMode_ = CameraModes_.modes[i];
823  // get color from video mode
824  dc1394_get_color_coding_from_video_mode(camera, DcamMode_,
825  &colorCoding);
826  // dont set mono16 as default for compatibility reasons
827  if (colorCoding != DC1394_COLOR_CODING_MONO16)
828  {
829  break;
830  }
831  }
832  }
833 
834  //cout << "Selected Mode " << DcamMode_ << endl;
835  // search for best framerate
836  DcamFps_
837  = CameraFramerates_[DC1394_VIDEO_MODE_MAX - DcamMode_].framerates[CameraFramerates_[DC1394_VIDEO_MODE_MAX
838  - DcamMode_].num - 1];
839 
840  // get width and height from video mode.
841  uint32_t w, h;
842  dc1394_get_image_size_from_video_mode(camera, DcamMode_, &w, &h);
843  Width_ = (int) w;
844  Height_ = (int) h;
845 
847 
848  // default settings for some special cameras
850  {
851  cout
852  << " Ignoring autodetected mode for Dragonfly2. Setting to format2, mode4, 7.5fps."
853  << endl;
854  DcamMode_ = DC1394_VIDEO_MODE_1600x1200_RGB8;
855  DcamFps_ = DC1394_FRAMERATE_7_5;
856  ColorChannels_ = 3;
857  Width_ = 1600;
858  Height_ = 1200;
859  //GetColorFromMode(DcamMode_);
861  }
863  {
864  cout
865  << " Ignoring autodetected mode for Grasshopper. Setting to format1, mode3, 15fps."
866  << endl;
867  cout << " Size 1600x1200" << endl;
868  DcamMode_ = DC1394_VIDEO_MODE_1024x768_YUV422;
869  DcamFps_ = DC1394_FRAMERATE_30;
870  Width_ = 1024;
871  Height_ = 768;
872  ColorChannels_ = 2;
874  }
876  {
877  cout
878  << " Ignoring autodetected mode for Fire-i. Setting to 640x480 RGB8, 15 fps."
879  << endl;
880  DcamMode_ = DC1394_VIDEO_MODE_640x480_RGB8;
881  DcamFps_ = DC1394_FRAMERATE_15;
882  Width_ = 640;
883  Height_ = 480;
884  ColorChannels_ = 1;
886  }
888  {
889  cout
890  << " Ignoring autodetected mode for FireFLY setting to 640x480, color, 30fps."
891  << endl;
892  DcamFps_ = DC1394_FRAMERATE_30;
893  DcamMode_ = DC1394_VIDEO_MODE_640x480_MONO8;
894  Width_ = 640;
895  Height_ = 480;
896  ColorChannels_ = 1;
898 
899  }
901  {
902  cout
903  << " \n\nIgnoring autodetected mode for FireFLY setting to mono8, 30fps. "
904  << endl;
905  DcamFps_ = DC1394_FRAMERATE_30;
906  DcamMode_ = DC1394_VIDEO_MODE_640x480_MONO8;
907  DcamFps_ = DC1394_FRAMERATE_30;
908  Width_ = 640;
909  Height_ = 480;
910  ColorChannels_ = 1;
912 
913  }
915  {
916  cout << " Setting best framerate right for the DragonFly 2.\n";
917  FramesPerSecond_ = 7.5; //DEBUG TODO: Dragonfly2
919  }
920 
922  {
923  cout << " Setting best framerate right for the KameraWerk Dresden i5\n";
924  FramesPerSecond_ = 25;
925  maxShutter_ = 400;
926  //set correct mode here!!!
927 
928  DcamMode_ = DC1394_VIDEO_MODE_1024x768_MONO8;
930  }
931  float fr;
932  dc1394_framerate_as_float(DcamFps_, &fr);
933  BIASDOUT(D_DCAM,"Best Settings for Camera: " << Width_<<"x"<<Height_
934  <<" at "<< fr<<"fps"<<" Colormodel: "<<ColorMode_);
935 
936  return 0;
937 }
938 
939 #define USE_NATIVE_XGA
940 
941 int
943 {
944  BIASDOUT(D_DCAM,"VideoSource_DCAM::UserSizeToMode("<<SelectedCam_<<"): "<<Width_<<"x"<<Height_<<" BytesPerPixel_: "<<BytesPerPixel_<<" ColorMode: "<<ColorMode_);
945  int res = 0;
946 
947  if (ForceF7_)
948  res = UserSizeToFormat7_();
949  else
950  {
951  if (BytesPerPixel_ == 1.0)
952  res = UserSizeToMode_8bit_();
953  else if (BytesPerPixel_ == 2.0)
954  res = UserSizeToMode_16bit_();
955  else
956  {
957  BIASERR("VideoSource_DCAM::UserSizeToMode(): "<<BytesPerPixel_*8
958  <<" -bit not yet impl");
959  return -1;
960  }
961  // -1 means: did not find a mode, try Format7
962  if (res == -1)
963  res = UserSizeToFormat7_();
964  }
965  return res;
966 }
967 
968 // try to find a matching mode or return -1 to indicate that Format7
969 // may be good
970 int
972 {
973  int res = 0;
974 
975  switch (ColorMode_)
976  {
978  ColorChannels_ = 2;
979  if (Width_ == 1600 && Height_ == 1200)
980  {
981  DcamMode_ = DC1394_VIDEO_MODE_1600x1200_YUV422;
982  //DcamFormat_ = FORMAT_SVGA_NONCOMPRESSED_1;
983  }
984  else if (Width_ == 1280 && Height_ == 960)
985  {
986  DcamMode_ = DC1394_VIDEO_MODE_1280x960_YUV422;
987  //DcamFormat_ = FORMAT_SVGA_NONCOMPRESSED_1;
988  }
989  else if (Width_ == 1024 && Height_ == 768)
990  {
991  DcamMode_ = DC1394_VIDEO_MODE_1024x768_YUV422;
992  //DcamFormat_ = FORMAT_SVGA_NONCOMPRESSED_1;
993  BIASDOUT(D_DCAM,"Using native XGA");
994  }
995  else if (Width_ == 800 && Height_ == 600)
996  {
997  DcamMode_ = DC1394_VIDEO_MODE_800x600_YUV422;
998  //DcamFormat_ = FORMAT_SVGA_NONCOMPRESSED_1;
999  }
1000  else if (Width_ == 640 && Height_ == 480)
1001  {
1002  DcamMode_ = DC1394_VIDEO_MODE_640x480_YUV422;
1003  //DcamFormat_ = FORMAT_VGA_NONCOMPRESSED;
1004  }
1005  else if (Width_ == 320 && Height_ == 240)
1006  {
1007  DcamMode_ = DC1394_VIDEO_MODE_320x240_YUV422;
1008  //DcamFormat_ = FORMAT_VGA_NONCOMPRESSED;
1009  }
1010  else
1011  res = -1;// Format 7 required,
1012  break;
1013  case ImageBase::CM_YUV411:
1014  ColorChannels_ = 2;
1015  // if (Width_ == 1600 && Height_ == 1200) {
1016  // DcamMode_ = MODE_1600x1200_YUV411;
1017  // DcamFormat_ = FORMAT_SVGA_NONCOMPRESSED_1;
1018  // }
1019  // else if (Width_ == 1280 && Height_ == 960) {
1020  // DcamMode_ = MODE_1280x960_YUV41;
1021  // DcamFormat_ = FORMAT_SVGA_NONCOMPRESSED_1;
1022  // }
1023  // else if (Width_ == 1024 && Height_ == 768) {
1024  // DcamMode_ = MODE_1024x768_YUV411;
1025  // DcamFormat_ = FORMAT_SVGA_NONCOMPRESSED_1;
1026  // BIASDOUT(D_DCAM,"Using native XGA");
1027  // }
1028  // else if (Width_ == 800 && Height_ == 600) {
1029  // DcamMode_ = MODE_800x600_YUV41;
1030  // DcamFormat_ = FORMAT_SVGA_NONCOMPRESSED_1;
1031  // }
1032  // else
1033  if (Width_ == 640 && Height_ == 480)
1034  {
1035  DcamMode_ = DC1394_VIDEO_MODE_640x480_YUV411;
1036  //DcamFormat_ = FORMAT_VGA_NONCOMPRESSED;
1037  }
1038  else
1039  res = -1;// Format 7 required,
1040  break;
1041  case ImageBase::CM_Grey:
1046  ColorChannels_ = 1;
1047  if (Width_ == 1600 && Height_ == 1200)
1048  {
1049  DcamMode_ = DC1394_VIDEO_MODE_1600x1200_MONO8;
1050  cout << "Mode:DC1394_VIDEO_MODE_1600x1200_MONO8" << endl;
1051  }
1052  else if (Width_ == 1024 && Height_ == 768)
1053  {
1054  DcamMode_ = DC1394_VIDEO_MODE_1024x768_MONO8;
1055  }
1056  else if (Width_ == 1280 && Height_ == 960)
1057  {
1058  DcamMode_ = DC1394_VIDEO_MODE_1280x960_MONO8;
1059  }
1060 
1061  else if (Width_ == 640 && Height_ == 480 && CamModel_
1063  {
1064  DcamMode_ = DC1394_VIDEO_MODE_640x480_MONO8;
1065  BIASDOUT(D_DCAM,"Mode: "
1066  <<" 640x480_MONO");
1067  }
1068  else
1069  return -1;
1070  break;
1071  case ImageBase::CM_RGB:
1072  if (Width_ == 640 && Height_ == 480)
1073  {
1074  DcamMode_ = DC1394_VIDEO_MODE_640x480_RGB8;
1075  }
1076  else
1077  res = -1;
1078  break;
1079  default:
1080  BIASERR("VideoSource_DCAM::UserSizeToMode(): Unsupported ColorModel_"
1081  <<ColorMode_)
1082  ;
1083  res = -2;
1084  }
1085 
1086  return res;
1087 }
1088 
1089 int
1091 {
1092 
1093  int res = 0;
1094  switch (ColorMode_)
1095  {
1096  case ImageBase::CM_Grey:
1101  if (Width_ == 640 && Height_ == 480)
1102  {
1103  ColorChannels_ = 1;
1104  DcamMode_ = DC1394_VIDEO_MODE_640x480_MONO16;
1105  // DcamFormat_ = FORMAT_VGA_NONCOMPRESSED;
1106  BIASDOUT(D_DCAM,"Mode: "
1107  <<" 640x480_MONO16");
1108  }
1109  else if (Width_ == 1024 && Height_ == 768)
1110  {
1111  ColorChannels_ = 1;
1112  DcamMode_ = DC1394_VIDEO_MODE_1024x768_MONO16;
1113  BIASDOUT(D_DCAM," Mode: "
1114  <<" 1024x768_MONO16");
1115  }
1116  else if (Width_ == 1280 && Height_ == 960)
1117  {
1118  ColorChannels_ = 1;
1119  DcamMode_ = DC1394_VIDEO_MODE_1280x960_MONO16;
1120  }
1121  else if (Width_ == 1600 && Height_ == 1200)
1122  {
1123  ColorChannels_ = 1;
1124  DcamMode_ = DC1394_VIDEO_MODE_1600x1200_MONO16;
1125  }
1126  else
1127  res = -1;
1128  break;
1129  default:
1130  BIASERR("VideoSource_DCAM::UserSizeToMode(): Unsupported ColoModel_ for 16bpp:"<<ColorMode_)
1131  ;
1132  res = -2;
1133  }
1134 
1135  return res;
1136 }
1137 
1138 unsigned int
1140 {
1141 
1142  unsigned int BpP = 0;
1143  unsigned int QuadletsPerPacket;
1144 
1145  int QuadletsPerFrame;
1146  double TransmissionTimePerFrame;
1147  double MaxCyclesPerFrame;
1148  unsigned int CyclesPerFrame;
1149 
1150  if (FramesPerSecond_ == 0.0)
1151  {
1152  BIASERR("VideoSource_DCAM::CalcBytesPerPacket(): FramesPerSecond_ is 0!");
1153  return 0;
1154  }
1155 
1156  dc1394_format7_get_packet_parameters(camera, DC1394_VIDEO_MODE_FORMAT7_0,
1157  &MinBpP_, &MaxBpP_);
1158 
1159  BIASDOUT(D_DCAM_F7,"MinBpP: "<<MinBpP_<<" MaxBpP: "<<MaxBpP_);
1160 
1161  QuadletsPerFrame = Width_ * Height_ * ColorChannels_ / 4;
1162  // time to transmit one frame to reach this fps in [ms]
1163  float fps = FramesPerSecond_;
1164  // evil hack to let 15 fps work
1165  if (fps > 14.9 && fps < 20.0)
1166  fps += 2.0;
1167  // hack to get 30 fps work
1168  if (fps > 29.9 && fps < 35)
1169  fps += 4.0;
1170  TransmissionTimePerFrame = 1000.0 / fps;
1171  // each 125usec one packet is transmitted
1172  MaxCyclesPerFrame = TransmissionTimePerFrame / 0.125;
1173  CyclesPerFrame = (int) MaxCyclesPerFrame;
1174 
1175  QuadletsPerPacket = QuadletsPerFrame / CyclesPerFrame;
1176 
1177  while ((QuadletsPerFrame % QuadletsPerPacket) != 0)
1178  {
1179  CyclesPerFrame--;
1180  QuadletsPerPacket = QuadletsPerFrame / CyclesPerFrame;
1181  }
1182 
1183  BIASDOUT(D_DCAM_F7,"FramesPerSecond: "<<FramesPerSecond_);
1184  BIASDOUT(D_DCAM_F7,"TransmissionTimePerFrame: "<<TransmissionTimePerFrame);
1185  BIASDOUT(D_DCAM_F7,"MaxCyclesPerFrame: "<<MaxCyclesPerFrame);
1186  BIASDOUT(D_DCAM_F7,"CyclesPerFrame: "<<CyclesPerFrame);
1187  BIASDOUT(D_DCAM_F7,"QuadletsPerFrame: "<<QuadletsPerFrame);
1188  BIASDOUT(D_DCAM_F7,"QuadletsPerPacket: "<<QuadletsPerPacket);
1189  BIASDOUT(D_DCAM_F7,"Resulting theoretical fps: "
1190  <<1000/((float)CyclesPerFrame * 0.125));
1191  BpP = QuadletsPerPacket * 4;
1192  if (BpP < MinBpP_)
1194  else if (BpP > MaxBpP_)
1196  else
1197  BytesPerPacket_ = BpP;
1198 
1199  return 0;
1200 }
1201 
1202 int
1204 {
1205  /*
1206  unsigned int realbpp;
1207 
1208  dc1394_set_format7_byte_per_packet(IEEE1394Handle_[IEEE1394Card_],
1209  DcamNodes_[SelectedCam_],
1210  MODE_FORMAT7_0,BytesPerPacket_);
1211  usleep(10000);
1212  dc1394_query_format7_byte_per_packet(IEEE1394Handle_[IEEE1394Card_],
1213  DcamNodes_[SelectedCam_],
1214  DcamMode_, &realbpp);
1215 
1216  TransmissionTime_ =(int) (((Width_*Height_*ColorChannels_)/realbpp) * 0.125);
1217  BIASDOUT(D_DCAM_F7,"requested BpP: "<< BytesPerPacket_ <<" got BpP: "<<realbpp
1218  <<" TransmissionTime_: "<<TransmissionTime_<<" ms")
1219  BytesPerPacket_ = realbpp;
1220  */
1221  BIASERR("VideoSource_DCAM::ApplyBytesPerPacket(): Sorry, not implemented");
1222  return -1;
1223 }
1224 
1225 int
1227 {
1228  BIASDOUT(D_DCAM,"VideoSource_DCAM::InitCam("<<SelectedCam_<<")");
1229 
1230  // Set camera per default to firewire B, if capable
1231  if (TryFirewireB_)
1232  {
1233  if (camera->bmode_capable)
1234  {
1235 
1236  dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
1237  dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_800);
1238  BIASDOUT(D_DCAM,"Set cam to Firewire B");
1239 
1240  }
1241  else
1242  {
1243  // set speed to 400
1244  dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
1245  }
1246  }
1247  else
1248  {
1249  dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
1251  sleep(1);
1252  }
1253 
1254  if (!DirectF7_)
1255  {
1256 
1257  if (Width_ != 0 || Height_ != 0 || UseBinning_)
1258  {
1259  // try to get user settings
1260  if (UserSizeToMode() < 0)
1261  {
1262  BIASERR("UserSizeToMode() failed, trying to find default values");
1263  //return -1;
1264  SelectDefault();
1265  }
1266 
1267  }
1268  else
1269  {
1270  // select default settings for cam
1271  if (UserMode_)
1272  {
1273  cout << "\n\tSetting mode from User\n\n" << endl;
1274  // get width and height from video mode.
1275  uint32_t w, h;
1276  dc1394_get_image_size_from_video_mode(camera, DcamMode_, &w, &h);
1277  Width_ = (int) w;
1278  Height_ = (int) h;
1280  dc1394framerates_t frameRates =
1281  CameraFramerates_[DC1394_VIDEO_MODE_MAX - DcamMode_];
1282  //cout<<"Mode: "<<DcamMode_<<" DC1394_FRAMERATE_NUM:"<<DC1394_FRAMERATE_NUM<<endl;
1283  //cout<<"Struct says:"<<frameRates.num<<endl;
1284  DcamFps_
1285  = (dc1394framerate_t) (frameRates.framerates[frameRates.num
1286  - 1]);
1287  // for(int i=0;i<DC1394_FRAMERATE_NUM;i++)
1288  // cout<<"frameRates:"<<frameRates.framerates[i]<<",";
1289  // cout<<endl;
1290  cout << "DcamFps_: " << DcamFps_ << endl;
1291  }
1292  else
1293  {
1294  SelectDefault();
1295  }
1296  }
1297  // set mode
1298  if (dc1394_video_set_mode(camera, DcamMode_) != DC1394_SUCCESS)
1299  {
1300  BIASERR("Unable to set default mode for camera");
1301  return -1;
1302  }
1304  sleep(1);
1305 
1306  if (DcamMode_ < DC1394_VIDEO_MODE_FORMAT7_MIN)
1307  {
1308 
1309  // set framerate
1310 
1311  // try to get user framerate
1312  if (FramesPerSecond_ != 0.0)
1313  {
1314  float fps = FramesPerSecond_;
1315  dc1394framerate_t videoframerate = DC1394_FRAMERATE_MIN;
1316 
1317  // set video frame rate from param file
1318  if (fps <= 1.875)
1319  videoframerate = DC1394_FRAMERATE_1_875;
1320  else if (fps <= 3.75)
1321  videoframerate = DC1394_FRAMERATE_3_75;
1322  else if (fps <= 7.5)
1323  videoframerate = DC1394_FRAMERATE_7_5;
1324  else if (fps <= 15.0)
1325  videoframerate = DC1394_FRAMERATE_15;
1326  else if (fps <= 30.0)
1327  videoframerate = DC1394_FRAMERATE_30;
1328  else if (fps <= 60.0)
1329  videoframerate = DC1394_FRAMERATE_60;
1330  else if (fps <= 120.0)
1331  videoframerate = DC1394_FRAMERATE_120;
1332  else if (fps <= 240.0)
1333  videoframerate = DC1394_FRAMERATE_240;
1334 
1335  // try to set user framerate
1336  if (videoframerate > DcamFps_)
1337  {
1338  videoframerate = DcamFps_;
1339  }
1340  if (dc1394_video_set_framerate(camera, videoframerate)
1341  != DC1394_SUCCESS)
1342  {
1343  BIASERR("Failed to set user frame rate, setting default");
1344  dc1394_video_set_framerate(camera, DcamFps_);
1345  }
1346  }
1347  else
1348  {
1349  if (dc1394_video_set_framerate(camera, DcamFps_)
1350  != DC1394_SUCCESS)
1351  {
1352  BIASERR("Failed to set default framerate");
1353  return -1;
1354  }
1355  cout << "Set default framerate" << endl;
1356  }
1357  }
1358  else if (DcamMode_ < DC1394_VIDEO_MODE_FORMAT7_MAX)
1359  {
1360  // format 7 if autodetected
1361  // set bytes per packet
1362  // TODO: Implement autoselcted format 7
1363  BIASERR("Autoselected Format 7 yet not implemented");
1364  return -1;
1365  // set mode
1366  }
1367 
1368  } //end !DirectF7_
1369  else
1370  {
1371  // set requested format 7 mode
1372  if (dc1394_video_set_mode(camera, DcamMode_) != DC1394_SUCCESS)
1373  {
1374  BIASERR("Failed to set user requested format 7 mode");
1375  return -1;
1376  }
1377  dc1394_format7_set_image_size(camera, DcamMode_, Width_, Height_);
1378  cout << "Left: " << Left_ << ", Top: " << Top_ << endl;
1379  // set size and left top
1380  dc1394_format7_set_image_position(camera, DcamMode_, Left_, Top_);
1381  dc1394_format7_set_color_coding(camera, DcamMode_, f7ColorCoding_);
1383 
1384  // set bytes per packet
1385  uint32_t bpp;
1386  if (BytesPerPacket_ == 0)
1387  {
1388  dc1394_format7_get_recommended_packet_size(camera, DcamMode_, &bpp);
1389  }
1390  else
1391  {
1392  bpp = BytesPerPacket_;
1393  }
1394  BIASDOUT(D_DCAM,"Set Bytes per packet to: " << bpp);
1395  dc1394_format7_set_packet_size(camera, DcamMode_, bpp);
1396  }
1397 
1398  // init capture mode of cam
1399  const int sizeInternCamBuff = NUM_DMA_BUFFERS;
1400 
1401  err = dc1394_capture_setup(camera, sizeInternCamBuff,
1402  DC1394_CAPTURE_FLAGS_DEFAULT);
1404  sleep(1);
1405 
1406  // try to reset camera
1407  if (err != DC1394_SUCCESS)
1408  {
1409  dc1394_reset_bus(camera);
1410  err = dc1394_capture_setup(camera, sizeInternCamBuff,
1411  DC1394_CAPTURE_FLAGS_DEFAULT);
1412  }
1413 
1414  if (err == DC1394_SUCCESS)
1415  {
1416  BIASDOUT(D_DCAM,"Initialization successful");
1417  }
1418  else
1419  {
1420  BIASDOUT(D_DCAM,"Initialization failed");
1421  return -1;
1422  }
1423 
1424  // here we have to test, if there is really some pic from cam, or if it is to slow...
1425  // this is possible because firewire b cams can be put on firewire a bus.
1426 
1427  //dc1394_video_set_transmission(camera, DC1394_ON);
1428  //cout << "set transmission ON" << endl;
1429  //dc1394video_frame_t * frame;
1430  //
1431  //err = dc1394_capture_dequeue(camera,DC1394_CAPTURE_POLICY_POLL,&frame);
1432  //cout << "dequeued frame with code: " << err << endl;
1433  //sleep(5);
1434  //dc1394_capture_enqueue(camera,frame);
1435  //cout << "gave frame back" << endl;
1436  //
1437  //
1438  //dc1394_video_set_transmission(camera,DC1394_OFF);
1439  //cout << "stopped transmission" << endl;
1440  //
1441  //if(err != DC1394_SUCCESS){
1442  //dc1394_capture_stop(camera);
1443  //cout << "stopped camera" << endl;
1444  // cout << "set speed down" << endl;
1445  // dc1394_video_set_operation_mode( camera, DC1394_OPERATION_MODE_LEGACY );
1446  // dc1394_video_set_iso_speed( camera, (dc1394speed_t)(DC1394_ISO_SPEED_400) );
1447  // dc1394_capture_setup(camera, sizeInternCamBuff, DC1394_CAPTURE_FLAGS_DEFAULT);
1448  //}
1449 
1450 
1451  // dc1394_video_set_transmission( camera, DC1394_ON );
1452  // dc1394video_frame_t * frame;
1453  // bool capturing = false;
1454  // while(!capturing){
1455  // // try 10 times to get an image
1456  // for(int i = 0; i < 10; i++){
1457  // err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_POLL, &frame);
1458  // //cout << "Errorcode: " << err << endl;
1459  // if(err == DC1394_SUCCESS){
1460  // capturing = true;
1461  // dc1394_video_set_transmission( camera, DC1394_OFF );
1462  // i = 10;
1463  // //cout << "captured pic successfully" << endl;
1464  // }
1465  // dc1394_capture_enqueue(camera,frame);
1466  //
1467  // if(i == 9 && err == DC1394_FAILURE){
1468  // // try to set speed down
1469  // cout << "Setting speed down" << endl;
1470  // dc1394_video_set_transmission( camera, DC1394_OFF );
1471  // dc1394_capture_stop(camera);
1472  // dc1394_video_set_operation_mode( camera, DC1394_OPERATION_MODE_LEGACY );
1473  // err = dc1394_video_set_iso_speed( camera, (dc1394speed_t)(DC1394_ISO_SPEED_400) );
1474  // dc1394_capture_setup(camera, sizeInternCamBuff, DC1394_CAPTURE_FLAGS_DEFAULT);
1475  // dc1394_video_set_transmission( camera, DC1394_ON );
1476  // i = 0;
1477  // }
1478  // //cout << "test" << endl;
1479  // usleep(100000);
1480  // }
1481  // }
1482 
1483  CompleteInitialized_ = true;
1484  //cout << "did init" << endl;
1486 }
1487 
1488 
1489 void
1492  if( CompleteInitialized_){
1494  }
1495 }
1496 
1497 int
1498 VideoSource_DCAM::AutoMode(dc1394feature_t feature, dc1394feature_mode_t mode)
1499 {
1500  if (dc1394_feature_set_mode(camera, feature, mode) != DC1394_SUCCESS)
1501  {
1502  BIASERR("VideoSource_DCAM::AutoMode(): failed to set feature auto mode");
1503  return -1;
1504  }
1505 
1506  return 0;
1507 
1508 }
1509 void
1511 {
1512  dc1394feature_mode_t mode;
1513  if (b)
1514  mode = DC1394_FEATURE_MODE_AUTO;
1515  else
1516  mode = DC1394_FEATURE_MODE_MANUAL;
1517 
1518  AutoMode(DC1394_FEATURE_SHUTTER, mode);
1519 }
1520 bool
1522 {
1523  dc1394feature_mode_t mode;
1524  if (dc1394_feature_get_mode(camera, DC1394_FEATURE_SHUTTER, &mode)
1525  == DC1394_SUCCESS)
1526  {
1527  if (DC1394_FEATURE_MODE_AUTO == mode)
1528  return true;
1529  }
1530  return false;
1531 }
1532 
1533 
1534 void
1536 SetAutoBrightness(bool brightness){
1537  dc1394feature_mode_t mode;
1538  if (brightness)
1539  mode = DC1394_FEATURE_MODE_AUTO;
1540  else
1541  mode = DC1394_FEATURE_MODE_MANUAL;
1542  AutoMode(DC1394_FEATURE_BRIGHTNESS, mode);
1543 }
1544 
1545 bool
1548  dc1394feature_mode_t mode;
1549  if (dc1394_feature_get_mode(camera, DC1394_FEATURE_BRIGHTNESS, &mode)
1550  == DC1394_SUCCESS)
1551  {
1552  if (DC1394_FEATURE_MODE_AUTO == mode)
1553  return true;
1554  }
1555  return false;
1556 }
1557 
1558 void
1560 {
1561  dc1394feature_mode_t mode;
1562  if (gain)
1563  mode = DC1394_FEATURE_MODE_AUTO;
1564  else
1565  mode = DC1394_FEATURE_MODE_MANUAL;
1566  AutoMode(DC1394_FEATURE_GAIN, mode);
1567 }
1568 
1569 bool
1571 {
1572  dc1394feature_mode_t mode;
1573  if (dc1394_feature_get_mode(camera, DC1394_FEATURE_GAIN, &mode)
1574  == DC1394_SUCCESS)
1575  {
1576  if (DC1394_FEATURE_MODE_AUTO == mode)
1577  return true;
1578  }
1579  return false;
1580 }
1581 
1582 int
1583 VideoSource_DCAM::OnePushAuto(dc1394feature_t feature)
1584 {
1585  dc1394error_t res;
1586  if (CamModel_ == CAMERA_PTGREY_DRAGONFLY_COLOR && feature
1587  == DC1394_FEATURE_WHITE_BALANCE)
1588  {
1590  }
1591  else
1592  {
1593  res = dc1394_feature_set_mode(camera, feature,
1594  DC1394_FEATURE_MODE_ONE_PUSH_AUTO);
1595 
1596  if (res != DC1394_SUCCESS)
1597  {
1598  BIASERR("VideoSource_DCAM::OnePushAuto()");
1599  return -1;
1600  }
1601  }
1602 
1603  return 0;
1604 }
1605 
1606 bool
1607 VideoSource_DCAM::OnePushRunning(dc1394feature_t feature)
1608 {
1609 
1610  dc1394error_t res;
1611  dc1394feature_mode_t mode;
1612  res = dc1394_feature_get_mode(camera, feature, &mode);
1613  if (res != DC1394_SUCCESS)
1614  return -1;
1615 
1616  if (mode == DC1394_FEATURE_MODE_ONE_PUSH_AUTO)
1617  {
1618  return true;
1619  }
1620  else
1621  return false;
1622 }
1623 
1624 int
1626 {
1627  dc1394error_t res;
1628  if (trigger)
1629  {
1630  Trigger_ = DC1394_TRIGGER_MODE_0;
1631  BIASDOUT(D_DCAM,"Triggermode: 1 (extern)");
1632  res = dc1394_external_trigger_set_power(camera, DC1394_ON);
1633  }
1634  else
1635  {
1636  Trigger_ = DC1394_TRIGGER_MODE_3;
1637  BIASDOUT(D_DCAM,"Triggermode: 3 (intern)");
1638  // fix for sony not supporting trigger modes correctly
1640  res = dc1394_external_trigger_set_power(camera, DC1394_OFF);
1641  }
1642  }
1643 
1644  // fix for sony not supporting trigger modes correctly
1645  if (CamModel_ != CAMERA_SONY_DFW_X700 || Trigger_ != DC1394_TRIGGER_MODE_3) {
1646  res = dc1394_external_trigger_set_mode(camera, Trigger_);
1647  return res;
1648  } else {
1649  return 0;
1650  }
1651  if (res != DC1394_SUCCESS)
1652  {
1653  BIASERR("unable to set camera "<<ID_<<" to trigger mode ");
1654  return -1;
1655  }
1656 
1657  return 0;
1658 
1659 }
1660 
1661 unsigned int
1662 VideoSource_DCAM::GetFeature(dc1394feature_t feature)
1663 {
1664 
1665  dc1394bool_t isPresent;
1666  dc1394_feature_is_present(camera, feature, &isPresent);
1667  unsigned int value;
1668  if (isPresent)
1669  {
1670  dc1394_feature_get_value(camera, feature, &value);
1671  }
1672  else
1673  {
1674  BIASERR("Feature not supported by camera "<<ID_);BIASASSERT(false);
1675  return -1;
1676  }
1677 
1678  return value;
1679 }
1680 
1681 int
1682 VideoSource_DCAM::SetFeature(dc1394feature_t feature, unsigned int value)
1683 {
1684  dc1394bool_t isPresent;
1685  dc1394_feature_is_present(camera, feature, &isPresent);
1686 
1687  if (isPresent)
1688  {
1689  dc1394feature_mode_t mode = DC1394_FEATURE_MODE_MANUAL;
1690  AutoMode(feature, mode);
1691  dc1394_feature_set_value(camera, feature, value);
1692  }
1693  else
1694  {
1695  BIASERR("Feature not supported by camera "<<ID_);
1696  return -1;
1697  }
1698 
1699  return 0;
1700 }
1701 
1702 int
1703 VideoSource_DCAM::SetLeftTop(unsigned int left, unsigned int top)
1704 {
1705  if (left <= (MaxWidth_ - Width_) && top <= (MaxHeight_ - Height_))
1706  {
1707  Top_ = top;
1708  Left_ = left;
1709  UserTopLeft_ = true;
1710  }
1711  else
1712  {
1713  BIASERR("VideoSource_DCAM::SetLeftTop() values too large:"<<left<<"x"<<top);
1714  return -1;
1715  }
1716 
1717  return 0;
1718 }
1719 
1720 // exptime is given in milliseconds (one thousand of a second)
1721 int
1723 {
1724  dc1394feature_t feature = DC1394_FEATURE_SHUTTER;
1725  int value = 0;
1726  switch (CamModel_)
1727  {
1728  case CAMERA_SONY_DFW_X700:
1729  if ((exptime <= 16.05120063) && (exptime >= 0.13376))
1730  value = 2049 - int(round(exptime * 28636363.0 / (1197.0 * 800.0 * 2.0)));
1731  else if ((exptime <= 0.13376) && (exptime > 0.067))
1732  {
1733  value = 2048;
1734  }
1735  else if ((exptime <= 0.067) && (exptime >= 0.00012))
1736  {
1737  value = (int) (2848.4 - round(28636363.0 * exptime / (1197.0 * 2.0)));
1738  }
1739  else if ((exptime <= 0.00012) && (exptime >= 0.00004))
1740  {
1741  value = 2848;
1742  }
1743  else
1744  {
1745  BIASERR("Exposuretime out of bounds: "<<exptime);
1746  return -1;
1747  }
1748  break;
1749  case CAMERA_SONY_DFW_V500:
1750  if (exptime <= 5.0 && exptime >= (1.0 / 30))
1751  value = 0x800 - (int) (30 * exptime);
1752  else if (exptime < (1.0 / 30) && exptime >= (1.0 / 10000.0))
1753  value = (int) (2573.6 - 15734.3 * exptime);
1754  else
1755  {
1756  BIASERR("Exposuretime out of bounds: "<<exptime);
1757  return -1;
1758  }
1759  break;
1771  dc1394_feature_set_absolute_control(camera, feature, DC1394_ON);
1772  //these are microseconds
1773  dc1394_feature_set_absolute_value(camera, feature, exptime);
1774  //cout<<"`olute shutter value:"<<exptime<<endl;
1775  return 0;
1776  break;
1777  case CAMERA_UNIBRAIN_FIREI:
1778  // map [1,99] ms to range [0,7]
1779  value = rint((1000.0*exptime) / 99.0*7.0);
1780  break;
1782  value = rint(exptime*1000.0);
1783  break;
1784  default:
1785  BIASERR("Sorry your Camera Model:"<<CamModel_<<" is not supported.");
1786  value = -1;
1787  }
1788 
1789  if (value > 0)
1790  return SetFeature(DC1394_FEATURE_SHUTTER, value);
1791  else
1792  return -1;
1793 
1794  return 0;
1795 }
1796 
1797 float
1799 {
1800  float exptime = 0.0;
1801  int shutter = GetFeature(DC1394_FEATURE_SHUTTER);
1802 
1803  switch (CamModel_)
1804  {
1805  // see technical ,manual. p. 27 (JW)
1806  case CAMERA_SONY_DFW_X700:
1807  if (shutter < 2048)
1808  exptime = ((float) (2048 - shutter + 1) * (1197.0 * 800.0 * 2.0)
1809  / (28.636363 * 1000000.0));
1810  else
1811  // OK, linear dependency to intensity (apetersen, jw 11/2004)
1812  if (shutter < 2848)
1813  exptime = ((2848.4 - float(shutter)) * (1197.0 * 2.0) / (28.636363
1814  * 1000000.0));
1815  else
1816  exptime = 50.0 / 1000000.0;
1817  break;
1818  case CAMERA_SONY_DFW_V500:
1819  if (shutter < 0x800)
1820  exptime = ((float) (shutter - 2048) / 30.0);
1821  else
1822  exptime = ((float) (shutter - 2573.6) / -15734.3);
1823  break;
1835  default:
1836  dc1394_feature_get_absolute_value(camera, DC1394_FEATURE_SHUTTER, &exptime);
1837  break;
1838  }
1839 
1840  return exptime;
1841 }
1842 
1843 int
1844 VideoSource_DCAM::SetGain(float gain) // gain is in dB
1845 {
1846  dc1394feature_t feature = DC1394_FEATURE_GAIN;
1847 
1848  int res = 0;
1849  switch (CamModel_)
1850  {
1851  case CAMERA_SONY_DFW_X700:
1852  {
1853  int min = 0x800;
1854  int max = 0x8b4;
1855  int value = min + (int) (gain * (float) (max - min));
1856  res = SetFeature(feature, value);
1857  break;
1858  }
1859  case CAMERA_SONY_DFW_V500:
1860  {
1861  int min = 0x00;
1862  int max = 0x12;
1863  int value = min + (int) (gain * (float) (max - min));
1864  res = SetFeature(feature, value);
1865  break;
1866  }
1867  case CAMERA_UNIBRAIN_FIREI:
1868  {
1869  int value = gain * 255.0 / 30.0;
1870  SetFeature(feature, value);
1871  break;
1872  }
1884  default:
1885  dc1394_feature_set_absolute_control(camera, feature, DC1394_ON);
1886  //cout<<"Setting gain:"<<gain<<endl;
1887  res = (int)dc1394_feature_set_absolute_value(camera, feature, gain);
1888  break;
1889  }
1890  return res;
1891 }
1892 
1893 float
1895 {
1896  float gain = 0.0; // gain is in dB
1897 
1898  switch (CamModel_)
1899  {
1900  case CAMERA_SONY_DFW_X700:
1901  {
1902  int min = 0x800;
1903  int max = 0x8b4;
1904  int value = GetFeature(DC1394_FEATURE_GAIN);
1905  cout << "Value in GetGain from GetFeature(...) :" << value << endl;
1906  // translate gain to dB
1907  gain = (float) (value - min) / (float) (max - min);
1908  }
1909  break;
1910  case CAMERA_SONY_DFW_V500:
1911  {
1912  int min = 0x00;
1913  int max = 0x12;
1914  int value = GetFeature(DC1394_FEATURE_GAIN);
1915  cout << "Value in GetGain from GetFeature(...) :" << value << endl;
1916  // translate gain to dB
1917  gain = (float) (value - min) / (float) (max - min);
1918  }
1919  break;
1920  case CAMERA_UNIBRAIN_FIREI:
1921  gain = GetFeature(DC1394_FEATURE_GAIN);
1922  break;
1934  default:
1935  {
1936  //dc1394error_t res =
1937  dc1394_feature_get_absolute_value(camera,DC1394_FEATURE_GAIN, &gain);
1938  //cout<<"GetGain()"<<gain<<endl;
1939  break;
1940  }
1941  }
1942  return gain;
1943 }
1944 
1945 
1946 int
1948 SetBrightness(float brightness){
1949  dc1394feature_t feature = DC1394_FEATURE_BRIGHTNESS;
1950  dc1394_feature_set_absolute_control(camera, feature, DC1394_ON);
1951  // cout<<"Setting brightness:"<<brightness<<endl;
1952  dc1394error_t res = dc1394_feature_set_absolute_value(camera, feature, brightness);
1953  return (int)res;
1954 }
1955 
1956 float
1959  float brightness = 0.0; //
1960  dc1394_feature_get_absolute_value(camera,DC1394_FEATURE_BRIGHTNESS, &brightness);
1961  //cout<<"Getting brightness:"<<brightness<<endl;
1962  return brightness;
1963 }
1964 
1965 int
1967 {
1968  int res;
1969  res = SetFeature(DC1394_FEATURE_GAMMA, g); //+128;
1970  if (res < 0) return res;
1971  else return 0;
1972 }
1973 
1974 int
1976 {
1977  int value;
1978  value = GetFeature(DC1394_FEATURE_GAMMA);
1979  return value; // -128; why 128 ??
1980 }
1981 
1982 int
1983 VideoSource_DCAM::SetWhiteBalance(float rvalue, float bvalue)
1984 {
1985  //rvalue and bvalue are in range -0.5 to 0.5
1986  //cout<<"Setting whiteBalance:"<<endl;
1987  int ibval = 0, irval = 0;
1988  switch (CamModel_)
1989  {
1990  case CAMERA_SONY_DFW_X700:
1991  case CAMERA_SONY_DFW_V500:
1992  // the values for sony cameras are from 0x00 to 0xFF,
1993  // scale to 0-255 in integer (cmenk)
1994  ibval = (int) rint((bvalue + 0.5f ) * 255.0f);
1995  irval = (int) rint((rvalue + 0.5f ) * 255.0f);
1996  if (ibval > 255)
1997  ibval = 255;
1998  if (irval > 255)
1999  irval = 255;
2000  if (ibval < 0)
2001  ibval = 0;
2002  if (irval < 0)
2003  irval = 0;
2004  break;
2007  ibval = (unsigned int) rint(bvalue*32) + 32;
2008  irval = (unsigned int) rint(rvalue*32) + 32;
2009  if (ibval > 63)
2010  ibval = 63;
2011  if (irval > 63)
2012  irval = 63;
2013  if (ibval < 0)
2014  ibval = 0;
2015  if (irval < 0)
2016  irval = 0;
2017  //cerr << irval <<", "<<ibval<<endl;
2018  break;
2020  ibval = (unsigned int) rint(bvalue*63) + 63;
2021  irval = (unsigned int) rint(rvalue*63) + 63;
2022  if (ibval > 127)
2023  ibval = 127;
2024  if (irval > 127)
2025  irval = 127;
2026  if (ibval < 0)
2027  ibval = 0;
2028  if (irval < 0)
2029  irval = 0;
2030  //cerr << irval <<", "<<ibval<<endl;
2031  break;
2032  case CAMERA_PTGREY_GRASSHOPPER_COLOR://IEEE1394
2033  default:
2034  ibval = (unsigned int) rint(bvalue*512) + 512;
2035  irval = (unsigned int) rint(rvalue*512) + 512;
2036  if (ibval > 1023)
2037  ibval = 1023;
2038  if (irval > 1023)
2039  irval = 1023;
2040  if (ibval < 0)
2041  ibval = 0;
2042  if (irval < 0)
2043  irval = 0;
2044  //cerr << irval <<", "<<ibval<<endl;
2045  break;
2046  }
2047  if (dc1394_feature_whitebalance_set_value(camera, ibval, irval)== DC1394_SUCCESS)
2048  return 0;
2049  else{
2050  BIASWARN("Could not set white balance, feature not supported by either camera or lib.");
2051  return -2;
2052  }
2053 }
2054 
2055 int
2057 {
2058  dc1394feature_mode_t mode;
2059  int res = 0;
2060 
2061  BIASDOUT(D_DCAM,"Entering SetCamera()");
2062 
2063  if (camparam.AutoShutterChanged)
2064  {
2065  if (camparam.AutoShutter)
2066  mode = DC1394_FEATURE_MODE_AUTO;
2067  else
2068  mode = DC1394_FEATURE_MODE_MANUAL;
2069 
2070  res = AutoMode(DC1394_FEATURE_SHUTTER, mode);
2071  if (res < 0)
2072  return res;
2073  }
2074  if (camparam.AutoGainChanged)
2075  {
2076  if (camparam.AutoGain)
2077  mode = DC1394_FEATURE_MODE_AUTO;
2078  else
2079  mode = DC1394_FEATURE_MODE_MANUAL;
2080 
2081  res = AutoMode(DC1394_FEATURE_GAIN, mode);
2082  if (res < 0)
2083  return res;
2084  }
2085  if (camparam.AutoWhiteBalanceChanged)
2086  {
2087  if (camparam.AutoWhiteBalance)
2088  mode = DC1394_FEATURE_MODE_AUTO;
2089  else
2090  mode = DC1394_FEATURE_MODE_MANUAL;
2091 
2092  res = AutoMode(DC1394_FEATURE_WHITE_BALANCE, mode);
2093  if (res < 0)
2094  return res;
2095  }
2096 
2097  if (camparam.ShutterChanged)
2098  {
2099  res = SetShutter(camparam.Shutter);
2100  if (res < 0)
2101  return res;
2102  }
2103  if (camparam.GainChanged)
2104  {
2105  res = SetGain(camparam.Gain);
2106  if (res < 0)
2107  return res;
2108  }
2109  if (camparam.WhiteBalanceChanged)
2110  {
2111  res = SetFeature(DC1394_FEATURE_WHITE_BALANCE, camparam.WhiteBalance);
2112  if (res < 0)
2113  return res;
2114  }
2115  if (camparam.SharpenChanged)
2116  {
2117  res = SetFeature(DC1394_FEATURE_SHARPNESS, camparam.Sharpen);
2118  if (res < 0)
2119  return res;
2120  }
2121  if (camparam.GammaModeChanged)
2122  {
2123  res = SetGammaMode(camparam.GammaMode);
2124  if (res < 0)
2125  return res;
2126  }
2127  if (camparam.OpticalFilterChanged)
2128  {
2129  // double the call, to cope with ignorant cams
2130  res = SetFeature(DC1394_FEATURE_OPTICAL_FILTER, camparam.OpticalFilter);
2131  res = SetFeature(DC1394_FEATURE_OPTICAL_FILTER, camparam.OpticalFilter);
2132  if (res < 0)
2133  return res;
2134  }
2135  if (camparam.WhiteBalanceOnePush)
2136  {
2137  res = OnePushAuto(DC1394_FEATURE_WHITE_BALANCE);
2138  if (res < 0)
2139  return res;
2140  }
2141 
2142  return res;
2143 }
2144 
2147 {
2148  unsigned int vendor = euid >> 40;
2149  unsigned int model = (euid >> 12) & 0xFF;
2150  unsigned int model_lo = (euid) & 0xFFF;
2151  BIASDOUT(D_DCAM,"EUID:"<<hex<<euid<<" vendorid: "<<vendor<<" modelid: "<<model<<dec);
2152  cout << "EUID:" << hex << euid << " vendorid: " << vendor << " modelid: "
2153  << model << dec << endl;
2154 
2155  switch (vendor)
2156  {
2157  // Sony
2158  case 0x080046:
2159  {
2160  BIASDOUT(D_DCAM,"Vendor: Sony");
2161  switch (model)
2162  {
2163  case 0x20:
2164  // BytesPerPixel_ = 1.0;
2165  // ColorMode_ = ImageBase::CM_UYVY422;
2166  return CAMERA_SONY_DFW_V500;
2167  case 0x60:
2168  // BytesPerPixel_ = 1.0;
2169  // ColorMode_ = ImageBase::CM_UYVY422;
2170  return CAMERA_SONY_DFW_X700;
2171  default:
2172  return CAMERA_UNKNOWN;
2173  }
2174  }
2175  case 0x00b09d: // PtGey
2176  {
2177  BIASDOUT(D_DCAM,"Vendor: PointGrey Research");
2178  //cout<<"Model is: "<<model<<endl;
2179  switch (model)
2180  {
2181  case 0xcc:
2182  BIASDOUT(D_DCAM,"Model: Dragonfly BW LowRes")
2183  ;
2184  // ColorMode_ = ImageBase::CM_Grey;
2185  // Shift16_ = 6; // 16 bits - 10 significant bits
2187  case 0x4c:
2188  BIASDOUT(D_DCAM,"Model: Dragonfly Color LowRes")
2189  ;
2190  // ColorMode_ = ImageBase::CM_Bayer_RGGB;
2191  // Shift16_ = 6; // 16 bits - 10 significant bits
2193  case 0xff:
2194  case 0xfe:
2195  BIASDOUT(D_DCAM,"Model: Dragonfly B&W HiRes")
2196  ;
2197  // ColorMode_ = ImageBase::CM_Grey;
2198  Shift16_ = 6; // 16 bits - 10 significant bits
2200  case 0xf5:
2201  case 0x28:
2202  BIASDOUT(D_DCAM,"Model: Scorpion Color 1600")
2203  ;
2204  // ColorMode_ = ImageBase::CM_Bayer_GBRG;
2205  // ok, RGGB seems to be right, but did it changed ? friso
2206  // ColorMode_ = ImageBase::CM_Bayer_RGGB;
2207  // Shift16_ = 4; // 16 bits - 12 significant bits
2208 
2210  case 0x18:
2211  BIASDOUT(D_DCAM,"Model: FireFly Color")
2212  ;
2213  // ColorMode_ = ImageBase::CM_Bayer_GBRG;
2215  case 0x16:
2216  BIASDOUT(D_DCAM,"Model: FireFly BW") ;
2217  //ColorMode_ = ImageBase::CM_Grey;
2218  return CAMERA_PTGREY_FIREFLY_BW;
2219  case 0xfb:
2220  if (model_lo == 0x355)
2221  {
2222  BIASDOUT(D_DCAM,"Model: GrassHopper Color");
2223  // ColorChannels_ = 3;
2224  // ColorMode_ = ImageBase::CM_RGB;
2225  // ColorChannels_ = 2;
2226  // ColorMode_ = ImageBase::CM_UYVY422;
2228  }
2229  else
2230  {
2231  BIASDOUT(D_DCAM,"Model: DragonFly2 HIRES Color");
2232  // ColorChannels_ = 3;
2233  // ColorMode_ = ImageBase::CM_RGB;
2235  }
2236  case 0x7:
2237  case 0xb2:
2238  case 0xc1:
2239  // ColorChannels_ = 3;
2240  // ColorMode_ = ImageBase::CM_Bayer_RGGB ;
2241  // cout<<"VS: PTGH:"<<endl;
2242  // BIASDOUT(D_DCAM,"Model: PtGrey GrassHopper Color");
2244  case 0x9:
2245  ColorChannels_ = 3;
2246  // ColorMode_ = ImageBase::CM_RGB;
2247  BIASDOUT(D_DCAM,"Model: PtGrey FLEA2 BW")
2248  ;
2249  return CAMERA_PTGREY_FLEA2_BW;
2250  case 0xcf:
2251  ColorChannels_ = 3;
2252  // ColorMode_ = ImageBase::CM_Bayer_GBRG;
2253  BIASDOUT(D_DCAM,"Model: PtGrey Bumblebee XB3")
2254  ;
2256  case 0x14:
2257  ColorChannels_ = 2;
2258  // ColorMode_ = ImageBase::CM_Bayer_GBRG;
2259  BIASDOUT(D_DCAM,"Model: PtGrey Bumblebee XB2")
2260  ;
2262  default:
2263  BIASDOUT(D_DCAM,"Model: Unknown:"<<model)
2264  ;
2265  return CAMERA_UNKNOWN;
2266  }
2267  }
2268  case 0x081443:
2269  {// UniBrain
2270  BIASDOUT(D_DCAM,"Vendor: Unibrain");
2271 
2272  switch (model)
2273  {
2274  case 0x37:
2275  case 0x30:
2276  BIASDOUT(D_DCAM,"Model: Fire-i")
2277  ;
2278  // ColorMode_ = ImageBase::CM_RGB;
2279  // ColorChannels_ = 3;
2280  return CAMERA_UNIBRAIN_FIREI;
2281  default:
2282  cout << "Unknown modelid: 0x" << hex << model << endl;
2283  }
2284  }
2285  case 0x97e:
2286  {
2287  BIASDOUT(D_DCAM,"Vendor: NET Gmbh");
2288  switch (model)
2289  {
2290  case 0x0:
2291  return CAMERA_NET_FO323SC;
2292  }
2293  }
2294  break;
2295  case 0xb02a:
2296  {
2297  switch (model)
2298  {
2299  case 0x20:
2301  }
2302  }
2303  break;
2304  // unknown vendorid
2305  default:
2306  return CAMERA_UNKNOWN;
2307  }
2308 
2309  return CAMERA_UNKNOWN;
2310 
2311 }
2312 /*
2313  void VideoSource_DCAM::PrintFormatAndMode_()
2314  {
2315  // cout <<"Internal Format: "<<DcamFormat_<<" Mode: "<< DcamMode_<<endl;
2316  int f = DcamFormat_ - FORMAT_VGA_NONCOMPRESSED;
2317  int m=0;
2318  switch (f) {
2319  case 0: m = DcamMode_ - MODE_FORMAT0_MIN; break;
2320  case 1: m = DcamMode_ - MODE_FORMAT1_MIN; break;
2321  case 2: m = DcamMode_ - MODE_FORMAT2_MIN; break;
2322  case 7: m = DcamMode_ - MODE_FORMAT7_MIN; break;
2323  }
2324  cout <<"Format: "<<f<<" Mode: "<<m;
2325 
2326  }
2327  */
2328 int
2330 {
2331 
2332  cout << "Width: " << Width_ << "UnitWidth: " << UnitWidth_ << endl;
2333  if ((unsigned int) Width_ % UnitWidth_ > 0)
2334  {
2335  BIASERR("VideoSource_DCAM::UserSizeToMode(): width of "<<Width_
2336  <<" not multiple of: "<<UnitWidth_);
2337  return -1;
2338  }
2339  if ((unsigned int) Height_ % UnitHeight_ > 0)
2340  {
2341  BIASERR("VideoSource_DCAM::UserSizeToMode(): height of "<<Height_
2342  <<" not multiple of: "<<UnitHeight_);
2343  return -1;
2344  }
2345  if (!UseBinning_)
2346  {
2347  DcamMode_ = DC1394_VIDEO_MODE_FORMAT7_0;
2348  //DcamFormat_ = FORMAT_SCALABLE_IMAGE_SIZE;
2349  if (!UserTopLeft_)
2350  {
2351  Left_ = (MaxWidth_ - Width_) / 2;
2352  Top_ = (MaxHeight_ - Height_) / 2;
2353  }
2354  BIASDOUT(D_DCAM_F7,"Using format7: "<<Width_<<"x"<<Height_<<"+"<<Left_
2355  <<"+"<<Top_);
2356  }
2357  else
2358  { // Binning for PtGrey Dragonfly
2359  BIASDOUT(D_DCAM_F7,"Using format7 Mode 1 (Binning): "<<Width_<<"x"<<Height_
2360  <<"+"<<Left_<<"+"<<Top_);
2361  DcamMode_ = DC1394_VIDEO_MODE_FORMAT7_1;
2362  // DcamFormat_ = FORMAT_SCALABLE_IMAGE_SIZE;
2363  ColorChannels_ = 1;
2364  }
2365 
2366  return 0;
2367 }
2368 
2369 int
2370 VideoSource_DCAM::SetColorFromMode_(dc1394video_mode_t videoMode)
2371 {
2372  dc1394color_coding_t colorCoding;
2373  dc1394color_filter_t colorFilter; //Bayer Pattern
2374  if (!DirectF7_)
2375  {
2376  dc1394_get_color_coding_from_video_mode(camera, videoMode, &colorCoding);
2377  }
2378  else
2379  {
2380  colorCoding = f7ColorCoding_;
2381  dc1394error_t res = dc1394_format7_get_color_filter(camera, videoMode, &colorFilter);
2382  if (res != DC1394_SUCCESS) {
2383 // if (res == DC1394_FUNCTION_NOT_SUPPORTED) {
2384 // known problem with dragonfly low res color camera, fkellner 07/11
2385 // }
2386  BIASWARN("Camera did not report a valid color filter, assuming RGGB");
2387  colorFilter = DC1394_COLOR_FILTER_RGGB;
2388  }
2389  }
2390 
2391  // cout << "Color Coding: " << colorCoding << endl;
2392  // select BIAS Colormodel
2393  switch (colorCoding)
2394  {
2395  case DC1394_COLOR_CODING_MONO8:
2397  ColorChannels_ = 1;
2398  break;
2399 
2400  case DC1394_COLOR_CODING_YUV411:
2402  ColorChannels_ = 1;
2403  break;
2404 
2405  case DC1394_COLOR_CODING_YUV422:
2406  ColorChannels_ = 2;
2408  break;
2409 
2410  case DC1394_COLOR_CODING_YUV444:
2411  ColorChannels_ = 1;
2413  break;
2414 
2415  case DC1394_COLOR_CODING_RGB8:
2416  ColorChannels_ = 3;
2418  break;
2419 
2420  case DC1394_COLOR_CODING_RGB16:
2421  ColorChannels_ = 3;
2422  BytesPerPixel_ = 2.0;
2424  break;
2425 
2426  case DC1394_COLOR_CODING_MONO16:
2427  ColorChannels_ = 1;
2429  BytesPerPixel_ = 2.0;
2430  break;
2431 
2432  case DC1394_COLOR_CODING_RAW8:
2433  if(colorFilter == DC1394_COLOR_FILTER_RGGB)
2435  else if(colorFilter == DC1394_COLOR_FILTER_GBRG)
2437  else if(colorFilter == DC1394_COLOR_FILTER_GRBG)
2439  else if(colorFilter == DC1394_COLOR_FILTER_BGGR)
2441  ColorChannels_ = 1;
2442  break;
2443 
2444  case DC1394_COLOR_CODING_RAW16:
2445  if(colorFilter == DC1394_COLOR_FILTER_RGGB)
2447  else if(colorFilter == DC1394_COLOR_FILTER_GBRG)
2449  else if(colorFilter == DC1394_COLOR_FILTER_GRBG)
2451  else if(colorFilter == DC1394_COLOR_FILTER_BGGR)
2453  ColorChannels_ = 1;
2454  BytesPerPixel_ = 2.0;
2455  break;
2456 
2457  default:
2458  ColorChannels_ = 1;
2460  }
2461 
2462  //
2463  //DC1394_COLOR_CODING_MONO16S,
2464  // DC1394_COLOR_CODING_RGB16S,
2465  return 0;
2466 }
2467 
2468 std::string VideoSource_DCAM::
2469 VideoModeToString(dc1394video_mode_t mode){
2470  string s;
2471  switch(mode){
2472  case DC1394_VIDEO_MODE_160x120_YUV444:
2473  s = "160 x 120, YUV444";
2474  break;
2475  case DC1394_VIDEO_MODE_320x240_YUV422:
2476  s = "320 x 240, YUV422";
2477  break;
2478  case DC1394_VIDEO_MODE_640x480_YUV411:
2479  s = "640 x 480, YUV411";
2480  break;
2481  case DC1394_VIDEO_MODE_640x480_YUV422:
2482  s = "640 x 480, YUV422";
2483  break;
2484  case DC1394_VIDEO_MODE_640x480_RGB8:
2485  s = "640 x 480, RGB";
2486  break;
2487  case DC1394_VIDEO_MODE_640x480_MONO8:
2488  s = "640 x 480, Mono8";
2489  break;
2490  case DC1394_VIDEO_MODE_640x480_MONO16:
2491  s = "640 x 480, Mono16";
2492  break;
2493  case DC1394_VIDEO_MODE_800x600_YUV422:
2494  s = "800 x 600, YUV422";
2495  break;
2496  case DC1394_VIDEO_MODE_800x600_RGB8:
2497  s = "800 x 600, RGB";
2498  break;
2499  case DC1394_VIDEO_MODE_800x600_MONO8:
2500  s = "800 x 600, Mono8";
2501  break;
2502  case DC1394_VIDEO_MODE_800x600_MONO16:
2503  s = "800 x 600, Mono16";
2504  break;
2505  case DC1394_VIDEO_MODE_1024x768_YUV422:
2506  s = "1024 x 768, YUV442";
2507  break;
2508  case DC1394_VIDEO_MODE_1024x768_RGB8:
2509  s = "1024 x 768, RGB";
2510  break;
2511  case DC1394_VIDEO_MODE_1024x768_MONO8:
2512  s = "1024 x 768, Mono8";
2513  break;
2514  case DC1394_VIDEO_MODE_1024x768_MONO16:
2515  s = "1024 x 768, Mono16";
2516  break;
2517  case DC1394_VIDEO_MODE_1280x960_YUV422:
2518  s = "1280 x 960, YUV422";
2519  break;
2520  case DC1394_VIDEO_MODE_1280x960_RGB8:
2521  s = "1280 x 960, RGB";
2522  break;
2523  case DC1394_VIDEO_MODE_1280x960_MONO8:
2524  s = "1280 x 960, Mono8";
2525  break;
2526  case DC1394_VIDEO_MODE_1280x960_MONO16:
2527  s = "1280 x 960, Mono16";
2528  break;
2529  case DC1394_VIDEO_MODE_1600x1200_YUV422:
2530  s = "1600 x 1200, YUV422";
2531  break;
2532  case DC1394_VIDEO_MODE_1600x1200_RGB8:
2533  s = "1600 x 1200, RGB";
2534  break;
2535  case DC1394_VIDEO_MODE_1600x1200_MONO8:
2536  s = "1600 x 1200, Mono8";
2537  break;
2538  case DC1394_VIDEO_MODE_1600x1200_MONO16:
2539  s = "1600 x 1200, Mono16";
2540  break;
2541  case DC1394_VIDEO_MODE_FORMAT7_0:
2542  s = "Format7 0";
2543  break;
2544  case DC1394_VIDEO_MODE_FORMAT7_1:
2545  s = "Format7 1";
2546  break;
2547  case DC1394_VIDEO_MODE_FORMAT7_2:
2548  s = "Format7 2";
2549  break;
2550  case DC1394_VIDEO_MODE_FORMAT7_3:
2551  s = "Format7 3";
2552  break;
2553  case DC1394_VIDEO_MODE_FORMAT7_4:
2554  s = "Format7 4";
2555  break;
2556  case DC1394_VIDEO_MODE_FORMAT7_5:
2557  s = "Format7 5";
2558  break;
2559  case DC1394_VIDEO_MODE_FORMAT7_6:
2560  s = "Format7 6";
2561  break;
2562  case DC1394_VIDEO_MODE_FORMAT7_7:
2563  s = "Format7 7";
2564  break;
2565  default:
2566  s = "unknown";
2567  }
2568 
2569  return s;
2570 }
2571 
Stores the camera parameters such as Shutter, Gain, etc.
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
Bayer_GRBG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:145
virtual int SoftwareWhiteBalance()
Set white balance to optimal value in software.
VideoSource_DCAM(int Card=0)
Constructor with IEEE1394 card.
bool OnePushRunning(dc1394feature_t feature)
is a feature available at OnePush?
void SetFPS(float fps)
Set frame per second for image capturing.
int SetColorFromMode_(dc1394video_mode_t videoMode)
selects the colormodel for a specific mode
int SetLeftTop(unsigned int left, unsigned int top)
set the topleft corner for partitial scan
dc1394video_mode_t DcamMode_
Defines a common interface to different devices.
std::vector< std::vector< float > > framerates
std::vector< unsigned int > f7_unitWidth
gray values, 1 channel
Definition: ImageBase.hh:130
int GrabSingle(BIAS::Camera< unsigned char > &image)
Select the port (bus-id) to use, only valid before OpenDevice()
int SetFeature(dc1394feature_t feature, unsigned int value)
Set a camera feature by hand.
bool IsControllable_
Must be initialized be the derived classes.
std::vector< unsigned int > f7_MaxBpP
int BIASVideoSource_EXPORT ScanBus(std::stringstream &ofs)
support function to get the number of cameras and IDs of all cameras on one bus
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
Definition: ImageBase.cpp:827
dc1394trigger_mode_t Trigger_
void SetModeAndFramerate(dc1394video_mode_t mode, float framerate)
virtual void SetExternalTrigger(bool trigger=true)
Specify if there is an external trigger to be used.
void SetAutoGain(bool b)
set the gain to auto or manual mode
int UserSizeToMode_8bit_()
for all formats with standard 8bpp per channel (unsigned char image)
YUV411, 2 channles, full luminance, 1 U, 1 V.
Definition: ImageBase.hh:137
Stores camera information such as model, vendor, framerates.
Bayer_RGGB, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:143
void ActivateScorpionTimestamp()
Activates the timestamp for PointGrey Scorpion SCOR-20SO.
BIAS::ImageBase::EColorModel ColorMode_
Color mode used by camera.
enum BIAS::CameraModel_e CameraModel
int UserSizeToMode_16bit_()
for all formats with 16bit per pixel per channel (aka short int)
This class VideoSource_DCAM implements access to IEEE1394 (Firewire, iLink) cameras following the DCa...
int SetGain(float g)
set value for gain
float BytesPerPixel_
BytesPerPixel cannot be int (e.g. it is 1.5 for YUV420p)
std::vector< unsigned int > f7_unitHeight
dc1394framerates_t CameraFramerates_[DC1394_VIDEO_MODE_NUM]
int OpenDevice()
Opens a dc1394 device.
unsigned int GetFeature(dc1394feature_t feature)
get the value of a specific feature
std::vector< dc1394video_mode_t > videoModes
bool CompleteInitialized_
Complete_initialized_ is set when OpenDevice(), UseChannel() etc. are done.
CameraModel GetModelForEuid(const u_int64_t euid)
searches for the correct cammodel by means of the euid of a camera
int GetHeight() const
std::vector< unsigned int > f7_bestBpP
int QueryCam()
querys the cam for available modes, framerates and features
int Width_
Image format.
int SelectDefault()
selects the default framerate for a cam
int SetShutter(float exptime)
set value for shutter
Bayer_BGGR, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:146
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
int UserSizeToFormat7_()
if user requested format 7
std::vector< unsigned int > f7_MinBpP
dc1394color_coding_t f7ColorCoding_
Bayer_GBRG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:144
int GetGammaMode()
get the value of Gamma Mode
dc1394featureset_t DcamFeatures_
void GetBytesPerPacketForFormat7(int camid, dc1394video_mode_t mode, int width, int height, unsigned int &bppmin, unsigned int &bppmax)
returns min and max bytes per packet for a specified resolution in format 7
bool Grabbing_
Grabbing flag is set and unset in GrabSingle() methods.
int UserSizeToMode()
tries to find a camera mode from user given width and height
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...
CM_YUV444, 3 channels, all channels have full data.
Definition: ImageBase.hh:136
float FramesPerSecond_
Capturing framerate.
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
int SetWhiteBalance(float rvalue, float bvalue)
sets the white balance of the camera, rvalue and bvalue are in range -0.5 to 0.5
int ID_
Camera ID.
double minContrast_
Feature ranges.
void SetAutoShutter(bool b)
set the shutter to auto or manual mode
int AutoMode(dc1394feature_t feature, dc1394feature_mode_t mode)
Set a camera feature to auto or to manual mode.
UYVY422, 2 channels, full luminance Y, subsampled half U,V inverse order.
Definition: ImageBase.hh:134
int SetGammaMode(int g)
set Gamma Mode
bool bExternalTrigger_
External trigger flag.
pthread_mutex_t grabMutex_
bool Active_
Active flag is set in PreGrab() und unset in PostGrab()
int OnePushAuto(dc1394feature_t feature)
static std::string VideoModeToString(dc1394video_mode_t mode)
returns a string from a IEEE1394 video mode
void SetExternalTrigger(bool trigger=true)
set External Trigger mode, overrides Base class function
void InvalidateUID()
sets the image&#39;s uid to invalid
Definition: ImageBase.hh:597
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
void SetUID(const BIAS::UUID &id)
Definition: ImageBase.hh:589
void SetCam_ID(int manualcamid_)
set&#39;s the id of a camera manually, has to be called before OpenDevice()
unsigned int CalcBytesPerPacket()
Evaluate Min and Max BpP, framesize and fps, then calc BpP.
int UpdateMetaData()
copy P_ and co.
Definition: Camera.cpp:446
int CloseDevice()
closes a camera device and cleans up
std::vector< dc1394video_mode_t > f7_modes
int SetBrightness(float b)
set value for brightness
float GetGain()
get the value of the gain feature
int ActivateExternalTrigger_(bool trigger=true)
if external triggering is true, activate it here in Opendevice
std::vector< unsigned int > f7_maxHeight
BIAS::ImageBase::EColorModel GetColorModel() const
void SetTime(unsigned long long int sec, unsigned long long int usec)
Set time and ensure correct format (seconds and useconds after &#39;sec&#39;)
Definition: Camera.hh:124
int PostGrab()
stops iso transmission of a camera.
dc1394framerate_t DcamFps_
float GetBrightness()
get the value of the brightness feature
int PreGrab()
initializes the iso transmission of a camera.
int ApplyBytesPerPacket()
Set this value and read back what really happend.
int SetCamera(CameraParameterSet camparam)
set camera to parameters specified in complete set
int InitCam()
initializes the camera and tries to set the optimal settings for the camera if no settings are specif...
std::vector< unsigned int > f7_maxWidth
dc1394video_mode_t bestMode
dc1394camera_list_t * cameraList
unsigned int GetSize() const
returns the image size in bytes = count - NOT the dimension DEPRECATED Please use GetSizeByte instead...
Definition: ImageBase.hh:361
static UUID GenerateUUID(const bool &consecutively=DEFAULT_UUID_CONSECUTIVELY)
static function which simply produces a uuid and returns
Definition: UUID.cpp:235
dc1394video_modes_t CameraModes_
float GetShutter()
get the value of the shutter feature