ViSP  2.6.2
vp1394TwoGrabber.cpp
1 /****************************************************************************
2  *
3  * $Id: vp1394TwoGrabber.cpp 3841 2012-07-13 22:21:03Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Firewire cameras video capture.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
42 
48 #include <iostream>
49 
50 #include <visp/vpConfig.h>
51 
52 /*
53  * Interface with libdc1394 2.x
54  */
55 #if defined(VISP_HAVE_DC1394_2)
56 #include <unistd.h>
57 
58 #include <visp/vp1394TwoGrabber.h>
59 #include <visp/vpFrameGrabberException.h>
60 #include <visp/vpImageIo.h>
61 #include <visp/vpImageConvert.h>
62 #include <visp/vpTime.h>
63 
64 const char * vp1394TwoGrabber::strVideoMode[DC1394_VIDEO_MODE_NUM]= {
65  "MODE_160x120_YUV444",
66  "MODE_320x240_YUV422",
67  "MODE_640x480_YUV411",
68  "MODE_640x480_YUV422",
69  "MODE_640x480_RGB8",
70  "MODE_640x480_MONO8",
71  "MODE_640x480_MONO16",
72  "MODE_800x600_YUV422",
73  "MODE_800x600_RGB8",
74  "MODE_800x600_MONO8",
75  "MODE_1024x768_YUV422",
76  "MODE_1024x768_RGB8",
77  "MODE_1024x768_MONO8",
78  "MODE_800x600_MONO16",
79  "MODE_1024x768_MONO16",
80  "MODE_1280x960_YUV422",
81  "MODE_1280x960_RGB8",
82  "MODE_1280x960_MONO8",
83  "MODE_1600x1200_YUV422",
84  "MODE_1600x1200_RGB8",
85  "MODE_1600x1200_MONO8",
86  "MODE_1280x960_MONO16",
87  "MODE_1600x1200_MONO16",
88  "MODE_EXIF",
89  "MODE_FORMAT7_0",
90  "MODE_FORMAT7_1",
91  "MODE_FORMAT7_2",
92  "MODE_FORMAT7_3",
93  "MODE_FORMAT7_4",
94  "MODE_FORMAT7_5",
95  "MODE_FORMAT7_6",
96  "MODE_FORMAT7_7"
97 };
98 
99 const char * vp1394TwoGrabber::strFramerate[DC1394_FRAMERATE_NUM]= {
100  "FRAMERATE_1_875",
101  "FRAMERATE_3_75",
102  "FRAMERATE_7_5",
103  "FRAMERATE_15",
104  "FRAMERATE_30",
105  "FRAMERATE_60",
106  "FRAMERATE_120",
107  "FRAMERATE_240"
108 };
109 
110 const char * vp1394TwoGrabber::strColorCoding[DC1394_COLOR_CODING_NUM]= {
111  "COLOR_CODING_MONO8",
112  "COLOR_CODING_YUV411",
113  "COLOR_CODING_YUV422",
114  "COLOR_CODING_YUV444",
115  "COLOR_CODING_RGB8",
116  "COLOR_CODING_MONO16",
117  "COLOR_CODING_RGB16",
118  "COLOR_CODING_MONO16S",
119  "COLOR_CODING_RGB16S",
120  "COLOR_CODING_RAW8",
121  "COLOR_CODING_RAW16",
122 };
123 
124 
125 
171 {
172  // protected members
173  width = height = 0;
174 
175  // private members
176  num_cameras = 0;
177  cameras = NULL;
178  camera_id = 0;
179  verbose = false;//true;
180  camIsOpen = NULL;
181  init = false;
182  cameras = NULL;
183 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
184  d = NULL;
185  list = NULL;
186 #endif
187  num_buffers = 4; // ring buffer size
188 
189  isDataModified = NULL;
190  initialShutterMode = NULL;
191  dataCam = NULL;
192 
193  reset = false;
194  initialize(reset);
195 
196  // open();
197 }
198 
209 {
210 /* if(num_cameras >= 1){
211  delete[] isDataModified;
212  delete[] initialShutterMode;
213  delete[] dataCam;
214  }*/
215  close();
216 }
217 
218 
340 void
341 vp1394TwoGrabber::setCamera(uint64_t camera_id)
342 {
343  // Suppose that if camera_id is a camera GUID, this value is greater
344  // than the number of cameras connected to the bus
345  if (camera_id >= num_cameras) {
346  // Check if camera_id is a camera guid
347  bool is_guid = false;
348  // check if the camera_id is a guid
349  for (unsigned int i=0; i< num_cameras; i++) {
350  if (cameras[i]->guid == camera_id) {
351  this->camera_id = i;
352  is_guid = true;
353  break;
354  }
355  }
356  if (is_guid == false) {
357  close();
358  vpERROR_TRACE("The camera with GUID 0x%x or id %u is not present",
359  camera_id, camera_id);
360  vpERROR_TRACE("Only %u camera on the bus.", num_cameras);
362  "The required camera is not present") );
363  }
364  }
365  else {
366  this->camera_id = camera_id;
367  }
368 
369  // create a pointer to the working camera
370  camera = cameras[this->camera_id];
371 }
372 
373 
388 void
389 vp1394TwoGrabber::getCamera(uint64_t &camera_id)
390 {
391  if (num_cameras) {
392  camera_id = this->camera_id;
393  }
394  else {
395  close();
396  vpERROR_TRACE("No cameras found");
398  "No cameras found") );
399  }
400 }
401 
416 uint64_t
418 {
419  if (num_cameras) {
420  return this->camera_id;
421  }
422  else {
423  close();
424  vpERROR_TRACE("No cameras found");
426  "No cameras found") );
427  }
428 }
429 
437 void
438 vp1394TwoGrabber::getNumCameras(unsigned int &ncameras)
439 {
440  if (! num_cameras) {
441  vpCTRACE << "No camera found..."<< std::endl;
442  ncameras = 0;
443  }
444 
445  ncameras = num_cameras;
446 }
447 
455 unsigned int
457 {
458  unsigned int ncameras = 0;
459  if (! num_cameras) {
460  vpCTRACE << "No camera found..."<< std::endl;
461  ncameras = 0;
462  }
463 
464  ncameras = num_cameras;
465  return ncameras;
466 }
467 
513 void
515 {
516  open();
517  if (! num_cameras) {
518  close();
519  vpERROR_TRACE("No camera found");
521  "No camera found") );
522  }
523  if (!isVideoModeSupported(videomode)){
524  vpERROR_TRACE("Video mode not supported by camera %d",camera_id);
526  "Video mode not supported") );
527  return ;
528  }
529  // Stop dma capture if started
530  setTransmission(DC1394_OFF);
531  setCapture(DC1394_OFF);
532 
533  if (dc1394_video_set_mode(camera, (dc1394video_mode_t) videomode) != DC1394_SUCCESS) {
534 
535  close();
536  vpERROR_TRACE("Can't set video mode");
538  "Can't set video mode") );
539  }
540 
541  setCapture(DC1394_ON);
542  setTransmission(DC1394_ON);
543 
544  // Updates image size from new video mode
545  if (dc1394_get_image_size_from_video_mode(camera,
546  (dc1394video_mode_t) videomode,
547  &this->width, &this->height)
548  != DC1394_SUCCESS) {
549 
550  close();
551  vpERROR_TRACE("Can't set video mode");
553  "Can't get image size") );
554  }
555 
556 }
557 
574 void
576 {
577  if (! num_cameras) {
578  close();
579  vpERROR_TRACE("No camera found");
581  "No camera found") );
582  }
583 
584  dc1394video_mode_t _videomode;
585  if (dc1394_video_get_mode(camera, &_videomode) != DC1394_SUCCESS) {
586 
587  close();
588  vpERROR_TRACE("Can't get current video mode");
590  "Can't get current video mode") );
591  }
592  videomode = (vp1394TwoVideoModeType) _videomode;
593 
594 }
595 
596 
597 
615 uint32_t
616 vp1394TwoGrabber::getVideoModeSupported(std::list<vp1394TwoVideoModeType> & videomodes)
617 {
618  // Refresh the list of supported modes
619  videomodes.clear();
620 
621  if (! num_cameras) {
622  close();
623  vpERROR_TRACE("No camera found");
625  "No camera found") );
626  }
627  dc1394video_modes_t _videomodes;
628 
629  // get video modes:
630  if (dc1394_video_get_supported_modes(camera, &_videomodes)!=DC1394_SUCCESS) {
631 
632  close();
633  vpERROR_TRACE("Can't get video modes");
635  "Can't get video modes") );
636  }
637 
638  // parse the video modes to add in the list
639  for (unsigned i=0; i < _videomodes.num; i++) {
640  vp1394TwoVideoModeType _mode = (vp1394TwoVideoModeType) _videomodes.modes[i];
641  videomodes.push_back( _mode );
642  }
643 
644  // return the number of available video modes
645  return _videomodes.num;
646 }
662 bool
664 {
665  if (! num_cameras) {
666  close();
667  vpERROR_TRACE("No camera found");
669  "No camera found") );
670  }
671  dc1394video_modes_t _videomodes;
672 
673  // get video modes:
674  if (dc1394_video_get_supported_modes(camera, &_videomodes)!=DC1394_SUCCESS) {
675 
676  close();
677  vpERROR_TRACE("Can't get video modes");
679  "Can't get video modes") );
680  }
681 
682  // parse the video modes to check with the desired
683  for (unsigned i=0; i < _videomodes.num; i++) {
684  if ((vp1394TwoVideoModeType) _videomodes.modes[i] == videomode)
685  return true;
686  }
687  return false;
688 }
689 
702 bool
704 {
705 
706  if (dc1394_is_video_mode_scalable((dc1394video_mode_t) videomode))
707  return true;
708 
709  return false;
710 }
711 
727 bool
729 {
731  getColorCoding(coding);
732 
733  switch (coding) {
737  case vpCOLOR_CODING_RAW8:
739  return false;
743  case vpCOLOR_CODING_RGB8:
746  return true;
747  }
748  return false;
749 }
750 
775 void
777 {
778  open();
779  if (! num_cameras) {
780  close();
781  vpERROR_TRACE("No camera found");
783  "No camera found") );
784  }
785 
786  vp1394TwoVideoModeType cur_videomode;
787  getVideoMode(cur_videomode);
788  if (isVideoModeFormat7(cur_videomode))
789  return;
790 
791  if (!isFramerateSupported(cur_videomode,fps)){
792  vpERROR_TRACE("Framerate not supported by camera %d",camera_id);
794  "Framerate not supported") );
795  return ;
796  }
797 
798  // Stop dma capture if started
799  setTransmission(DC1394_OFF);
800  setCapture(DC1394_OFF);
801 
802  if (dc1394_video_set_framerate(camera, (dc1394framerate_t) fps) != DC1394_SUCCESS) {
803 
804  close();
805  vpERROR_TRACE("Can't set framerate");
807  "Can't set framerate") );
808  }
809 
810  setCapture(DC1394_ON);
811  setTransmission(DC1394_ON);
812 }
813 
830 void
832 {
833  if (! num_cameras) {
834  close();
835  vpERROR_TRACE("No camera found");
837  "No camera found") );
838  }
839  dc1394framerate_t _fps;
840  if (dc1394_video_get_framerate(camera, &_fps) != DC1394_SUCCESS) {
841 
842  close();
843  vpERROR_TRACE("Can't get current framerate");
845  "Can't get current framerate") );
846  }
847  fps = (vp1394TwoFramerateType) _fps;
848 
849 }
850 
882 uint32_t
884  std::list<vp1394TwoFramerateType> & fps)
885 {
886  if (! num_cameras) {
887  close();
888  vpERROR_TRACE("No camera found");
890  "No camera found") );
891  }
892 
893  // Refresh the list of supported framerates
894  fps.clear();
895 
896  switch (mode) {
897  // Framerate not available for:
898  // - vpVIDEO_MODE_EXIF ie Format_6
899  // - vpVIDEO_MODE_FORMAT7... ie the Format_7
900  case vpVIDEO_MODE_EXIF:
909  return 0;
910  break;
911  default:
912  {
913  dc1394framerates_t _fps;
914  if (dc1394_video_get_supported_framerates(camera,
915  (dc1394video_mode_t)mode,
916  &_fps) != DC1394_SUCCESS) {
917  close();
918  vpERROR_TRACE("Could not query supported frametates for mode %d\n",
919  mode);
921  "Could not query supported framerates") );
922  }
923  if (_fps.num == 0)
924  return 0;
925 
926  for (unsigned int i = 0; i < _fps.num; i ++)
927  fps.push_back((vp1394TwoFramerateType)_fps.framerates[i]);
928 
929  return _fps.num;
930  }
931  break;
932  }
933 }
967 bool
970 {
971  if (! num_cameras) {
972  close();
973  vpERROR_TRACE("No camera found");
975  "No camera found") );
976  }
977 
978  switch (mode) {
979  // Framerate not available for:
980  // - vpVIDEO_MODE_EXIF ie Format_6
981  // - vpVIDEO_MODE_FORMAT7... ie the Format_7
982  case vpVIDEO_MODE_EXIF:
991  return 0;
992  break;
993  default:
994  {
995  dc1394framerates_t _fps;
996  if (dc1394_video_get_supported_framerates(camera,
997  (dc1394video_mode_t)mode,
998  &_fps) != DC1394_SUCCESS) {
999  close();
1000  vpERROR_TRACE("Could not query supported frametates for mode %d\n",
1001  mode);
1003  "Could not query supported framerates") );
1004  }
1005  if (_fps.num == 0)
1006  return 0;
1007 
1008  for (unsigned int i = 0; i < _fps.num; i ++){
1009  if (fps==(vp1394TwoFramerateType)_fps.framerates[i]){
1010  return true;
1011  }
1012  }
1013  return false;
1014  }
1015  break;
1016  }
1017 }
1018 
1067 void
1069 {
1070  if (! num_cameras) {
1071  close();
1072  vpERROR_TRACE("No camera found");
1074  "No camera found") );
1075  }
1076 
1077  dc1394video_mode_t _videomode;
1078  if (dc1394_video_get_mode(camera, &_videomode) != DC1394_SUCCESS) {
1079 
1080  close();
1081  vpERROR_TRACE("Can't get current video mode");
1083  "Can't get current video mode") );
1084  }
1085 
1086  if (!isColorCodingSupported((vp1394TwoVideoModeType)_videomode,coding)){
1087  vpERROR_TRACE("Color coding not supported by camera %d",camera_id);
1089  "Color coding not supported") );
1090  return ;
1091  }
1092 
1093  // Format 7 video mode
1094  if (dc1394_is_video_mode_scalable(_videomode)) {
1095  setTransmission(DC1394_OFF);
1096  setCapture(DC1394_OFF);
1097 
1098  if (dc1394_format7_set_color_coding(camera, _videomode,
1099  (dc1394color_coding_t) coding)
1100  != DC1394_SUCCESS) {
1101 
1102  close();
1103  vpERROR_TRACE("Can't set color coding");
1105  "Can't set color coding") );
1106  }
1107 
1108  setCapture(DC1394_ON);
1109  setTransmission(DC1394_ON);
1110  }
1111 }
1112 
1130 void
1132 {
1133  if (! num_cameras) {
1134  close();
1135  vpERROR_TRACE("No camera found");
1137  "No camera found") );
1138  }
1139  dc1394video_mode_t _videomode;
1140  if (dc1394_video_get_mode(camera, &_videomode) != DC1394_SUCCESS) {
1141 
1142  close();
1143  vpERROR_TRACE("Can't get current video mode");
1145  "Can't get current video mode") );
1146  }
1147 
1148  dc1394color_coding_t _coding;
1149  if (dc1394_is_video_mode_scalable(_videomode)) {
1150  // Format 7 video mode
1151  if (dc1394_format7_get_color_coding(camera, _videomode, &_coding)
1152  != DC1394_SUCCESS) {
1153 
1154  close();
1155  vpERROR_TRACE("Can't get current color coding");
1157  "Can't query current color coding") );
1158  }
1159  }
1160  else if (dc1394_is_video_mode_still_image((dc1394video_mode_t)_videomode)) {
1162  "No color coding for format 6 video mode"));
1163  }
1164  else {
1165  // Not Format 7 and not Format 6 video modes
1166  if (dc1394_get_color_coding_from_video_mode(camera,
1167  (dc1394video_mode_t)_videomode,
1168  &_coding) != DC1394_SUCCESS) {
1169  close();
1170  vpERROR_TRACE("Could not query supported color coding for mode %d\n",
1171  _videomode);
1173  "Can't query current color coding"));
1174  }
1175  }
1176  coding = (vp1394TwoColorCodingType) _coding;
1177 }
1178 
1200 uint32_t
1202  std::list<vp1394TwoColorCodingType> & codings)
1203 {
1204  if (! num_cameras) {
1205  close();
1206  vpERROR_TRACE("No camera found");
1208  "No camera found") );
1209  }
1210 
1211  // Refresh the list of supported framerates
1212  codings.clear();
1213 
1214  if (dc1394_is_video_mode_scalable((dc1394video_mode_t)mode)) {
1215  // Format 7 video mode
1216  dc1394color_codings_t _codings;
1217  if (dc1394_format7_get_color_codings(camera,
1218  (dc1394video_mode_t)mode,
1219  &_codings) != DC1394_SUCCESS) {
1220  close();
1221  vpERROR_TRACE("Could not query supported color codings for mode %d\n",
1222  mode);
1224  "Could not query supported color codings") );
1225  }
1226  if (_codings.num == 0)
1227  return 0;
1228 
1229  for (unsigned int i = 0; i < _codings.num; i ++)
1230  codings.push_back((vp1394TwoColorCodingType)_codings.codings[i]);
1231 
1232  return _codings.num;
1233  }
1234  else if (dc1394_is_video_mode_still_image((dc1394video_mode_t)mode)) {
1235  // Format 6 video mode
1236  return 0;
1237  }
1238  else {
1239  // Not Format 7 and not Format 6 video modes
1240  dc1394color_coding_t _coding;
1241  if (dc1394_get_color_coding_from_video_mode(camera,
1242  (dc1394video_mode_t)mode,
1243  &_coding) != DC1394_SUCCESS) {
1244  close();
1245  vpERROR_TRACE("Could not query supported color coding for mode %d\n",
1246  mode);
1248  "Could not query supported color coding") );
1249  }
1250  codings.push_back((vp1394TwoColorCodingType)_coding);
1251  return 1;
1252  }
1253 }
1275 bool
1277  vp1394TwoColorCodingType coding)
1278 {
1279  if (! num_cameras) {
1280  close();
1281  vpERROR_TRACE("No camera found");
1283  "No camera found") );
1284  }
1285 
1286 
1287  if (dc1394_is_video_mode_scalable((dc1394video_mode_t)mode)) {
1288  // Format 7 video mode
1289  dc1394color_codings_t _codings;
1290  if (dc1394_format7_get_color_codings(camera,
1291  (dc1394video_mode_t)mode,
1292  &_codings) != DC1394_SUCCESS) {
1293  close();
1294  vpERROR_TRACE("Could not query supported color codings for mode %d\n",
1295  mode);
1297  "Could not query supported color codings") );
1298  }
1299  if (_codings.num == 0)
1300  return 0;
1301 
1302  for (unsigned int i = 0; i < _codings.num; i ++){
1303  if (coding==(vp1394TwoColorCodingType)_codings.codings[i])
1304  return true;
1305  }
1306  return false;
1307  }
1308  else if (dc1394_is_video_mode_still_image((dc1394video_mode_t)mode)) {
1309  // Format 6 video mode
1310  return false;
1311  }
1312  else {
1313  // Not Format 7 and not Format 6 video modes
1314  dc1394color_coding_t _coding;
1315  if (dc1394_get_color_coding_from_video_mode(camera,
1316  (dc1394video_mode_t)mode,
1317  &_coding) != DC1394_SUCCESS) {
1318  close();
1319  vpERROR_TRACE("Could not query supported color coding for mode %d\n",
1320  mode);
1322  "Could not query supported color coding") );
1323  return false;
1324  }
1325  if (coding==(vp1394TwoColorCodingType)_coding)
1326  return true;
1327 
1328  return false;
1329  }
1330 }
1331 
1332 
1364 void
1365 vp1394TwoGrabber::setFormat7ROI(unsigned int left, unsigned int top,
1366  unsigned int width, unsigned int height)
1367 {
1368  open();
1369  if (! num_cameras) {
1370  close();
1371  vpERROR_TRACE("No camera found");
1373  "No camera found") );
1374  }
1375 
1376  dc1394video_mode_t _videomode;
1377  if (dc1394_video_get_mode(camera, &_videomode) != DC1394_SUCCESS) {
1378 
1379  close();
1380  vpERROR_TRACE("Can't get current video mode");
1382  "Can't get current video mode") );
1383  }
1384  if (dc1394_is_video_mode_scalable(_videomode)) {
1385  // Stop dma capture if started
1386  setTransmission(DC1394_OFF);
1387  setCapture(DC1394_OFF);
1388  // Format 7 video mode
1389  unsigned int max_width, max_height;
1390  if (dc1394_format7_get_max_image_size(camera, _videomode,
1391  &max_width, &max_height)
1392  != DC1394_SUCCESS) {
1393 
1394  close();
1395  vpERROR_TRACE("Can't get format7 max image size");
1397  "Can't get format7 max image size") );
1398  }
1399 #if 0
1400  vpTRACE("left: %d top: %d width: %d height: %d", left, top,
1401  width == 0 ? DC1394_USE_MAX_AVAIL: width,
1402  height == 0 ? DC1394_USE_MAX_AVAIL : height);
1403  vpTRACE("max_width: %d max_height: %d", max_width, max_height);
1404 #endif
1405 
1406  if (left > max_width) {
1407  vpERROR_TRACE("Can't set format7 ROI");
1409  "Can't set format7 ROI") );
1410  }
1411  if (top > max_height) {
1412  vpERROR_TRACE("Can't set format7 ROI");
1414  "Can't set format7 ROI") );
1415  }
1416 
1417  int32_t roi_width;
1418  int32_t roi_height;
1419 
1420  if (width != 0) {
1421  // Check if roi width is acceptable (ie roi is contained in the image)
1422  if (width > (max_width - left))
1423  width = (max_width - left);
1424  roi_width = (int32_t)width;
1425  }
1426  else {
1427  roi_width = DC1394_USE_MAX_AVAIL;
1428  }
1429 
1430  if (height != 0) {
1431  // Check if roi height is acceptable (ie roi is contained in the image)
1432  if (height > (max_height - top))
1433  height = (max_height - top);
1434  roi_height = (int32_t)height;
1435  }
1436  else {
1437  roi_height = DC1394_USE_MAX_AVAIL;
1438  }
1439 
1440 
1441  if (dc1394_format7_set_roi(camera, _videomode,
1442  (dc1394color_coding_t) DC1394_QUERY_FROM_CAMERA, // color_coding
1443  DC1394_USE_MAX_AVAIL/*DC1394_QUERY_FROM_CAMERA*/, // bytes_per_packet
1444  (int32_t)left, // left
1445  (int32_t)top, // top
1446  roi_width,
1447  roi_height)
1448  != DC1394_SUCCESS) {
1449  close();
1450  vpERROR_TRACE("Can't set format7 roi");
1452  "Can't get current video mode") );
1453  }
1454  // Update the image size
1455  if (dc1394_format7_get_image_size(camera, _videomode,
1456  &this->width,
1457  &this->height)
1458  != DC1394_SUCCESS) {
1459  close();
1460  vpERROR_TRACE("Can't get format7 image size");
1462  "Can't get format7 image size") );
1463  }
1464 
1465  setCapture(DC1394_ON);
1466  setTransmission(DC1394_ON);
1467  }
1468 }
1483 void
1484 vp1394TwoGrabber::initialize(bool reset)
1485 {
1486  if (init == false){
1487  // Find cameras
1488 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
1489  if (d != NULL)
1490  dc1394_free (d);
1491 
1492  d = dc1394_new ();
1493  if (dc1394_camera_enumerate (d, &list) != DC1394_SUCCESS) {
1494  dc1394_camera_free_list (list);
1495  close();
1496  vpERROR_TRACE("Failed to enumerate cameras\n");
1498  "Failed to enumerate cameras") );
1499  }
1500 
1501  if (list->num == 0) {
1502  dc1394_camera_free_list (list);
1503  close();
1504  vpERROR_TRACE("No cameras found");
1506  "No cameras found") );
1507  }
1508 
1509  if (cameras != NULL)
1510  delete [] cameras;
1511 
1512  cameras = new dc1394camera_t * [list->num];
1513 
1514  num_cameras = 0;
1515 
1516  for (unsigned int i=0; i < list->num; i ++) {
1517  cameras[i] = dc1394_camera_new (d, list->ids[i].guid);
1518  if (!cameras[i]) {
1519  vpTRACE ("Failed to initialize camera with guid \"%ld\"\n",
1520  list->ids[i].guid);
1521  continue;
1522  }
1523  // Update the number of working cameras
1524  num_cameras ++;
1525  }
1526 
1527  if (reset) {
1528  // Reset the bus to make firewire working if the program was not properly
1529  // stopped by a CTRL-C. We reset here only the bus attached to the first
1530  // camera
1531  dc1394_reset_bus(cameras[0]);
1532  }
1533 
1534  if (list != NULL)
1535  dc1394_camera_free_list (list);
1536  list = NULL;
1537 
1538 #elif defined VISP_HAVE_DC1394_2_FIND_CAMERAS // old API <= libdc1394-2.0.0-rc7
1539  if (cameras != NULL)
1540  free(cameras);
1541  cameras = NULL;
1542  int err = dc1394_find_cameras(&cameras, &num_cameras);
1543 
1544  if (err!=DC1394_SUCCESS && err != DC1394_NO_CAMERA) {
1545  close();
1546  vpERROR_TRACE("Unable to look for cameras\n\n"
1547  "Please check \n"
1548  " - if the kernel modules `ieee1394',`raw1394' and `ohci1394' are loaded \n"
1549  " - if you have read/write access to /dev/raw1394\n\n");
1551  "Unable to look for cameras") );
1552 
1553  }
1554 #endif
1555 
1556  if (num_cameras == 0) {
1557  close();
1558  vpERROR_TRACE("No cameras found");
1560  "No cameras found") );
1561  }
1562 
1563  // allocation for the parameters
1564  isDataModified = new bool[num_cameras];
1565  for(unsigned int i=0; i<num_cameras; i++)
1566  isDataModified[i] = false;
1567  initialShutterMode = new dc1394feature_mode_t[num_cameras];
1568  dataCam = new vpDc1394TwoCameraParametersData[num_cameras];
1569 
1570  if (camera_id >= num_cameras) {
1571  // Bad camera id
1572  close();
1573  vpERROR_TRACE("Bad camera id: %u", camera_id);
1574  vpERROR_TRACE("Only %u camera on the bus.", num_cameras);
1576  "Bad camera id") );
1577  }
1578 
1579  if (verbose) {
1580  std::cout << "------ Bus information ------" << std::endl;
1581  std::cout << "Number of camera(s) on the bus : " << num_cameras <<std::endl;
1582  std::cout << "-----------------------------" << std::endl;
1583  }
1584 
1585  if (camIsOpen != NULL) delete [] camIsOpen;
1586  camIsOpen = new bool [num_cameras];
1587  for (unsigned int i = 0;i<num_cameras;i++){
1588  camIsOpen[i]=false;
1589  }
1590 
1591  init = true;
1592  }
1593 }
1603 void
1605 {
1606  if (init == false) initialize(false);
1607  if (camIsOpen[camera_id] == false){
1608  dc1394switch_t status = DC1394_OFF;
1609 
1610  //#ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
1611  dc1394_video_get_transmission(cameras[camera_id], &status);
1612  if (status != DC1394_OFF){
1613  //#endif
1614  if (dc1394_video_set_transmission(cameras[camera_id],DC1394_OFF)!=DC1394_SUCCESS)
1615  vpTRACE("Could not stop ISO transmission");
1616  else {
1617  vpTime::wait(500);
1618  if (dc1394_video_get_transmission(cameras[camera_id], &status)!=DC1394_SUCCESS)
1619  vpTRACE("Could get ISO status");
1620  else {
1621  if (status==DC1394_ON) {
1622  vpTRACE("ISO transmission refuses to stop");
1623  }
1624 #ifdef VISP_HAVE_DC1394_2_FIND_CAMERAS // old API <= libdc1394-2.0.0-rc7
1625  // No yet in the new API
1626  cameras[camera_id]->is_iso_on=status;
1627 #endif
1628  }
1629  //#ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
1630  }
1631  //#endif
1632  }
1633  setCamera(camera_id);
1634  //setIsoSpeed(DC1394_ISO_SPEED_400);
1635  setCapture(DC1394_ON);
1636  setTransmission(DC1394_ON);
1637  camIsOpen[camera_id] = true;
1638  }
1639 }
1648 void
1650 {
1651  if (init){
1652  if (num_cameras) {
1653  for (unsigned int i = 0; i < num_cameras;i++) {
1654  if (camIsOpen[i]) {
1655  camera = cameras[i];
1656  this->camera_id = i;// set camera id for the function updateDataStructToCam
1657  setTransmission(DC1394_OFF);
1658  setCapture(DC1394_OFF);
1659  if(isDataModified[i]){
1660  // reset values
1661  try{
1662  updateDataStructToCam();
1663  }
1664  catch(...){
1665  }
1666  // reset mode (manual, auto, ...)
1667  if (dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, initialShutterMode[i]) != DC1394_SUCCESS ||
1668  dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE, initialShutterMode[i]) != DC1394_SUCCESS ||
1669  dc1394_feature_set_mode(camera, DC1394_FEATURE_SHARPNESS, initialShutterMode[i]) != DC1394_SUCCESS ||
1670  dc1394_feature_set_mode(camera, DC1394_FEATURE_HUE, initialShutterMode[i]) != DC1394_SUCCESS ||
1671  dc1394_feature_set_mode(camera, DC1394_FEATURE_SATURATION, initialShutterMode[i]) != DC1394_SUCCESS ||
1672  dc1394_feature_set_mode(camera, DC1394_FEATURE_GAMMA, initialShutterMode[i]) != DC1394_SUCCESS ||
1673  dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, initialShutterMode[i]) != DC1394_SUCCESS ||
1674  dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, initialShutterMode[i]) != DC1394_SUCCESS ||
1675  dc1394_feature_set_mode(camera, DC1394_FEATURE_IRIS, initialShutterMode[i])){
1676 
1677  vpERROR_TRACE("Unable to reset the initial mode");
1679  "Unable to reset the initial mode"));
1680  }
1681  }
1682  }
1683 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
1684  dc1394_camera_free(cameras[i]);
1685 #elif defined VISP_HAVE_DC1394_2_FIND_CAMERAS // old API <= libdc1394-2.0.0-rc7
1686  dc1394_free_camera(cameras[i]);
1687 #endif
1688  }
1689  }
1690  if (camIsOpen != NULL) {
1691  delete [] camIsOpen;
1692  camIsOpen = NULL;
1693  }
1694 
1695 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
1696  if (cameras != NULL) {
1697  delete [] cameras;
1698  cameras = NULL;
1699  }
1700  if (d != NULL) {
1701  dc1394_free (d);
1702  d = NULL;
1703  }
1704 
1705 #elif defined VISP_HAVE_DC1394_2_FIND_CAMERAS // old API <= libdc1394-2.0.0-rc7
1706  if (cameras != NULL) {
1707  free(cameras);
1708  cameras = NULL;
1709  }
1710 #endif
1711 
1712  camIsOpen = NULL;
1713  num_cameras = 0;
1714 
1715  // remove data for the parameters
1716  if(isDataModified != NULL){
1717  delete[] isDataModified;
1718  isDataModified = NULL;
1719  }
1720  if(initialShutterMode != NULL){
1721  delete[] initialShutterMode;
1722  initialShutterMode = NULL;
1723  }
1724  if(dataCam != NULL){
1725  delete[] dataCam;
1726  dataCam = NULL;
1727  }
1728 
1729  init = false;
1730  }
1731 }
1732 
1744 void
1746 {
1747  if (size < 1) {
1748  close();
1750  "Could not set ring buffer size") );
1751  }
1752 
1753  if (size != num_buffers) {
1754  // We need to change the ring buffer size
1755  num_buffers = size;
1756  if(camIsOpen[camera_id]){
1757  setCapture(DC1394_OFF);
1758  setCapture(DC1394_ON);
1759  }
1760  }
1761 }
1762 
1772 unsigned int
1774 {
1775  return num_buffers;
1776 }
1777 
1816 void
1817 vp1394TwoGrabber::setAutoShutter(unsigned int minvalue, unsigned int maxvalue)
1818 {
1819  if (! num_cameras) {
1820  close();
1821  vpERROR_TRACE("No camera found");
1823  "No camera found") );
1824  }
1825 
1826  if (dc1394_feature_set_power(camera, DC1394_FEATURE_SHUTTER, DC1394_ON)
1827  != DC1394_SUCCESS) {
1828  // vpERROR_TRACE("Cannot set shutter on. \n");
1829  close();
1831  "Cannot set shutter on") );
1832  }
1833 
1834 
1835  if (dc1394_feature_set_mode(camera,
1836  DC1394_FEATURE_SHUTTER,
1837  DC1394_FEATURE_MODE_AUTO)
1838  != DC1394_SUCCESS) {
1839  // vpERROR_TRACE("Cannot set auto shutter. \n");
1840  close();
1842  "Cannot set auto shutter") );
1843  }
1844 
1845  if (dc1394_avt_set_auto_shutter(camera, minvalue, maxvalue)
1846  != DC1394_SUCCESS) {
1847  // vpERROR_TRACE("Cannot set auto shutter min and max values. Is the camera an AVT one?\n");
1848  close();
1850  "Cannot set auto shutter min and max values") );
1851  }
1852 }
1853 
1871 void
1872 vp1394TwoGrabber::setCapture(dc1394switch_t _switch)
1873 {
1874  if (! num_cameras) {
1875  close();
1876  vpERROR_TRACE("No camera found");
1878  "No camera found") );
1879  }
1880 
1881  if (_switch == DC1394_ON) {
1882  //if (dc1394_capture_setup(camera, num_buffers) != DC1394_SUCCESS) {
1883  // To be compatible with libdc1394 svn 382 version
1884  if (dc1394_capture_setup(camera, num_buffers,
1885  DC1394_CAPTURE_FLAGS_DEFAULT) != DC1394_SUCCESS) {
1886  vpERROR_TRACE("Unable to setup camera capture-\n"
1887  "make sure that the video mode and framerate are "
1888  "supported by your camera.\n");
1889  close();
1891  "Could not setup dma capture") );
1892  }
1893  }
1894  else { // _switch == DC1394_OFF
1895  dc1394error_t code = dc1394_capture_stop(camera);
1896 
1897  if (code != DC1394_SUCCESS && code != DC1394_CAPTURE_IS_NOT_SET) {
1898  vpERROR_TRACE("Unable to stop camera capture\n");
1899  close();
1901  "Could not setup dma capture") );
1902  }
1903  }
1904 }
1905 
1906 
1921 void
1922 vp1394TwoGrabber::setTransmission(dc1394switch_t _switch)
1923 {
1924  if (! num_cameras) {
1925  close();
1926  vpERROR_TRACE("No camera found");
1928  "No camera found") );
1929  }
1930 
1931  dc1394switch_t status = DC1394_OFF;
1932 
1933  if (dc1394_video_get_transmission(camera, &status)!=DC1394_SUCCESS) {
1934  vpERROR_TRACE("Unable to get transmision status");
1935  close();
1937  "Could not setup dma capture") );
1938  }
1939 
1940  // if (status!=_switch){
1941  // Start dma capture if halted
1942  if (dc1394_video_set_transmission(camera, _switch) != DC1394_SUCCESS) {
1943  vpERROR_TRACE("Unable to setup camera capture-\n"
1944  "make sure that the video mode and framerate are "
1945  "supported by your camera.\n");
1946  close();
1948  "Could not setup dma capture") );
1949  }
1950 
1951  if (_switch == DC1394_ON) {
1952  status = DC1394_OFF;
1953 
1954  int i = 0;
1955  while ( status == DC1394_OFF && i++ < 5 ) {
1956  usleep(50000);
1957  if (dc1394_video_get_transmission(camera, &status)!=DC1394_SUCCESS) {
1958  vpERROR_TRACE("Unable to get transmision status");
1959  close();
1961  "Could not setup dma capture") );
1962  }
1963  }
1964  }
1965  // }
1966 }
1967 
2002 void
2004 {
2005  if (! num_cameras) {
2006  close();
2007  vpERROR_TRACE("No camera found");
2009  "No camera found") );
2010  }
2011 
2012  dc1394operation_mode_t op_mode;
2013  dc1394speed_t speed;
2014 
2015  // Check the speed to configure in B-mode or A-mode
2016  if (isospeed >= vpISO_SPEED_800) {
2017  if (camera->bmode_capable != DC1394_TRUE) {
2018 // vpERROR_TRACE("Camera is not 1394B mode capable. \n"
2019 // "Set the iso speed lower or equal to 400Mbps");
2020  close();
2022  "Camera is not 1394B mode capable") );
2023  }
2024 
2025  if(dc1394_video_set_operation_mode(camera,
2026  DC1394_OPERATION_MODE_1394B)
2027  != DC1394_SUCCESS) {
2028 // vpERROR_TRACE("Cannot set camera to 1394B mode. \n");
2029  close();
2031  "Cannot set camera to 1394B mode") );
2032  }
2033 
2034  if (dc1394_video_get_operation_mode(camera, &op_mode) != DC1394_SUCCESS) {
2035 // vpERROR_TRACE("Failed to set 1394B mode. \n");
2036  close();
2038  "Failed to set 1394B mode") );
2039  }
2040  }
2041  else {
2042  if (dc1394_video_set_operation_mode(camera,
2043  DC1394_OPERATION_MODE_LEGACY)
2044  != DC1394_SUCCESS) {
2045 // vpERROR_TRACE("Cannot set camera to 1394A mode. \n");
2046  close();
2048  "Cannot set camera to 1394A mode") );
2049  }
2050 
2051  if (dc1394_video_get_operation_mode(camera, &op_mode) != DC1394_SUCCESS) {
2052 // vpERROR_TRACE("Failed to set 1394A mode. \n");
2053  close();
2055  "Failed to set 1394A mode") );
2056  }
2057  }
2058 
2059  if (dc1394_video_set_iso_speed(camera, (dc1394speed_t) isospeed)
2060  != DC1394_SUCCESS) {
2061 // vpERROR_TRACE("Cannot set requested iso speed. \n");
2062  close();
2064  "Cannot set requested iso speed") );
2065  }
2066 
2067  if (dc1394_video_get_iso_speed(camera, &speed) != DC1394_SUCCESS) {
2068 // vpERROR_TRACE("Failed to set iso speed. \n");
2069  close();
2071  "Failed to set iso speed") );
2072  }
2073 }
2074 
2085 void
2087 {
2088  open();
2089  acquire(I);
2090 }
2091 
2102 void
2104 {
2105  open();
2106  acquire(I);
2107 }
2108 
2109 
2148 dc1394video_frame_t *
2150 {
2151 
2152  if (! num_cameras) {
2153  close();
2154  vpERROR_TRACE("No camera found");
2156  "No camera found") );
2157  }
2158 
2159  dc1394video_frame_t *frame = NULL;
2160 
2161  if (dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame)
2162  !=DC1394_SUCCESS) {
2163  vpERROR_TRACE ("Error: Failed to capture from camera %d\n", camera_id);
2164  }
2165 
2166  return frame;
2167 }
2168 
2210 dc1394video_frame_t *
2212 {
2213  uint64_t timestamp;
2214  uint32_t id;
2215 
2216  dc1394video_frame_t *frame;
2217 
2218  frame = dequeue(I, timestamp, id);
2219 
2220  return frame;
2221 }
2222 
2271 dc1394video_frame_t *
2273  uint64_t &timestamp,
2274  uint32_t &id)
2275 {
2276 
2277  open();
2278 
2279  dc1394video_frame_t *frame;
2280 
2281  frame = dequeue();
2282 
2283  // Timeval data structure providing the unix time
2284  // [microseconds] at which the frame was captured in the ring buffer.
2285  timestamp = frame->timestamp;
2286  id = frame->id;
2287 
2288  this->width = frame->size[0];
2289  this->height = frame->size[1];
2290  unsigned int size = this->width * this->height;
2291 
2292  if ((I.getWidth() != this->width)||(I.getHeight() != this->height))
2293  I.resize(this->height, this->width);
2294 
2295  switch(frame->color_coding) {
2296  case DC1394_COLOR_CODING_MONO8:
2297  case DC1394_COLOR_CODING_RAW8:
2298  memcpy(I.bitmap, (unsigned char *) frame->image,
2299  size*sizeof(unsigned char));
2300  break;
2301  case DC1394_COLOR_CODING_MONO16:
2302  case DC1394_COLOR_CODING_RAW16:
2303  vpImageConvert::MONO16ToGrey( (unsigned char *) frame->image,
2304  I.bitmap, size);
2305  break;
2306 
2307  case DC1394_COLOR_CODING_YUV411:
2308  vpImageConvert::YUV411ToGrey( (unsigned char *) frame->image,
2309  I.bitmap, size);
2310  break;
2311 
2312  case DC1394_COLOR_CODING_YUV422:
2313  vpImageConvert::YUV422ToGrey( (unsigned char *) frame->image,
2314  I.bitmap, size);
2315  break;
2316 
2317  case DC1394_COLOR_CODING_YUV444:
2318  vpImageConvert::YUV444ToGrey( (unsigned char *) frame->image,
2319  I.bitmap, size);
2320  break;
2321 
2322  case DC1394_COLOR_CODING_RGB8:
2323  vpImageConvert::RGBToGrey((unsigned char *) frame->image, I.bitmap, size);
2324  break;
2325 
2326 
2327  default:
2328  close();
2329  vpERROR_TRACE("Format conversion not implemented. Acquisition failed.");
2331  "Format conversion not implemented. "
2332  "Acquisition failed.") );
2333  break;
2334  };
2335 
2336  return frame;
2337 }
2338 
2379 dc1394video_frame_t *
2381 {
2382  uint64_t timestamp;
2383  uint32_t id;
2384 
2385  dc1394video_frame_t *frame;
2386 
2387  frame = dequeue(I, timestamp, id);
2388 
2389  return frame;
2390 }
2391 
2440 dc1394video_frame_t *
2442  uint64_t &timestamp,
2443  uint32_t &id)
2444 {
2445 
2446  open();
2447 
2448  dc1394video_frame_t *frame;
2449 
2450  frame = dequeue();
2451 
2452  // Timeval data structure providing the unix time
2453  // [microseconds] at which the frame was captured in the ring buffer.
2454  timestamp = frame->timestamp;
2455  id = frame->id;
2456 
2457  this->width = frame->size[0];
2458  this->height = frame->size[1];
2459  unsigned int size = this->width * this->height;
2460 
2461  if ((I.getWidth() != width)||(I.getHeight() != height))
2462  I.resize(height, width);
2463 
2464  switch (frame->color_coding) {
2465  case DC1394_COLOR_CODING_MONO8:
2466  case DC1394_COLOR_CODING_RAW8:
2467  vpImageConvert::GreyToRGBa((unsigned char *) frame->image,
2468  (unsigned char *) I.bitmap, size);
2469  break;
2470 
2471  case DC1394_COLOR_CODING_MONO16:
2472  case DC1394_COLOR_CODING_RAW16:
2473  vpImageConvert::MONO16ToRGBa((unsigned char *) frame->image,
2474  (unsigned char *) I.bitmap, size);
2475  break;
2476 
2477  case DC1394_COLOR_CODING_YUV411:
2478  vpImageConvert::YUV411ToRGBa( (unsigned char *) frame->image,
2479  (unsigned char *) I.bitmap, size);
2480  break;
2481 
2482  case DC1394_COLOR_CODING_YUV422:
2483  vpImageConvert::YUV422ToRGBa( (unsigned char *) frame->image,
2484  (unsigned char *) I.bitmap, size);
2485  break;
2486 
2487  case DC1394_COLOR_CODING_YUV444:
2488  vpImageConvert::YUV444ToRGBa( (unsigned char *) frame->image,
2489  (unsigned char *) I.bitmap, size);
2490  break;
2491 
2492  case DC1394_COLOR_CODING_RGB8:
2493  vpImageConvert::RGBToRGBa((unsigned char *) frame->image,
2494  (unsigned char *) I.bitmap, size);
2495  break;
2496 
2497 
2498  default:
2499  close();
2500  vpERROR_TRACE("Format conversion not implemented. Acquisition failed.");
2502  "Format conversion not implemented. "
2503  "Acquisition failed.") );
2504  break;
2505  };
2506 
2507  return frame;
2508 }
2509 
2520 void
2521 vp1394TwoGrabber::enqueue(dc1394video_frame_t *frame)
2522 {
2523 
2524  if (! num_cameras) {
2525  close();
2526  vpERROR_TRACE("No camera found");
2528  "No camera found") );
2529  }
2530 
2531  if (frame)
2532  dc1394_capture_enqueue(camera, frame);
2533 }
2534 
2535 
2549 void
2551 {
2552  uint64_t timestamp;
2553  uint32_t id;
2554 
2555  dc1394video_frame_t *frame;
2556 
2557  frame = dequeue(I, timestamp, id);
2558  enqueue(frame);
2559 }
2560 
2579 void
2581  uint64_t &timestamp,
2582  uint32_t &id)
2583 {
2584  dc1394video_frame_t *frame;
2585 
2586  open();
2587  frame = dequeue(I, timestamp, id);
2588  enqueue(frame);
2589 }
2590 
2591 
2592 
2606 void
2608 {
2609  uint64_t timestamp;
2610  uint32_t id;
2611  dc1394video_frame_t *frame;
2612 
2613  open();
2614  frame = dequeue(I, timestamp, id);
2615  enqueue(frame);
2616 }
2617 
2636 void
2638  uint64_t &timestamp,
2639  uint32_t &id)
2640 {
2641  dc1394video_frame_t *frame;
2642 
2643  open();
2644  frame = dequeue();
2645  // Timeval data structure providing the unix time
2646  // [microseconds] at which the frame was captured in the ring buffer.
2647  timestamp = frame->timestamp;
2648  id = frame->id;
2649 
2650  this->width = frame->size[0];
2651  this->height = frame->size[1];
2652  unsigned int size = this->width * this->height;
2653 
2654  if ((I.getWidth() != width)||(I.getHeight() != height))
2655  I.resize(height, width);
2656 
2657  switch (frame->color_coding) {
2658  case DC1394_COLOR_CODING_MONO8:
2659  case DC1394_COLOR_CODING_RAW8:
2660  vpImageConvert::GreyToRGBa((unsigned char *) frame->image,
2661  (unsigned char *) I.bitmap, size);
2662  break;
2663 
2664  case DC1394_COLOR_CODING_YUV411:
2665  vpImageConvert::YUV411ToRGBa( (unsigned char *) frame->image,
2666  (unsigned char *) I.bitmap, size);
2667  break;
2668 
2669  case DC1394_COLOR_CODING_YUV422:
2670  vpImageConvert::YUV422ToRGBa( (unsigned char *) frame->image,
2671  (unsigned char *) I.bitmap, size);
2672  break;
2673 
2674  case DC1394_COLOR_CODING_YUV444:
2675  vpImageConvert::YUV444ToRGBa( (unsigned char *) frame->image,
2676  (unsigned char *) I.bitmap, size);
2677  break;
2678 
2679  case DC1394_COLOR_CODING_RGB8:
2680  vpImageConvert::RGBToRGBa((unsigned char *) frame->image,
2681  (unsigned char *) I.bitmap, size);
2682  break;
2683 
2684 
2685  default:
2686  close();
2687  vpERROR_TRACE("Format conversion not implemented. Acquisition failed.");
2689  "Format conversion not implemented. "
2690  "Acquisition failed.") );
2691  break;
2692  };
2693 
2694  enqueue(frame);
2695 
2696 }
2697 
2714 void vp1394TwoGrabber::getWidth(unsigned int &width)
2715 {
2716  if (! num_cameras) {
2717  close();
2718  vpERROR_TRACE("No camera found");
2720  "No camera found") );
2721  }
2722 
2723  width = this->width;
2724 }
2725 
2743 {
2744  if (! num_cameras) {
2745  close();
2746  vpERROR_TRACE("No camera found");
2748  "No camera found") );
2749  }
2750 
2751  return this->width;
2752 }
2753 
2771 void vp1394TwoGrabber::getHeight(unsigned int &height)
2772 {
2773  if (! num_cameras) {
2774  close();
2775  vpERROR_TRACE("No camera found");
2777  "No camera found") );
2778  }
2779 
2780  height = this->height;
2781 }
2800 {
2801  if (! num_cameras) {
2802  close();
2803  vpERROR_TRACE("No camera found");
2805  "No camera found") );
2806  }
2807 
2808  return this->height;
2809 }
2810 
2816 void
2818 {
2819  std::cout << "----------------------------------------------------------"
2820  << std::endl
2821  << "----- Information for camera " << camera_id
2822  << " -----" << std::endl
2823  << "----------------------------------------------------------" << std::endl;
2824 
2825 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
2826  dc1394_camera_print_info( camera, stdout);
2827 #elif defined VISP_HAVE_DC1394_2_FIND_CAMERAS // old API <= libdc1394-2.0.0-rc7
2828  dc1394_print_camera_info( camera);
2829 #endif
2830 
2831  dc1394featureset_t features;
2832 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
2833  if (dc1394_feature_get_all(camera, &features) != DC1394_SUCCESS) {
2834 #elif defined VISP_HAVE_DC1394_2_FIND_CAMERAS // old API <= libdc1394-2.0.0-rc7
2835  if (dc1394_get_camera_feature_set(camera, &features) != DC1394_SUCCESS) {
2836 #endif
2837  close();
2838  vpERROR_TRACE("unable to get feature set for camera %d\n", camera_id);
2840  "Cannot get camera features") );
2841 
2842  } else {
2843 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
2844  dc1394_feature_print_all(&features, stdout);
2845 #elif defined VISP_HAVE_DC1394_2_FIND_CAMERAS // old API <= libdc1394-2.0.0-rc7
2846  dc1394_print_feature_set(&features);
2847 #endif
2848  }
2849  std::cout << "----------------------------------------------------------" << std::endl;
2850 }
2851 
2865 {
2866  std::string _str = "";
2867  dc1394video_mode_t _videomode = (dc1394video_mode_t) videomode;
2868 
2869  if ((_videomode >= DC1394_VIDEO_MODE_MIN)
2870  && (_videomode <= DC1394_VIDEO_MODE_MAX)) {
2871  _str = strVideoMode[_videomode - DC1394_VIDEO_MODE_MIN];
2872  }
2873  else {
2874  vpCERROR << "The video mode " << videomode
2875  << " is not supported by the camera" << std::endl;
2876  }
2877 
2878  return _str;
2879 }
2880 
2894 {
2895  std::string _str = "";
2896  dc1394framerate_t _fps = (dc1394framerate_t) fps;
2897 
2898  if ((_fps >= DC1394_FRAMERATE_MIN)
2899  && (_fps <= DC1394_FRAMERATE_MAX)) {
2900  _str = strFramerate[_fps - DC1394_FRAMERATE_MIN];
2901  }
2902  else {
2903  vpCERROR << "The framerate " << fps
2904  << " is not supported by the camera" << std::endl;
2905  }
2906 
2907  return _str;
2908 }
2909 
2923 {
2924  std::string _str = "";
2925  dc1394color_coding_t _coding = (dc1394color_coding_t) colorcoding;
2926 
2927  if ((_coding >= DC1394_COLOR_CODING_MIN)
2928  && (_coding <= DC1394_COLOR_CODING_MAX)) {
2929  _str = strColorCoding[_coding - DC1394_COLOR_CODING_MIN];
2930 
2931  }
2932  else {
2933  vpCERROR << "The color coding " << colorcoding
2934  << " is not supported by the camera" << std::endl;
2935  }
2936 
2937  return _str;
2938 }
2939 
2959 {
2961 
2962  for (int i = DC1394_VIDEO_MODE_MIN; i <= DC1394_VIDEO_MODE_MAX; i ++) {
2963  _id = (vp1394TwoVideoModeType) i;
2964  if (videomode.compare(videoMode2string(_id)) == 0)
2965  return _id;
2966  };
2967 
2969  "The required videomode is not valid") );
2970 
2971  return (vp1394TwoVideoModeType) 0;
2972 }
2973 
2974 
2994 {
2996 
2997  for (int i = DC1394_FRAMERATE_MIN; i <= DC1394_FRAMERATE_MAX; i ++) {
2998  _id = (vp1394TwoFramerateType) i;
2999  if (framerate.compare(framerate2string(_id)) == 0)
3000  return _id;
3001  };
3002 
3004  "The required framerate is not valid") );
3005 
3006  return (vp1394TwoFramerateType) 0;
3007 }
3008 
3028 {
3030 
3031  for (int i = DC1394_COLOR_CODING_MIN; i <= DC1394_COLOR_CODING_MAX; i ++) {
3032  _id = (vp1394TwoColorCodingType) i;
3033  if (colorcoding.compare(colorCoding2string(_id)) == 0)
3034  return _id;
3035  };
3036 
3038  "The required color coding is not valid") );
3039 
3040  return (vp1394TwoColorCodingType) 0;
3041 }
3042 
3076 {
3077  for (unsigned int i = 0; i < num_cameras;i++) {
3078  if (camIsOpen[i]) {
3079  camera = cameras[i];
3080  setTransmission(DC1394_OFF);
3081  setCapture(DC1394_OFF);
3082  }
3083  }
3084 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE // new API > libdc1394-2.0.0-rc7
3085  setCamera(camera_id);
3086  // free the other cameras
3087  for (unsigned int i=0;i<num_cameras;i++){
3088  if (i!=camera_id) dc1394_camera_free(cameras[i]);
3089  }
3090 
3091  printf ("Reseting bus...\n");
3092  dc1394_reset_bus (camera);
3093 
3094  dc1394_camera_free (camera);
3095  dc1394_free (d);
3096  d = NULL;
3097  if (cameras != NULL)
3098  delete [] cameras;
3099  cameras = NULL ;
3100 #elif defined VISP_HAVE_DC1394_2_FIND_CAMERAS // old API <= libdc1394-2.0.0-rc7
3101 
3102  setCamera(camera_id);
3103  // free the other cameras
3104  for (unsigned int i=0;i<num_cameras;i++){
3105  if (i!=camera_id) dc1394_free_camera(cameras[i]);
3106  }
3107  free(cameras);
3108  cameras = NULL;
3109 
3110  dc1394_reset_bus(camera);
3111  dc1394_free_camera(camera);
3112 
3113 #endif
3114  if (camIsOpen != NULL)
3115  delete [] camIsOpen;
3116  camIsOpen = NULL ;
3117 
3118  num_cameras = 0;
3119 
3120  init = false;
3121  vpTime::wait(1000);
3122  initialize(false);
3123 }
3124 
3154 void vp1394TwoGrabber::setPanControl(unsigned int panControlValue)
3155 {
3156  open();
3157  if (! num_cameras) {
3158  close();
3159  vpERROR_TRACE("No camera found");
3161  "No camera found") );
3162  }
3163  uint64_t offset = 0x884;
3164  uint32_t value = 0x82000000 + (uint32_t)panControlValue;
3165  dc1394error_t err;
3166  err = dc1394_set_control_register(camera, offset, value);
3167  if (err != DC1394_SUCCESS) {
3168  vpERROR_TRACE("Unable to set PAN register");
3169  close();
3171  "Unable to set PAN register") );
3172  }
3173 }
3174 
3175 
3193 {
3194  if (! num_cameras) {
3195  close();
3196  vpERROR_TRACE("No camera found");
3198  "No camera found") );
3199  }
3200 
3201  uint32_t value;
3202  dc1394feature_t feature = (dc1394feature_t)param;
3203  dc1394error_t err;
3204  err = dc1394_feature_get_value(camera, feature, &value);
3205  if (err != DC1394_SUCCESS) {
3206  vpERROR_TRACE("Unable to get the information");
3207  close();
3209  "Unable to get the information") );
3210  }
3211  return (unsigned int)value;
3212 }
3213 
3214 
3236  unsigned int val)
3237 {
3238  if (! num_cameras) {
3239  close();
3240  vpERROR_TRACE("No camera found");
3242  "No camera found") );
3243  }
3244  uint32_t value = (uint32_t)val;
3245  dc1394feature_t feature = (dc1394feature_t)param;
3246  dc1394error_t err;
3247  dc1394bool_t hasManualMode = DC1394_FALSE;
3248  dc1394feature_modes_t modesAvailable;
3249 
3250  // test wether we can set the shutter value (manual mode available or not)
3251  err = dc1394_feature_get_modes(camera, feature, &modesAvailable);
3252  if (err != DC1394_SUCCESS) {
3253  vpERROR_TRACE("Unable to detect the manual mode information");
3254  close();
3256  "Unable to detect the manual mode information"));
3257  }
3258 
3259  for(unsigned int i=0; i<modesAvailable.num; i++){
3260  if(modesAvailable.modes[i] == DC1394_FEATURE_MODE_MANUAL){
3261  hasManualMode = DC1394_TRUE;
3262  }
3263  }
3264 
3265  if(hasManualMode == DC1394_TRUE){
3266 
3267  if(!isDataModified[camera_id]){// to ensure we save the first mode even after several set
3268  /* we update the structure */
3269  updateDataCamToStruct();
3270  err = dc1394_feature_get_mode(camera, feature, &(initialShutterMode[camera_id]));
3271  if (err != DC1394_SUCCESS) {
3272  vpERROR_TRACE("Unable to get the initial mode");
3273  close();
3275  "Unable to get the initial mode"));
3276  }
3277  isDataModified[camera_id] = true;
3278  }
3279 
3280  dc1394feature_mode_t manualMode = DC1394_FEATURE_MODE_MANUAL;
3281  err = dc1394_feature_set_mode(camera, feature, manualMode);
3282  if (err != DC1394_SUCCESS) {
3283  vpERROR_TRACE("Unable to set the muanual mode");
3284  close();
3286  "Unable to set the manual mode") );
3287  }
3288  err = dc1394_feature_set_value(camera, feature, value);
3289  if (err != DC1394_SUCCESS) {
3290  vpERROR_TRACE("Unable to set the shutter information");
3291  close();
3293  "Unable to set the shutter information") );
3294  }
3295  }
3296  else{
3297  vpERROR_TRACE("The camera does not have a manual mode.\nCannot change the value");
3299  "The camera does not have a manual mode"));
3300  }
3301 }
3309 void
3311 {
3312  if (! num_cameras) {
3313  close();
3314  vpERROR_TRACE("No camera found");
3316  "No camera found") );
3317  }
3318 
3319  guid = camera->guid;
3320 }
3321 
3329 uint64_t
3331 {
3332  if (! num_cameras) {
3333  close();
3334  vpERROR_TRACE("No camera found");
3336  "No camera found") );
3337  }
3338 
3339  return camera->guid;
3340 }
3341 
3342 
3347 inline void
3348 vp1394TwoGrabber::updateDataCamToStruct()
3349 {
3350  dataCam[camera_id].brightness = getParameterValue(vpFEATURE_BRIGHTNESS);
3351  dataCam[camera_id].exposure = getParameterValue(vpFEATURE_EXPOSURE);
3352  dataCam[camera_id].sharpness = getParameterValue(vpFEATURE_SHARPNESS);
3353  dataCam[camera_id].hue = getParameterValue(vpFEATURE_HUE);
3354  dataCam[camera_id].saturation = getParameterValue(vpFEATURE_SATURATION);
3355  dataCam[camera_id].gamma = getParameterValue(vpFEATURE_GAMMA);
3356  dataCam[camera_id].shutter = getParameterValue(vpFEATURE_SHUTTER);
3357  dataCam[camera_id].gain = getParameterValue(vpFEATURE_GAIN);
3358  dataCam[camera_id].iris = getParameterValue(vpFEATURE_IRIS);
3359 }
3360 
3365 inline void
3366 vp1394TwoGrabber::updateDataStructToCam()
3367 {
3368  setParameterValue(vpFEATURE_BRIGHTNESS, dataCam[camera_id].brightness);
3369  setParameterValue(vpFEATURE_EXPOSURE, dataCam[camera_id].exposure);
3370  setParameterValue(vpFEATURE_SHARPNESS, dataCam[camera_id].sharpness);
3371  setParameterValue(vpFEATURE_HUE, dataCam[camera_id].hue);
3372  setParameterValue(vpFEATURE_SATURATION, dataCam[camera_id].saturation);
3373  setParameterValue(vpFEATURE_GAMMA, dataCam[camera_id].gamma);
3374  setParameterValue(vpFEATURE_SHUTTER, dataCam[camera_id].shutter);
3375  setParameterValue(vpFEATURE_GAIN, dataCam[camera_id].gain);
3376  setParameterValue(vpFEATURE_IRIS, dataCam[camera_id].iris);
3377 }
3378 
3379 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
3380 
3398 uint32_t
3400 {
3401  // Refresh the list of supported modes
3402  videomodes.kill();
3403 
3404  if (! num_cameras) {
3405  close();
3406  vpERROR_TRACE("No camera found");
3408  "No camera found") );
3409  }
3410  dc1394video_modes_t _videomodes;
3411 
3412  // get video modes:
3413  if (dc1394_video_get_supported_modes(camera, &_videomodes)!=DC1394_SUCCESS) {
3414 
3415  close();
3416  vpERROR_TRACE("Can't get video modes");
3418  "Can't get video modes") );
3419  }
3420 
3421  // parse the video modes to add in the list
3422  for (unsigned i=0; i < _videomodes.num; i++) {
3423  vp1394TwoVideoModeType _mode = (vp1394TwoVideoModeType) _videomodes.modes[i];
3424  videomodes.addRight( _mode );
3425  }
3426 
3427  // return the number of available video modes
3428  return _videomodes.num;
3429 }
3430 
3463 uint32_t
3466 {
3467  if (! num_cameras) {
3468  close();
3469  vpERROR_TRACE("No camera found");
3471  "No camera found") );
3472  }
3473 
3474  // Refresh the list of supported framerates
3475  fps.kill();
3476 
3477  switch (mode) {
3478  // Framerate not available for:
3479  // - vpVIDEO_MODE_EXIF ie Format_6
3480  // - vpVIDEO_MODE_FORMAT7... ie the Format_7
3481  case vpVIDEO_MODE_EXIF:
3490  return 0;
3491  break;
3492  default:
3493  {
3494  dc1394framerates_t _fps;
3495  if (dc1394_video_get_supported_framerates(camera,
3496  (dc1394video_mode_t)mode,
3497  &_fps) != DC1394_SUCCESS) {
3498  close();
3499  vpERROR_TRACE("Could not query supported frametates for mode %d\n",
3500  mode);
3502  "Could not query supported framerates") );
3503  }
3504  if (_fps.num == 0)
3505  return 0;
3506 
3507  for (unsigned int i = 0; i < _fps.num; i ++)
3508  fps.addRight((vp1394TwoFramerateType)_fps.framerates[i]);
3509 
3510  return _fps.num;
3511  }
3512  break;
3513  }
3514 }
3515 
3540 uint32_t
3543 {
3544  if (! num_cameras) {
3545  close();
3546  vpERROR_TRACE("No camera found");
3548  "No camera found") );
3549  }
3550 
3551  // Refresh the list of supported framerates
3552  codings.kill();
3553 
3554  if (dc1394_is_video_mode_scalable((dc1394video_mode_t)mode)) {
3555  // Format 7 video mode
3556  dc1394color_codings_t _codings;
3557  if (dc1394_format7_get_color_codings(camera,
3558  (dc1394video_mode_t)mode,
3559  &_codings) != DC1394_SUCCESS) {
3560  close();
3561  vpERROR_TRACE("Could not query supported color codings for mode %d\n",
3562  mode);
3564  "Could not query supported color codings") );
3565  }
3566  if (_codings.num == 0)
3567  return 0;
3568 
3569  for (unsigned int i = 0; i < _codings.num; i ++)
3570  codings.addRight((vp1394TwoColorCodingType)_codings.codings[i]);
3571 
3572  return _codings.num;
3573  }
3574  else if (dc1394_is_video_mode_still_image((dc1394video_mode_t)mode)) {
3575  // Format 6 video mode
3576  return 0;
3577  }
3578  else {
3579  // Not Format 7 and not Format 6 video modes
3580  dc1394color_coding_t _coding;
3581  if (dc1394_get_color_coding_from_video_mode(camera,
3582  (dc1394video_mode_t)mode,
3583  &_coding) != DC1394_SUCCESS) {
3584  close();
3585  vpERROR_TRACE("Could not query supported color coding for mode %d\n",
3586  mode);
3588  "Could not query supported color coding") );
3589  }
3590  codings.addRight((vp1394TwoColorCodingType)_coding);
3591  return 1;
3592  }
3593 }
3594 #endif
3595 
3596 #endif
3597 
void getColorCoding(vp1394TwoColorCodingType &coding)
static const char * strFramerate[DC1394_FRAMERATE_NUM]
uint32_t getColorCodingSupported(vp1394TwoVideoModeType videomode, std::list< vp1394TwoColorCodingType > &codings)
static std::string colorCoding2string(vp1394TwoColorCodingType colorcoding)
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int size)
void setAutoShutter(unsigned int minvalue, unsigned int maxvalue)
void setIsoTransmissionSpeed(vp1394TwoIsoSpeedType isospeed)
static std::string framerate2string(vp1394TwoFramerateType fps)
unsigned int getWidth() const
Definition: vpImage.h:154
#define vpERROR_TRACE
Definition: vpDebug.h:379
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
#define vpTRACE
Definition: vpDebug.h:401
Provide simple list management.
Definition: vpList.h:112
Type * bitmap
points toward the bitmap
Definition: vpImage.h:115
static void MONO16ToGrey(unsigned char *grey16, unsigned char *grey, unsigned int size)
#define vpCERROR
Definition: vpDebug.h:354
vp1394TwoGrabber(bool reset=true)
bool isVideoModeFormat7(vp1394TwoVideoModeType videomode)
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:530
static const char * strColorCoding[DC1394_COLOR_CODING_NUM]
static void GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsigned int size)
static void YUV422ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
void kill()
Destroy the list.
Definition: vpList.h:694
static int wait(double t0, double t)
Definition: vpTime.cpp:149
unsigned int getParameterValue(vp1394TwoParametersType param)
void acquire(vpImage< unsigned char > &I)
unsigned int getNumCameras()
static vp1394TwoColorCodingType string2colorCoding(std::string colorcoding)
Error that can be emited by the vpFrameGrabber class and its derivates.
uint32_t getVideoModeSupported(std::list< vp1394TwoVideoModeType > &videomodes)
static void YUV444ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
bool isFramerateSupported(vp1394TwoVideoModeType videomode, vp1394TwoFramerateType fps)
unsigned int getRingBufferSize()
#define vpCTRACE
Definition: vpDebug.h:327
void setColorCoding(vp1394TwoColorCodingType coding)
void open(vpImage< unsigned char > &I)
static void YUV422ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
void setRingBufferSize(unsigned int size)
static vp1394TwoVideoModeType string2videoMode(std::string videomode)
void setFormat7ROI(unsigned int left=0, unsigned int top=0, unsigned int width=0, unsigned int height=0)
unsigned int height
Number of rows in the image.
void setCamera(uint64_t camera)
static const char * strVideoMode[DC1394_VIDEO_MODE_NUM]
void addRight(const type &el)
add a new element in the list, at the right of the current one
Definition: vpList.h:480
static void MONO16ToRGBa(unsigned char *grey16, unsigned char *rgba, unsigned int size)
void enqueue(dc1394video_frame_t *frame)
static vp1394TwoFramerateType string2framerate(std::string fps)
unsigned int getWidth()
void getFramerate(vp1394TwoFramerateType &fps)
static std::string videoMode2string(vp1394TwoVideoModeType videomode)
bool init
Set to true if the frame grabber has been initialized.
void setParameterValue(vp1394TwoParametersType param, unsigned int val)
static void YUV444ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
bool isColorCodingSupported(vp1394TwoVideoModeType videomode, vp1394TwoColorCodingType coding)
static void YUV411ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
void setFramerate(vp1394TwoFramerateType fps)
dc1394video_frame_t * dequeue()
void setVideoMode(vp1394TwoVideoModeType videomode)
void setPanControl(unsigned int panControlValue)
uint32_t getFramerateSupported(vp1394TwoVideoModeType videomode, std::list< vp1394TwoFramerateType > &fps)
unsigned int getHeight() const
Definition: vpImage.h:145
bool isVideoModeSupported(vp1394TwoVideoModeType videomode)
static void YUV411ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
void getVideoMode(vp1394TwoVideoModeType &videomode)
unsigned int width
Number of columns in the image.
unsigned int getHeight()