136 va_start(ap, nNumberUIDs);
138 for(
int u = 0 ; u < nNumberUIDs ; u++)
140 const char* pch = va_arg(ap,
const char*);
189 if (nFormat7Width == -1 || nFormat7Height == -1)
229 va_start(ap, nNumberUIDs);
231 for(
int u = 0 ; u < nNumberUIDs ; u++)
233 const char* pch = va_arg(ap,
const char*);
253 if (nFormat7Width == -1 || nFormat7Height == -1)
349 printf(
"error: selected camera mode not supported\n");
365 bool bOpened =
false;
372 printf(
"error: camera with UID 0x%s already opened\n",
m_sCameraUID[
c].c_str());
386 printf(
"error: could not find camera with UID 0x%s\n",
m_sCameraUID[
c].c_str());
392 int nNumberCameras = 0;
411 if(nNumberCameras == 0)
413 printf(
"error: no camera found\n");
422 printf(
"error: could not open requested number of cameras\n");
435 if (dc1394_video_set_iso_speed(
m_cameras[nCamera], DC1394_ISO_SPEED_400) != DC1394_SUCCESS)
437 printf(
"error: unable to set ISO speed to 400\n");
444 printf(
"error: unable to set video mode\n");
466 unsigned int nPacketSize = 0;
474 unsigned int nMinBytes, nMaxBytes;
479 int denominator = num_packets * 8;
480 nPacketSize = (
unsigned int) ( ( frame_size + denominator - 1) / float(denominator) / 10.0);
481 nPacketSize = nMinBytes * ( nPacketSize / nMinBytes);
483 if (nPacketSize < nMinBytes)
484 nPacketSize = nMinBytes;
486 if (nPacketSize > nMaxBytes)
487 nPacketSize = nMaxBytes;
492 printf(
"error: unable to set format7 packet size %d (framerate %f)\n", nPacketSize,
m_fFormat7FrameRate);
501 printf(
"error: could not set framerate\n");
508 unsigned int nBandwidth;
509 if(dc1394_video_get_bandwidth_usage(
m_cameras[nCamera],&nBandwidth) != DC1394_SUCCESS)
511 printf(
"error: unable to calculate bandwidth usage\n");
518 printf(
"Camera %d bandwidth usage: %d quadlets/cycle (%d quadlets/cycle left)\n",nCamera, nBandwidth,
m_nRemainingBandwidth);
522 printf(
"warning: Opening camera %d would exceed maximum firewire bandwidth (%d quadlets/cycle).\n", nCamera,
MAX_S400_BANDWIDTH);
531 bool bSuccess =
false;
534 while(!bSuccess && (nTries > 0))
536 if( dc1394_capture_setup(
m_cameras[nCamera],
NUM_BUFFERS, DC1394_CAPTURE_FLAGS_DEFAULT) == DC1394_SUCCESS)
545 printf(
"error: unable to setup camera (mode supported by camera?)\n");
551 if(dc1394_video_set_transmission(
m_cameras[nCamera], DC1394_ON) != DC1394_SUCCESS)
553 printf(
"error: unable to start camera iso transmission\n");
568 if(dc1394_video_set_transmission(
m_cameras[i], DC1394_OFF) != DC1394_SUCCESS)
569 printf(
"Error: could not stop iso transmission\n");
572 if(dc1394_capture_stop(
m_cameras[i]) != DC1394_SUCCESS)
573 printf(
"Error: could not stop capturing\n");
742 unsigned char* output = pOutput->
pixels;
745 for(
int i = 0 ; i <
height ; i++)
747 for(
int j = 0 ; j < width / 4 ; j++)
777 r = int(y + 1.370705 * v);
778 g = int(y - 0.698001 * v - 0.337633 * u);
779 b = int(y + 1.732446 * u);
785 if (r > 255) r = 255;
786 if (g > 255) g = 255;
787 if (b > 255) b = 255;
789 output[0] = (
unsigned char) r;
790 output[1] = (
unsigned char) g;
791 output[2] = (
unsigned char) b;
809 dc1394video_frame_t* pCurrentFrame = NULL;
811 while(pCurrentFrame == NULL)
813 if(dc1394_capture_dequeue(
m_cameras[nCurrentIndex], DC1394_CAPTURE_POLICY_POLL, &pCurrentFrame) != DC1394_SUCCESS)
815 printf(
"Error: could not capture current frame on camera %d\n",nCurrentIndex);
838 if(dc1394_capture_enqueue(
m_cameras[nCurrentIndex], pCurrentFrame) != DC1394_SUCCESS)
840 printf(
"Error: could not release current frame of camera %d\n", nCurrentIndex);
860 dc1394video_frame_t* pCurrentFrame = NULL;
862 while(pCurrentFrame == NULL)
864 if(dc1394_capture_dequeue(
m_cameras[nCurrentIndex], DC1394_CAPTURE_POLICY_POLL, &pCurrentFrame) != DC1394_SUCCESS)
866 printf(
"Error: could not capture current frame on camera %d\n",nCurrentIndex);
887 if(dc1394_capture_enqueue(
m_cameras[nCurrentIndex], pCurrentFrame) != DC1394_SUCCESS)
889 printf(
"Error: could not release current frame of camera %d\n",nCurrentIndex);
928 SetFeature(DC1394_FEATURE_GAIN,
"gain", nValue);
933 SetFeature(DC1394_FEATURE_EXPOSURE,
"exposure", nValue);
938 SetFeature(DC1394_FEATURE_SHUTTER,
"shutter", nValue);
948 dc1394_feature_whitebalance_set_value(
m_cameras[nCurrentCamera], nU, nV);
952 dc1394_feature_whitebalance_set_value(
m_cameras[nCurrentCamera], nU, nV);
961 dc1394_feature_temperature_set_value(
m_cameras[nCurrentCamera], nTemperature);
969 printf(
"== Camera %d =========================================================================\n", i);
971 dc1394featureset_t feature_set;
973 dc1394_feature_get_all(
m_cameras[nCurrentCamera], &feature_set);
974 dc1394_feature_print_all(&feature_set,stdout);
980 dc1394bool_t bPresent;
985 dc1394_feature_is_present(
m_cameras[nCurrentCamera],feature, &bPresent);
989 printf(
"warning: camera %d does not support %s feature\n", nCurrentCamera, sName.c_str());
995 dc1394_feature_get_boundaries(
m_cameras[nCurrentCamera],feature, &nMin, &nMax);
997 if( (nValue != -1) && ((nValue < nMin) || (nValue > nMax)) )
999 printf(
"warning: requested %s %d for camera %d is not in the valid range [%d;%d]\n", sName.c_str(), nValue, nCurrentCamera, nMin, nMax);
1003 dc1394feature_modes_t availableModes;
1004 dc1394_feature_get_modes(
m_cameras[nCurrentCamera],feature, &availableModes);
1006 bool bHasAuto =
false;
1007 bool bHasManual =
false;
1009 for(
int i = 0 ; i < availableModes.num ; i++)
1011 if(availableModes.modes[i] == DC1394_FEATURE_MODE_AUTO)
1013 if(availableModes.modes[i] == DC1394_FEATURE_MODE_MANUAL)
1021 printf(
"warning: camera %d has no auto %s feature\n", nCurrentCamera, sName.c_str());
1024 dc1394_feature_set_mode(
m_cameras[nCurrentCamera], feature, DC1394_FEATURE_MODE_AUTO);
1030 printf(
"warning: camera %d has no manual %s feature\n", nCurrentCamera, sName.c_str());
1033 dc1394_feature_set_mode(
m_cameras[nCurrentCamera], feature, DC1394_FEATURE_MODE_MANUAL);
1034 dc1394_feature_set_value(
m_cameras[nCurrentCamera], feature, nValue);
1043 case e60fps:
return DC1394_FRAMERATE_60;
1044 case e30fps:
return DC1394_FRAMERATE_30;
1045 case e15fps:
return DC1394_FRAMERATE_15;
1046 case e7_5fps:
return DC1394_FRAMERATE_7_5;
1047 case e3_75fps:
return DC1394_FRAMERATE_3_75;
1048 case e1_875fps:
return DC1394_FRAMERATE_1_875;
1050 default:
return DC1394_FRAMERATE_30;
1056 dc1394camera_list_t * list;
1057 dc1394camera_t *camera;
1060 bool bFinished =
false;
1065 err=dc1394_camera_enumerate (
m_pDC1394, &list);
1068 if (nIndex >= list->num)
1073 camera = dc1394_camera_new (
m_pDC1394, list->ids[nIndex].guid);
1080 dc1394_camera_free_list (list);
1082 dc1394_reset_bus (camera);
1084 dc1394_camera_free (camera);
1099 dc1394camera_list_t* camera_list;
1101 if(dc1394_camera_enumerate(
m_pDC1394, &camera_list) != DC1394_SUCCESS)
1103 printf(
"error: cannot enumerate cameras\n");
1107 int nNumberCams = camera_list->num;
1109 for(
int i = 0 ; i < nNumberCams ; i++)
1111 printf(
"= camera %d ========================================= :\n",i);
1116 if(dc1394_camera_print_info(
m_cameras[i], stdout) != DC1394_SUCCESS)
1118 printf(
"error: could not retrieve info for camera %d\n",i);
1121 dc1394_camera_free_list(camera_list);
1128 dc1394_camera_free_list(camera_list);
1135 printf(
"error: found more cameras than MAX_CAMERAS\n");
1141 printf(
"= Found %d cameras ==================================\n",nNumberCams);
1148 int nLow = (int) uid;
1149 int nHigh = (int) (uid >> 32);
1151 sprintf(szUID,
"%08X%08X%c",nHigh,nLow,
'\0');
void ConvertYUV411(CByteImage *pInput, CByteImage *pOutput)
CByteImage * m_pTempImageHeader
BayerPatternType
The four possible variants for Bayer pattern conversion.
void SetWhiteBalance(int nU, int nV, int nCamera=-1)
CByteImage::ImageType GetType()
void SetCameraUids(std::vector< std::string > uids)
dc1394framerate_t GetDCFrameRateMode(FrameRate frameRate)
static dc1394_t * m_pDC1394
int width
The width of the image in pixels.
void SetExposure(int nValue)
static int m_nRemainingBandwidth
void SetFeature(dc1394feature_t feature, std::string sName, int nValue)
bool ConvertBayerPattern(const CByteImage *pInputImage, CByteImage *pOutputImage, BayerPatternType type)
Converts an 8 bit Bayer pattern CByteImage to an RGB24 color CByteImage.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
void SetTemperature(int nTemperature)
unsigned char * pixels
The pointer to the the pixels.
bool CaptureBayerPatternImage(CByteImage **ppImages)
static int m_nCameraBandwidth[MAX_CAMERAS]
float m_fFormat7FrameRate
void SetShutter(int nValue)
bool CaptureImage(CByteImage **ppImages)
bool CopyImage(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0, bool bUseSameSize=false)
Copies one CByteImage to another.
std::string CamUIDToString(uint64_t uid)
GLsizei const GLchar ** string
CLinux1394Capture2(int nCameras, VideoMode mode, ColorMode colorMode, ImageProcessor::BayerPatternType bayerPatternType=ImageProcessor::eBayerRG, FrameRate frameRate=e30fps)
int m_nOpenedCameras[MAX_CAMERAS]
std::string m_sCameraUID[MAX_CAMERAS]
GLubyte GLubyte GLubyte a
int height
The height of the image in pixels.
void YUVToRGB(int y, int u, int v, unsigned char *output)
const ColorMode m_colorMode
int bytesPerPixel
The number of bytes used for encoding one pixel.
GLenum GLsizei GLsizei height
ImageType
Enum specifying the supported image types.
static dc1394camera_t * m_cameras[MAX_CAMERAS]
GLenum GLenum GLenum input
ImageType type
The type of the image.
GLdouble GLdouble GLdouble r
const ImageProcessor::BayerPatternType m_bayerPatternType
GLuint GLenum GLenum transform
void SleepThread(int nMS)
static CLinux1394Capture2 * m_pCameraOpener[MAX_CAMERAS]
#define MAX_S400_BANDWIDTH
bool Resize(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0, bool bInterpolation=true)
Resizes a CByteImage and writes the result to a CByteImage.
static int m_nOverallCameras
dc1394video_mode_t m_video_mode