74 int CLinux1394Capture::m_nOverallCameras = 0;
75 CLinux1394Capture::TCameraInfo CLinux1394Capture::m_CameraInfo[
MAX_CAMERAS];
77 int CLinux1394Capture::m_nInstances = 0;
78 raw1394handle_t CLinux1394Capture::m_handles[
MAX_CAMERAS];
79 dc1394_cameracapture CLinux1394Capture::m_cameras[
MAX_CAMERAS];
80 nodeid_t* CLinux1394Capture::m_pCameraNodes[
MAX_PORTS];
99 m_nCameras = nCameras;
105 m_bFormat7Mode =
false;
107 if(m_nInstances == 0)
112 m_pCameraOpener[i] = NULL;
123 m_sCameraUID[i] =
"";
127 va_start(ap, nNumberUIDs);
129 for(
int u = 0 ; u < nNumberUIDs ; u++)
131 const char* pch = va_arg(ap,
const char*);
132 m_sCameraUID[u] += pch;
133 transform(m_sCameraUID[u].begin(), m_sCameraUID[u].end(), m_sCameraUID[u].begin(), (
int(*)(
int)) toupper);
144 m_nCameras = nNumberUIDs;
150 m_bFormat7Mode =
false;
152 if(m_nInstances == 0)
157 m_pCameraOpener[i] = NULL;
171 m_mode(mode), m_colorMode(colorMode), m_bayerPatternType(bayerPatternType)
179 m_nCameras = nCameras;
184 m_bFormat7Mode =
true;
185 m_nFormat7PacketSize = nFormat7PacketSize == -1 ? USE_MAX_AVAIL : nFormat7PacketSize;
186 m_nFormat7MinX = nFormat7MinX;
187 m_nFormat7MinY = nFormat7MinY;
188 m_nFormat7Width = nFormat7Width;
189 m_nFormat7Height = nFormat7Height;
193 if (m_nInstances == 0)
198 m_pCameraOpener[i] = NULL;
207 m_mode(mode), m_colorMode(colorMode), m_bayerPatternType(bayerPatternType)
211 m_sCameraUID[i] =
"";
215 va_start(ap, nNumberUIDs);
217 for(
int u = 0 ; u < nNumberUIDs ; u++)
219 const char* pch = va_arg(ap,
const char*);
220 m_sCameraUID[u] += pch;
221 transform(m_sCameraUID[u].begin(), m_sCameraUID[u].end(), m_sCameraUID[u].begin(), (
int(*)(
int)) toupper);
232 m_nCameras = nNumberUIDs;
237 m_bFormat7Mode =
true;
238 m_nFormat7PacketSize = nFormat7PacketSize == -1 ? USE_MAX_AVAIL : nFormat7PacketSize;
239 m_nFormat7MinX = nFormat7MinX;
240 m_nFormat7MinY = nFormat7MinY;
241 m_nFormat7Width = nFormat7Width;
242 m_nFormat7Height = nFormat7Height;
245 m_bFormat7Mode =
true;
247 if (m_nInstances == 0)
252 m_pCameraOpener[i] = NULL;
268 delete m_pTempImageHeader;
276 if(m_nInstances == 0)
279 for(
int p = 0 ; p < m_nPorts ; p++)
280 dc1394_free_camera_nodes(m_pCameraNodes[p]);
283 for(
int h = 0 ; h < m_nOverallCameras ; h++)
284 dc1394_destroy_handle(m_handles[h]);
286 m_nOverallCameras = 0;
296 if(!InitCameraMode())
298 printf(
"error: selected camera mode not supported\n");
312 for(
int c = 0 ; c < m_nCameras ; c++)
314 bool bOpened =
false;
315 for(
int a = 0 ; a < m_nOverallCameras ; a++)
317 if(m_sCameraUID[c] == m_CameraInfo[a].sUID)
319 if(m_pCameraOpener[a])
321 printf(
"error: camera with UID 0x%s already opened\n", m_sCameraUID[c].c_str());
327 m_pCameraOpener[a] =
this;
328 m_nOpenedCameras[c] = a;
335 printf(
"error: could not find camera with UID 0x%s\n",m_sCameraUID[c].c_str());
341 int nNumberCameras = 0;
342 for(
int c = 0 ; c < m_nOverallCameras ; c++)
344 if(m_pCameraOpener[c] == NULL)
349 m_pCameraOpener[c] =
this;
350 m_nOpenedCameras[nNumberCameras] = c;
354 if( (m_nCameras != -1) && (nNumberCameras == m_nCameras))
360 if(nNumberCameras == 0)
362 printf(
"error: no camera found\n");
366 m_nCameras = nNumberCameras;
369 if(nNumberCameras < m_nCameras)
371 printf(
"error: could not open requested number of cameras\n");
382 int p = m_CameraInfo[nCamera].nPort;
383 int i = m_CameraInfo[nCamera].nIndex;
385 printf(
"Opening camera %d: Port %d, Index %d, UID 0x%s, Format7 = %i\n",nCamera,p,i,m_CameraInfo[nCamera].sUID.c_str(), m_bFormat7Mode);
387 char *device_name = 0;
391 if (dc1394_dma_setup_format7_capture(m_handles[nCamera], m_cameras[nCamera].node, i + 1, MODE_FORMAT7_0, SPEED_400, m_nFormat7PacketSize, m_nFormat7MinX, m_nFormat7MinY, m_nFormat7Width, m_nFormat7Height,
NUM_BUFFERS,
DROP_FRAMES, device_name, &m_cameras[nCamera]) != DC1394_SUCCESS)
393 printf(
"error: unable to setup camera (mode supported by camera?)\n");
400 if (dc1394_dma_setup_capture(m_handles[nCamera], m_cameras[nCamera].node, i + 1, FORMAT_VGA_NONCOMPRESSED, m_video_mode, SPEED_400, GetDCFrameRateMode(m_frameRate),
NUM_BUFFERS,
DROP_FRAMES, device_name, &m_cameras[nCamera]) != DC1394_SUCCESS)
402 printf(
"error: unable to setup camera (mode supported by camera?)\n");
409 if (dc1394_start_iso_transmission(m_handles[nCamera], m_cameras[nCamera].node) != DC1394_SUCCESS)
411 printf(
"error: unable to start camera iso transmission\n");
421 for (
int i = 0; i < m_nCameras; i++)
425 if(m_pCameraOpener[i] ==
this)
427 dc1394_dma_unlisten(m_handles[i], &m_cameras[i]);
428 dc1394_dma_release_camera(m_handles[i], &m_cameras[i]);
429 m_pCameraOpener[i] = NULL;
444 bool CLinux1394Capture::InitCameraMode()
455 m_pTempImageHeader->
width = 640;
456 m_pTempImageHeader->
height = 480;
462 m_video_mode = MODE_640x480_MONO;
466 m_video_mode = MODE_640x480_RGB;
470 m_video_mode = MODE_640x480_YUV411;
482 m_video_mode = MODE_640x480_MONO;
483 m_pTempImageHeader->
width = 640;
484 m_pTempImageHeader->
height = 480;
488 m_video_mode = MODE_640x480_MONO;
490 m_pTempImageHeader->
width = 640;
491 m_pTempImageHeader->
height = 480;
495 m_video_mode = MODE_640x480_RGB;
496 m_pTempImageHeader->
width = 640;
497 m_pTempImageHeader->
height = 480;
501 m_video_mode = MODE_640x480_YUV411;
503 m_pTempImageHeader->
width = 640;
504 m_pTempImageHeader->
height = 480;
531 int width = pInput->
width;
532 int height = pInput->
height;
537 unsigned char* output = pOutput->
pixels;
538 unsigned char* input = pInput->
pixels;
540 for(
int i = 0 ; i < height ; i++)
542 for(
int j = 0 ; j < width / 4 ; j++)
552 YUVToRGB(y1,u,v,output);
553 YUVToRGB(y2,u,v,output + 3);
554 YUVToRGB(y3,u,v,output + 6);
555 YUVToRGB(y4,u,v,output + 9);
563 void CLinux1394Capture::YUVToRGB(
int y,
int u,
int v,
unsigned char* output)
572 r = int(y + 1.370705 * v);
573 g = int(y - 0.698001 * v - 0.337633 * u);
574 b = int(y + 1.732446 * u);
580 if (r > 255) r = 255;
581 if (g > 255) g = 255;
582 if (b > 255) b = 255;
584 output[0] = (
unsigned char) r;
585 output[1] = (
unsigned char) g;
586 output[2] = (
unsigned char) b;
591 if ( (width == -1) || (height == -1) )
597 for (i = 0; i < m_nCameras; i++)
599 if (!m_handles[m_nOpenedCameras[i]])
602 dc1394_dma_done_with_buffer(&m_cameras[m_nOpenedCameras[i]]);
605 for (i = 0; i < m_nCameras; i++)
607 dc1394_dma_single_capture(&m_cameras[m_nOpenedCameras[i]]);
610 for (i = 0; i < m_nCameras; i++)
612 m_pTempImageHeader->
pixels = (
unsigned char *) m_cameras[m_nOpenedCameras[i]].capture_buffer;
627 ConvertYUV411(m_pTempImageHeader, ppImages[i]);
645 ConvertYUV411(m_pTempImageHeader, m_pTempImage);
657 if ( (width == -1) || (height == -1) )
663 for (i = 0; i < m_nCameras; i++)
665 if (!m_handles[m_nOpenedCameras[i]])
668 dc1394_dma_done_with_buffer(&m_cameras[m_nOpenedCameras[i]]);
671 for (i = 0; i < m_nCameras; i++)
673 dc1394_dma_single_capture(&m_cameras[m_nOpenedCameras[i]]);
676 for (i = 0; i < m_nCameras; i++)
678 m_pTempImageHeader->
pixels = (
unsigned char *) m_cameras[m_nOpenedCameras[i]].capture_buffer;
713 for (
int i = 0; i < m_nCameras; i++)
717 dc1394_auto_on_off(m_handles[i], m_cameras[i].node, FEATURE_GAIN, 1);
721 dc1394_auto_on_off(m_handles[i], m_cameras[i].node, FEATURE_GAIN, 0);
722 dc1394_set_gain(m_handles[i], m_cameras[i].node, nValue);
729 for (
int i = 0; i < m_nCameras; i++)
733 dc1394_auto_on_off(m_handles[i], m_cameras[i].node, FEATURE_EXPOSURE, 1);
737 dc1394_auto_on_off(m_handles[i], m_cameras[i].node, FEATURE_EXPOSURE, 0);
738 dc1394_set_exposure(m_handles[i], m_cameras[i].node, nValue);
745 for (
int i = 0; i < m_nCameras; i++)
749 dc1394_auto_on_off(m_handles[i], m_cameras[i].node, FEATURE_SHUTTER, 1);
753 dc1394_auto_on_off(m_handles[i], m_cameras[i].node, FEATURE_SHUTTER, 0);
754 dc1394_set_shutter(m_handles[i], m_cameras[i].node, nValue);
759 int CLinux1394Capture::GetDCFrameRateMode(FrameRate frameRate)
763 case e60fps:
return FRAMERATE_60;
764 case e30fps:
return FRAMERATE_30;
765 case e15fps:
return FRAMERATE_15;
766 case e7_5fps:
return FRAMERATE_7_5;
767 case e3_75fps:
return FRAMERATE_3_75;
770 default:
return FRAMERATE_30;
774 bool CLinux1394Capture::ListCameras()
777 if(m_nOverallCameras != 0)
781 raw1394handle_t raw_handle = raw1394_new_handle();
784 printf(
"error: unable to aquire a raw1394 handle\n");
789 m_nPorts = raw1394_get_port_info(raw_handle, ports, m_nPorts);
790 raw1394_destroy_handle(raw_handle);
791 printf(
"number of ports = %d\n", m_nPorts);
794 for (
int p = 0; p < m_nPorts; p++)
799 raw_handle = raw1394_new_handle();
800 raw1394_set_port(raw_handle, p);
801 m_pCameraNodes[p] = dc1394_get_camera_nodes(raw_handle, &camCount, 1);
802 raw1394_destroy_handle(raw_handle);
805 for (
int i = 0; i < camCount; i++)
807 m_handles[m_nOverallCameras] = dc1394_create_handle(p);
808 if (!m_handles[m_nOverallCameras])
810 printf(
"error: unable to aquire a raw1394 handle\n");
815 m_cameras[m_nOverallCameras].node = m_pCameraNodes[p][i];
816 dc1394_feature_set features;
818 if (dc1394_get_camera_feature_set(m_handles[m_nOverallCameras], m_cameras[m_nOverallCameras].node, &features) != DC1394_SUCCESS)
820 printf(
"info: unable to get feature set\n");
827 unsigned int channel, speed;
829 if (dc1394_get_iso_channel_and_speed(m_handles[m_nOverallCameras], m_cameras[m_nOverallCameras].node, &channel, &speed) != DC1394_SUCCESS)
831 printf(
"error: unable to get the iso channel number\n");
837 dc1394_camerainfo info;
839 if (dc1394_get_camera_info(m_handles[m_nOverallCameras], m_cameras[m_nOverallCameras].node, &info) != DC1394_SUCCESS)
841 printf(
"error: unable to retrieve camera info\n");
845 m_CameraInfo[m_nOverallCameras].nPort = p;
846 m_CameraInfo[m_nOverallCameras].nIndex = i;
847 unsigned int low = info.euid_64;
848 unsigned int high = (info.euid_64 >> 32);
849 m_CameraInfo[m_nOverallCameras].sUID = CamUIDToString(low,high);
852 if(m_nOverallCameras > MAX_CAMERAS)
854 printf(
"error: found more cameras than MAX_CAMERAS\n");
865 std::string CLinux1394Capture::CamUIDToString(
unsigned int nLow,
unsigned int nHigh)
867 std::string UID =
"";
869 sprintf(szUID,
"%08X%08X\0",nHigh,nLow);
bool Resize(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0, bool bInterpolation=true)
Resizes a CByteImage and writes the result to a CByteImage.
bool CopyImage(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0, bool bUseSameSize=false)
Copies one CByteImage to another.
BayerPatternType
The four possible variants for Bayer pattern conversion.
void SetShutter(unsigned int nValue)
ImageType
Enum specifying the supported image types.
bool ConvertBayerPattern(const CByteImage *pInputImage, CByteImage *pOutputImage, BayerPatternType type)
Converts an 8 bit Bayer pattern CByteImage to an RGB24 color CByteImage.
CByteImage::ImageType GetType()
ImageType type
The type of the image.
int width
The width of the image in pixels.
int height
The height of the image in pixels.
bool CaptureBayerPatternImage(CByteImage **ppImages)
bool CaptureImage(CByteImage **ppImages)
unsigned char * pixels
The pointer to the the pixels.
void SetExposure(unsigned int nValue)
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
void SetGain(unsigned int nValue)
int bytesPerPixel
The number of bytes used for encoding one pixel.
CLinux1394Capture(int nCameras, VideoMode mode, ColorMode colorMode, ImageProcessor::BayerPatternType bayerPatternType=ImageProcessor::eBayerRG, FrameRate frameRate=e30fps)