25 #include <dc1394/control.h>
27 #include "VideoSource_DCAM.hh"
34 #define NUM_DMA_BUFFERS 10
47 dc1394camera_list_t *camsList;
50 dc1394_t *d = dc1394_new();
51 err = dc1394_camera_enumerate(d, &camsList);
52 ncams = (int) camsList->num;
54 if (err != DC1394_SUCCESS)
56 BIASERR(
"Scanning bus failed");
63 for (
int i = 0; i < ncams; i++)
66 cam->
OpenDevice(camsList->ids[i].guid & 0x00000FFF);
69 ss <<
"0" <<
" " << (camsList->ids[i].guid & 0x00000FFF) <<
" "
80 BIASERR(
"No cameras found on bus ");
94 dc1394camera_list_t *camsList;
97 dc1394_t *d = dc1394_new();
98 err = dc1394_camera_enumerate(d, &camsList);
99 ncams = (int) camsList->num;
101 if (err != DC1394_SUCCESS)
104 for (
int i = 0; i < ncams; i++)
107 cams = dc1394_camera_new(d, camsList->ids[i].guid);
110 camInfo.
camid = (camsList->ids[i].guid & 0x00000FFF);
111 string m(cams->model);
112 string v(cams->vendor);
115 camInfo.
guid = camsList->ids[i].guid;
117 bool setFirewireManual =
false;
119 unsigned int vendor = (camsList->ids[i].guid) >> 40;
120 unsigned int model = (camsList->ids[i].guid >> 12) & 0xFF;
123 if ((model == 0xf5 || model == 0x28) && vendor == 0x00b09d)
125 setFirewireManual =
true;
127 else if (m ==
"Firefly MV FFMV-03MTM")
129 setFirewireManual =
true;
132 if (cams->bmode_capable == DC1394_TRUE && !setFirewireManual)
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_;
147 dc1394_video_get_supported_modes(cams, &modes);
148 for (
unsigned int j = 0; j < modes.num; j++)
151 modesVector.push_back(modes.modes[j]);
153 if (modes.modes[j] < DC1394_VIDEO_MODE_EXIF)
155 vector<float> innerFramesVector;
156 dc1394framerates_t framerates;
158 dc1394_video_get_supported_framerates(cams, modes.modes[j],
160 for (
unsigned int l = 0; l < framerates.num; l++)
162 dc1394_framerate_as_float(framerates.framerates[l], &fr);
163 innerFramesVector.push_back(fr);
165 framesVector.push_back(innerFramesVector);
168 else if (modes.modes[j] > DC1394_VIDEO_MODE_EXIF)
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_,
175 dc1394_format7_get_packet_parameters(cams, modes.modes[j],
177 dc1394_format7_get_recommended_packet_size(cams, modes.modes[j],
180 for (
int k = 0; k < 8; k++)
182 if (modes.modes[j] == DC1394_VIDEO_MODE_FORMAT7_0 + k)
185 (dc1394video_mode_t) (DC1394_VIDEO_MODE_FORMAT7_0 + k));
209 dc1394color_coding_t colorCoding;
212 for (y = modes.num - 1; y >= 0; y--)
214 if (modes.modes[y] < DC1394_VIDEO_MODE_EXIF)
218 dc1394_get_color_coding_from_video_mode(cams, modes.modes[y],
221 if (colorCoding != DC1394_COLOR_CODING_MONO16)
228 cout <<
"Best Mode: " << camInfo.
bestMode << endl;
231 camInfo.
bestFramerate = framesVector[y][framesVector[y].size() - 1];
233 camInfos.push_back(camInfo);
235 dc1394_camera_free(cams);
237 dc1394_camera_free_list(camsList);
257 DcamMode_ = DC1394_VIDEO_MODE_160x120_YUV444;
290 #ifdef BIAS_HAVE_PTHREADS
301 dc1394_camera_free(
camera);
308 dc1394video_mode_t mode,
int width,
int height,
unsigned int& minbpp,
309 unsigned int& maxbpp)
311 dcbus = dc1394_new();
316 BIASDOUT(D_DCAM,
"There is no cam to open");
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);
350 camid = manualcamid_;
358 BIASDOUT(D_DCAM,
"VideoSource_DCAM::OpenDevice("<< camid <<
")");
359 dcbus = dc1394_new();
362 BIASERR(
"dc1394_new() failed.");
366 if (
err != DC1394_SUCCESS)
368 BIASERR(
"dc1394_camera_enumerate() failed.");
376 BIASERR(
"There is no cam to open");
391 bool foundCamWithId =
false;
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);
408 foundCamWithId =
true;
412 dc1394_camera_free(
camera);
454 DcamMode_ = (dc1394video_mode_t) (DC1394_VIDEO_MODE_FORMAT7_MIN + mode);
489 #ifdef BIAS_HAVE_PTHREADS
493 BIASDOUT(D_DCAM,
"VideoSource_DCAM::GrabSingle("<<
SelectedCam_<<
")");
497 BIASERR(
"VideoSource_DCAM::GrabSingle(): Given Image is empty, use InitImage()");
503 BIASERR(
"VideoSource_DCAM::GrabSingle(): VideoSource Object not active, use PreGrab()");
508 BIASERR(
"VideoSource_DCAM::GrabSingle(): VideoSource Object is already grabbing()");
513 dc1394video_frame_t * frame;
514 err = dc1394_capture_dequeue(
camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
515 if (
err != DC1394_SUCCESS)
517 BIASERR(
"VideoSource_DCAM::GrabSingle(): unable to capture from camera:"<<
CamModel_);
523 while(frame &&
err == DC1394_SUCCESS) {
525 err = dc1394_capture_enqueue(
camera, frame);
526 err = dc1394_capture_dequeue(
camera, DC1394_CAPTURE_POLICY_POLL, &frame);
532 image.
SetTime(0, frame->timestamp);
535 err = dc1394_capture_enqueue(
camera, frame);
542 #ifdef BIAS_HAVE_PTHREADS
549 #ifdef BUILD_IMAGE_USHORT
553 #ifdef BIAS_HAVE_PTHREADS
557 BIASDOUT(D_DCAM,
"VideoSource_DCAM::GrabSingle("<<
SelectedCam_<<
")");
561 BIASERR(
"VideoSource_DCAM::GrabSingle(): Given Image is empty, use InitImage()");
567 BIASERR(
"VideoSource_DCAM::GrabSingle(): VideoSource Object not active, use PreGrab()");
572 BIASERR(
"VideoSource_DCAM::GrabSingle(): VideoSource Object is already grabbing()");
577 dc1394video_frame_t * frame;
578 err = dc1394_capture_dequeue(
camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
579 if (
err != DC1394_SUCCESS)
581 BIASERR(
"VideoSource_DCAM::GrabSingle(): unable to capture from camera:"<<
CamModel_);
586 unsigned int numbytes = image.
GetSize();
588 unsigned char *idata = (
unsigned char *) image.
GetImageData();
589 unsigned char *buf = (
unsigned char *) frame->image;
591 for (
unsigned int i = 0; i < numbytes; i += 2)
593 idata[i] = buf[i + 1];
594 idata[i + 1] = buf[i];
597 *(
unsigned short *) (&idata[i]) = (*(
unsigned short *) (&idata[i]))
600 image.
SetTime(0, frame->timestamp);
603 err = dc1394_capture_enqueue(
camera, frame);
610 #ifdef BIAS_HAVE_PTHREADS
628 BIASDOUT(D_DCAM,
"VideoSource_DCAM::PreGrab("<<
SelectedCam_<<
")");
636 printf(
"Start transmission\n");
637 if (dc1394_video_set_transmission(
camera, DC1394_ON) != DC1394_SUCCESS)
639 fprintf(stderr,
"Unable to start camera iso transmission\n");
647 dc1394switch_t isoOn;
648 dc1394_video_get_transmission(
camera, &isoOn);
649 cout <<
"Iso on: " << isoOn << endl;
659 BIASDOUT(D_DCAM,
"VideoSource_DCAM::PostGrab("<<
SelectedCam_<<
")");
661 if (dc1394_video_set_transmission(
camera, DC1394_OFF) != DC1394_SUCCESS)
663 cout <<
"Couldn't stop the camera?" << endl;
665 dc1394_capture_stop(
camera);
674 BIASDOUT(D_DCAM,
"VideoSource_DCAM::QueryCam("<<
SelectedCam_<<
")");
679 if (
err != DC1394_SUCCESS)
681 BIASDOUT(D_DCAM,
"Could not query cam for modes");
689 if (mode < DC1394_VIDEO_MODE_EXIF)
691 err = dc1394_video_get_supported_framerates(
camera, mode,
699 - mode].framerates[j], &fr);
709 if (mode > DC1394_VIDEO_MODE_EXIF)
815 cout <<
"VideoSource_DCAM::SelectDefault(" <<
SelectedCam_ <<
")" << endl;
816 dc1394color_coding_t colorCoding;
827 if (colorCoding != DC1394_COLOR_CODING_MONO16)
852 <<
" Ignoring autodetected mode for Dragonfly2. Setting to format2, mode4, 7.5fps."
854 DcamMode_ = DC1394_VIDEO_MODE_1600x1200_RGB8;
865 <<
" Ignoring autodetected mode for Grasshopper. Setting to format1, mode3, 15fps."
867 cout <<
" Size 1600x1200" << endl;
868 DcamMode_ = DC1394_VIDEO_MODE_1024x768_YUV422;
878 <<
" Ignoring autodetected mode for Fire-i. Setting to 640x480 RGB8, 15 fps."
880 DcamMode_ = DC1394_VIDEO_MODE_640x480_RGB8;
890 <<
" Ignoring autodetected mode for FireFLY setting to 640x480, color, 30fps."
893 DcamMode_ = DC1394_VIDEO_MODE_640x480_MONO8;
903 <<
" \n\nIgnoring autodetected mode for FireFLY setting to mono8, 30fps. "
906 DcamMode_ = DC1394_VIDEO_MODE_640x480_MONO8;
916 cout <<
" Setting best framerate right for the DragonFly 2.\n";
923 cout <<
" Setting best framerate right for the KameraWerk Dresden i5\n";
928 DcamMode_ = DC1394_VIDEO_MODE_1024x768_MONO8;
932 dc1394_framerate_as_float(
DcamFps_, &fr);
933 BIASDOUT(D_DCAM,
"Best Settings for Camera: " <<
Width_<<
"x"<<
Height_
934 <<
" at "<< fr<<
"fps"<<
" Colormodel: "<<
ColorMode_);
939 #define USE_NATIVE_XGA
958 <<
" -bit not yet impl");
981 DcamMode_ = DC1394_VIDEO_MODE_1600x1200_YUV422;
986 DcamMode_ = DC1394_VIDEO_MODE_1280x960_YUV422;
991 DcamMode_ = DC1394_VIDEO_MODE_1024x768_YUV422;
993 BIASDOUT(D_DCAM,
"Using native XGA");
997 DcamMode_ = DC1394_VIDEO_MODE_800x600_YUV422;
1002 DcamMode_ = DC1394_VIDEO_MODE_640x480_YUV422;
1007 DcamMode_ = DC1394_VIDEO_MODE_320x240_YUV422;
1035 DcamMode_ = DC1394_VIDEO_MODE_640x480_YUV411;
1049 DcamMode_ = DC1394_VIDEO_MODE_1600x1200_MONO8;
1050 cout <<
"Mode:DC1394_VIDEO_MODE_1600x1200_MONO8" << endl;
1054 DcamMode_ = DC1394_VIDEO_MODE_1024x768_MONO8;
1058 DcamMode_ = DC1394_VIDEO_MODE_1280x960_MONO8;
1064 DcamMode_ = DC1394_VIDEO_MODE_640x480_MONO8;
1065 BIASDOUT(D_DCAM,
"Mode: "
1074 DcamMode_ = DC1394_VIDEO_MODE_640x480_RGB8;
1080 BIASERR(
"VideoSource_DCAM::UserSizeToMode(): Unsupported ColorModel_"
1104 DcamMode_ = DC1394_VIDEO_MODE_640x480_MONO16;
1106 BIASDOUT(D_DCAM,
"Mode: "
1107 <<
" 640x480_MONO16");
1112 DcamMode_ = DC1394_VIDEO_MODE_1024x768_MONO16;
1113 BIASDOUT(D_DCAM,
" Mode: "
1114 <<
" 1024x768_MONO16");
1119 DcamMode_ = DC1394_VIDEO_MODE_1280x960_MONO16;
1124 DcamMode_ = DC1394_VIDEO_MODE_1600x1200_MONO16;
1130 BIASERR(
"VideoSource_DCAM::UserSizeToMode(): Unsupported ColoModel_ for 16bpp:"<<
ColorMode_)
1142 unsigned int BpP = 0;
1143 unsigned int QuadletsPerPacket;
1145 int QuadletsPerFrame;
1146 double TransmissionTimePerFrame;
1147 double MaxCyclesPerFrame;
1148 unsigned int CyclesPerFrame;
1152 BIASERR(
"VideoSource_DCAM::CalcBytesPerPacket(): FramesPerSecond_ is 0!");
1156 dc1394_format7_get_packet_parameters(
camera, DC1394_VIDEO_MODE_FORMAT7_0,
1165 if (fps > 14.9 && fps < 20.0)
1168 if (fps > 29.9 && fps < 35)
1170 TransmissionTimePerFrame = 1000.0 / fps;
1172 MaxCyclesPerFrame = TransmissionTimePerFrame / 0.125;
1173 CyclesPerFrame = (int) MaxCyclesPerFrame;
1175 QuadletsPerPacket = QuadletsPerFrame / CyclesPerFrame;
1177 while ((QuadletsPerFrame % QuadletsPerPacket) != 0)
1180 QuadletsPerPacket = QuadletsPerFrame / CyclesPerFrame;
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;
1221 BIASERR(
"VideoSource_DCAM::ApplyBytesPerPacket(): Sorry, not implemented");
1228 BIASDOUT(D_DCAM,
"VideoSource_DCAM::InitCam("<<
SelectedCam_<<
")");
1233 if (
camera->bmode_capable)
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");
1244 dc1394_video_set_iso_speed(
camera, DC1394_ISO_SPEED_400);
1249 dc1394_video_set_iso_speed(
camera, DC1394_ISO_SPEED_400);
1262 BIASERR(
"UserSizeToMode() failed, trying to find default values");
1273 cout <<
"\n\tSetting mode from User\n\n" << endl;
1280 dc1394framerates_t frameRates =
1285 = (dc1394framerate_t) (frameRates.framerates[frameRates.num
1290 cout <<
"DcamFps_: " <<
DcamFps_ << endl;
1300 BIASERR(
"Unable to set default mode for camera");
1306 if (
DcamMode_ < DC1394_VIDEO_MODE_FORMAT7_MIN)
1315 dc1394framerate_t videoframerate = DC1394_FRAMERATE_MIN;
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;
1340 if (dc1394_video_set_framerate(
camera, videoframerate)
1343 BIASERR(
"Failed to set user frame rate, setting default");
1352 BIASERR(
"Failed to set default framerate");
1355 cout <<
"Set default framerate" << endl;
1358 else if (
DcamMode_ < DC1394_VIDEO_MODE_FORMAT7_MAX)
1363 BIASERR(
"Autoselected Format 7 yet not implemented");
1374 BIASERR(
"Failed to set user requested format 7 mode");
1378 cout <<
"Left: " <<
Left_ <<
", Top: " <<
Top_ << endl;
1394 BIASDOUT(D_DCAM,
"Set Bytes per packet to: " << bpp);
1399 const int sizeInternCamBuff = NUM_DMA_BUFFERS;
1401 err = dc1394_capture_setup(
camera, sizeInternCamBuff,
1402 DC1394_CAPTURE_FLAGS_DEFAULT);
1407 if (
err != DC1394_SUCCESS)
1409 dc1394_reset_bus(
camera);
1410 err = dc1394_capture_setup(
camera, sizeInternCamBuff,
1411 DC1394_CAPTURE_FLAGS_DEFAULT);
1414 if (
err == DC1394_SUCCESS)
1416 BIASDOUT(D_DCAM,
"Initialization successful");
1420 BIASDOUT(D_DCAM,
"Initialization failed");
1500 if (dc1394_feature_set_mode(
camera, feature, mode) != DC1394_SUCCESS)
1502 BIASERR(
"VideoSource_DCAM::AutoMode(): failed to set feature auto mode");
1512 dc1394feature_mode_t mode;
1514 mode = DC1394_FEATURE_MODE_AUTO;
1516 mode = DC1394_FEATURE_MODE_MANUAL;
1518 AutoMode(DC1394_FEATURE_SHUTTER, mode);
1523 dc1394feature_mode_t mode;
1524 if (dc1394_feature_get_mode(
camera, DC1394_FEATURE_SHUTTER, &mode)
1527 if (DC1394_FEATURE_MODE_AUTO == mode)
1537 dc1394feature_mode_t mode;
1539 mode = DC1394_FEATURE_MODE_AUTO;
1541 mode = DC1394_FEATURE_MODE_MANUAL;
1542 AutoMode(DC1394_FEATURE_BRIGHTNESS, mode);
1548 dc1394feature_mode_t mode;
1549 if (dc1394_feature_get_mode(
camera, DC1394_FEATURE_BRIGHTNESS, &mode)
1552 if (DC1394_FEATURE_MODE_AUTO == mode)
1561 dc1394feature_mode_t mode;
1563 mode = DC1394_FEATURE_MODE_AUTO;
1565 mode = DC1394_FEATURE_MODE_MANUAL;
1566 AutoMode(DC1394_FEATURE_GAIN, mode);
1572 dc1394feature_mode_t mode;
1573 if (dc1394_feature_get_mode(
camera, DC1394_FEATURE_GAIN, &mode)
1576 if (DC1394_FEATURE_MODE_AUTO == mode)
1587 == DC1394_FEATURE_WHITE_BALANCE)
1593 res = dc1394_feature_set_mode(
camera, feature,
1594 DC1394_FEATURE_MODE_ONE_PUSH_AUTO);
1596 if (res != DC1394_SUCCESS)
1598 BIASERR(
"VideoSource_DCAM::OnePushAuto()");
1611 dc1394feature_mode_t mode;
1612 res = dc1394_feature_get_mode(
camera, feature, &mode);
1613 if (res != DC1394_SUCCESS)
1616 if (mode == DC1394_FEATURE_MODE_ONE_PUSH_AUTO)
1631 BIASDOUT(D_DCAM,
"Triggermode: 1 (extern)");
1632 res = dc1394_external_trigger_set_power(
camera, DC1394_ON);
1637 BIASDOUT(D_DCAM,
"Triggermode: 3 (intern)");
1640 res = dc1394_external_trigger_set_power(
camera, DC1394_OFF);
1651 if (res != DC1394_SUCCESS)
1653 BIASERR(
"unable to set camera "<<
ID_<<
" to trigger mode ");
1665 dc1394bool_t isPresent;
1666 dc1394_feature_is_present(
camera, feature, &isPresent);
1670 dc1394_feature_get_value(
camera, feature, &value);
1674 BIASERR(
"Feature not supported by camera "<<
ID_);BIASASSERT(
false);
1684 dc1394bool_t isPresent;
1685 dc1394_feature_is_present(
camera, feature, &isPresent);
1689 dc1394feature_mode_t mode = DC1394_FEATURE_MODE_MANUAL;
1691 dc1394_feature_set_value(
camera, feature, value);
1695 BIASERR(
"Feature not supported by camera "<<
ID_);
1713 BIASERR(
"VideoSource_DCAM::SetLeftTop() values too large:"<<left<<
"x"<<top);
1724 dc1394feature_t feature = DC1394_FEATURE_SHUTTER;
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))
1735 else if ((exptime <= 0.067) && (exptime >= 0.00012))
1737 value = (int) (2848.4 - round(28636363.0 * exptime / (1197.0 * 2.0)));
1739 else if ((exptime <= 0.00012) && (exptime >= 0.00004))
1745 BIASERR(
"Exposuretime out of bounds: "<<exptime);
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);
1756 BIASERR(
"Exposuretime out of bounds: "<<exptime);
1771 dc1394_feature_set_absolute_control(
camera, feature, DC1394_ON);
1773 dc1394_feature_set_absolute_value(
camera, feature, exptime);
1779 value = rint((1000.0*exptime) / 99.0*7.0);
1782 value = rint(exptime*1000.0);
1785 BIASERR(
"Sorry your Camera Model:"<<
CamModel_<<
" is not supported.");
1790 return SetFeature(DC1394_FEATURE_SHUTTER, value);
1800 float exptime = 0.0;
1801 int shutter =
GetFeature(DC1394_FEATURE_SHUTTER);
1808 exptime = ((float) (2048 - shutter + 1) * (1197.0 * 800.0 * 2.0)
1809 / (28.636363 * 1000000.0));
1813 exptime = ((2848.4 - float(shutter)) * (1197.0 * 2.0) / (28.636363
1816 exptime = 50.0 / 1000000.0;
1819 if (shutter < 0x800)
1820 exptime = ((float) (shutter - 2048) / 30.0);
1822 exptime = ((float) (shutter - 2573.6) / -15734.3);
1836 dc1394_feature_get_absolute_value(
camera, DC1394_FEATURE_SHUTTER, &exptime);
1846 dc1394feature_t feature = DC1394_FEATURE_GAIN;
1855 int value = min + (int) (gain * (
float) (max - min));
1863 int value = min + (int) (gain * (
float) (max - min));
1869 int value = gain * 255.0 / 30.0;
1885 dc1394_feature_set_absolute_control(
camera, feature, DC1394_ON);
1887 res = (int)dc1394_feature_set_absolute_value(
camera, feature, gain);
1905 cout <<
"Value in GetGain from GetFeature(...) :" << value << endl;
1907 gain = (float) (value - min) / (float) (max - min);
1915 cout <<
"Value in GetGain from GetFeature(...) :" << value << endl;
1917 gain = (float) (value - min) / (float) (max - min);
1937 dc1394_feature_get_absolute_value(
camera,DC1394_FEATURE_GAIN, &gain);
1949 dc1394feature_t feature = DC1394_FEATURE_BRIGHTNESS;
1950 dc1394_feature_set_absolute_control(
camera, feature, DC1394_ON);
1952 dc1394error_t res = dc1394_feature_set_absolute_value(
camera, feature, brightness);
1959 float brightness = 0.0;
1960 dc1394_feature_get_absolute_value(
camera,DC1394_FEATURE_BRIGHTNESS, &brightness);
1970 if (res < 0)
return res;
1987 int ibval = 0, irval = 0;
1994 ibval = (int) rint((bvalue + 0.5f ) * 255.0f);
1995 irval = (int) rint((rvalue + 0.5f ) * 255.0f);
2007 ibval = (
unsigned int) rint(bvalue*32) + 32;
2008 irval = (
unsigned int) rint(rvalue*32) + 32;
2020 ibval = (
unsigned int) rint(bvalue*63) + 63;
2021 irval = (
unsigned int) rint(rvalue*63) + 63;
2034 ibval = (
unsigned int) rint(bvalue*512) + 512;
2035 irval = (
unsigned int) rint(rvalue*512) + 512;
2047 if (dc1394_feature_whitebalance_set_value(
camera, ibval, irval)== DC1394_SUCCESS)
2050 BIASWARN(
"Could not set white balance, feature not supported by either camera or lib.");
2058 dc1394feature_mode_t mode;
2061 BIASDOUT(D_DCAM,
"Entering SetCamera()");
2066 mode = DC1394_FEATURE_MODE_AUTO;
2068 mode = DC1394_FEATURE_MODE_MANUAL;
2070 res =
AutoMode(DC1394_FEATURE_SHUTTER, mode);
2077 mode = DC1394_FEATURE_MODE_AUTO;
2079 mode = DC1394_FEATURE_MODE_MANUAL;
2081 res =
AutoMode(DC1394_FEATURE_GAIN, mode);
2088 mode = DC1394_FEATURE_MODE_AUTO;
2090 mode = DC1394_FEATURE_MODE_MANUAL;
2092 res =
AutoMode(DC1394_FEATURE_WHITE_BALANCE, mode);
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;
2160 BIASDOUT(D_DCAM,
"Vendor: Sony");
2177 BIASDOUT(D_DCAM,
"Vendor: PointGrey Research");
2182 BIASDOUT(D_DCAM,
"Model: Dragonfly BW LowRes")
2188 BIASDOUT(D_DCAM,
"Model: Dragonfly Color LowRes")
2195 BIASDOUT(D_DCAM,
"Model: Dragonfly B&W HiRes")
2202 BIASDOUT(D_DCAM,
"Model: Scorpion Color 1600")
2211 BIASDOUT(D_DCAM,
"Model: FireFly Color")
2216 BIASDOUT(D_DCAM,
"Model: FireFly BW") ;
2220 if (model_lo == 0x355)
2222 BIASDOUT(D_DCAM,
"Model: GrassHopper Color");
2231 BIASDOUT(D_DCAM,
"Model: DragonFly2 HIRES Color");
2247 BIASDOUT(D_DCAM,
"Model: PtGrey FLEA2 BW")
2253 BIASDOUT(D_DCAM,
"Model: PtGrey Bumblebee XB3")
2259 BIASDOUT(D_DCAM,
"Model: PtGrey Bumblebee XB2")
2263 BIASDOUT(D_DCAM,
"Model: Unknown:"<<model)
2270 BIASDOUT(D_DCAM,
"Vendor: Unibrain");
2276 BIASDOUT(D_DCAM,
"Model: Fire-i")
2282 cout <<
"Unknown modelid: 0x" << hex << model << endl;
2287 BIASDOUT(D_DCAM,
"Vendor: NET Gmbh");
2335 BIASERR(
"VideoSource_DCAM::UserSizeToMode(): width of "<<
Width_
2341 BIASERR(
"VideoSource_DCAM::UserSizeToMode(): height of "<<
Height_
2347 DcamMode_ = DC1394_VIDEO_MODE_FORMAT7_0;
2359 BIASDOUT(D_DCAM_F7,
"Using format7 Mode 1 (Binning): "<<
Width_<<
"x"<<
Height_
2361 DcamMode_ = DC1394_VIDEO_MODE_FORMAT7_1;
2372 dc1394color_coding_t colorCoding;
2373 dc1394color_filter_t colorFilter;
2376 dc1394_get_color_coding_from_video_mode(
camera, videoMode, &colorCoding);
2381 dc1394error_t res = dc1394_format7_get_color_filter(
camera, videoMode, &colorFilter);
2382 if (res != DC1394_SUCCESS) {
2386 BIASWARN(
"Camera did not report a valid color filter, assuming RGGB");
2387 colorFilter = DC1394_COLOR_FILTER_RGGB;
2393 switch (colorCoding)
2395 case DC1394_COLOR_CODING_MONO8:
2400 case DC1394_COLOR_CODING_YUV411:
2405 case DC1394_COLOR_CODING_YUV422:
2410 case DC1394_COLOR_CODING_YUV444:
2415 case DC1394_COLOR_CODING_RGB8:
2420 case DC1394_COLOR_CODING_RGB16:
2426 case DC1394_COLOR_CODING_MONO16:
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)
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)
2472 case DC1394_VIDEO_MODE_160x120_YUV444:
2473 s =
"160 x 120, YUV444";
2475 case DC1394_VIDEO_MODE_320x240_YUV422:
2476 s =
"320 x 240, YUV422";
2478 case DC1394_VIDEO_MODE_640x480_YUV411:
2479 s =
"640 x 480, YUV411";
2481 case DC1394_VIDEO_MODE_640x480_YUV422:
2482 s =
"640 x 480, YUV422";
2484 case DC1394_VIDEO_MODE_640x480_RGB8:
2485 s =
"640 x 480, RGB";
2487 case DC1394_VIDEO_MODE_640x480_MONO8:
2488 s =
"640 x 480, Mono8";
2490 case DC1394_VIDEO_MODE_640x480_MONO16:
2491 s =
"640 x 480, Mono16";
2493 case DC1394_VIDEO_MODE_800x600_YUV422:
2494 s =
"800 x 600, YUV422";
2496 case DC1394_VIDEO_MODE_800x600_RGB8:
2497 s =
"800 x 600, RGB";
2499 case DC1394_VIDEO_MODE_800x600_MONO8:
2500 s =
"800 x 600, Mono8";
2502 case DC1394_VIDEO_MODE_800x600_MONO16:
2503 s =
"800 x 600, Mono16";
2505 case DC1394_VIDEO_MODE_1024x768_YUV422:
2506 s =
"1024 x 768, YUV442";
2508 case DC1394_VIDEO_MODE_1024x768_RGB8:
2509 s =
"1024 x 768, RGB";
2511 case DC1394_VIDEO_MODE_1024x768_MONO8:
2512 s =
"1024 x 768, Mono8";
2514 case DC1394_VIDEO_MODE_1024x768_MONO16:
2515 s =
"1024 x 768, Mono16";
2517 case DC1394_VIDEO_MODE_1280x960_YUV422:
2518 s =
"1280 x 960, YUV422";
2520 case DC1394_VIDEO_MODE_1280x960_RGB8:
2521 s =
"1280 x 960, RGB";
2523 case DC1394_VIDEO_MODE_1280x960_MONO8:
2524 s =
"1280 x 960, Mono8";
2526 case DC1394_VIDEO_MODE_1280x960_MONO16:
2527 s =
"1280 x 960, Mono16";
2529 case DC1394_VIDEO_MODE_1600x1200_YUV422:
2530 s =
"1600 x 1200, YUV422";
2532 case DC1394_VIDEO_MODE_1600x1200_RGB8:
2533 s =
"1600 x 1200, RGB";
2535 case DC1394_VIDEO_MODE_1600x1200_MONO8:
2536 s =
"1600 x 1200, Mono8";
2538 case DC1394_VIDEO_MODE_1600x1200_MONO16:
2539 s =
"1600 x 1200, Mono16";
2541 case DC1394_VIDEO_MODE_FORMAT7_0:
2544 case DC1394_VIDEO_MODE_FORMAT7_1:
2547 case DC1394_VIDEO_MODE_FORMAT7_2:
2550 case DC1394_VIDEO_MODE_FORMAT7_3:
2553 case DC1394_VIDEO_MODE_FORMAT7_4:
2556 case DC1394_VIDEO_MODE_FORMAT7_5:
2559 case DC1394_VIDEO_MODE_FORMAT7_6:
2562 case DC1394_VIDEO_MODE_FORMAT7_7:
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.
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.
unsigned char OpticalFilter
std::vector< std::vector< float > > framerates
std::vector< unsigned int > f7_unitWidth
int GrabSingle(BIAS::Camera< unsigned char > &image)
Select the port (bus-id) to use, only valid before OpenDevice()
static int InstancesTotal_
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
unsigned int WhiteBalance
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
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.
Stores camera information such as model, vendor, framerates.
Bayer_RGGB, 1 channel RGB image Bayer tile.
bool OpticalFilterChanged
void ActivateScorpionTimestamp()
Activates the timestamp for PointGrey Scorpion SCOR-20SO.
BIAS::ImageBase::EColorModel ColorMode_
Color mode used by camera.
void SetAutoBrightness(bool b)
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]
~VideoSource_DCAM()
Destructor.
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
std::vector< unsigned int > f7_bestBpP
int QueryCam()
querys the cam for available modes, framerates and features
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.
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.
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.
float FramesPerSecond_
Capturing framerate.
color values, 3 channels, order: red,green,blue
int SetWhiteBalance(float rvalue, float bvalue)
sets the white balance of the camera, rvalue and bvalue are in range -0.5 to 0.5
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.
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 SetFirewireB(bool on)
void InvalidateUID()
sets the image's uid to invalid
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
void SetUID(const BIAS::UUID &id)
void SetCam_ID(int manualcamid_)
set'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.
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
bool AutoWhiteBalanceChanged
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 'sec')
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...
static UUID GenerateUUID(const bool &consecutively=DEFAULT_UUID_CONSECUTIVELY)
static function which simply produces a uuid and returns
dc1394video_modes_t CameraModes_
float GetShutter()
get the value of the shutter feature