18 #include "../include/cob_camera_sensors/StdAfx.h" 25 #include "cob_vision/windows/src/extern/TinyXml/tinyxml.h" 28 #include <opencv/highgui.h> 31 namespace fs = boost::filesystem;
89 std::cerr <<
"ERROR - VirtualColorCam::Open:" << std::endl;
90 std::cerr <<
"\t ... Camera not initialized." << std::endl;
101 std::stringstream ss;
102 std::string sCameraIndex;
111 if ( !fs::exists( absoluteDirectoryName ) )
113 std::cerr <<
"ERROR - VirtualColorCam::Open:" << std::endl;
114 std::cerr <<
"\t ... Path '" << absoluteDirectoryName.file_string() <<
"' not found" << std::endl;
118 int colorImageCounter = 0;
120 if ( fs::is_directory( absoluteDirectoryName ) )
122 std::cout <<
"INFO - VirtualColorCam::Open:" << std::endl;
123 std::cout <<
"\t ... Parsing directory '" << absoluteDirectoryName.directory_string() <<
"'" << std::endl;;
124 fs::directory_iterator end_iter;
125 for ( fs::directory_iterator dir_itr( absoluteDirectoryName ); dir_itr != end_iter; ++dir_itr )
129 if (fs::is_regular_file(dir_itr->status()))
131 std::string filename = dir_itr->path().string();
132 if ((dir_itr->path().extension() ==
".jpg" || dir_itr->path().extension() ==
".jpe" ||
133 dir_itr->path().extension() ==
".jpeg" || dir_itr->path().extension() ==
".bmp" ||
134 dir_itr->path().extension() ==
".bmp" || dir_itr->path().extension() ==
".dib" ||
135 dir_itr->path().extension() ==
".png" || dir_itr->path().extension() ==
".pgm" ||
136 dir_itr->path().extension() ==
".ppm" || dir_itr->path().extension() ==
".sr" ||
137 dir_itr->path().extension() ==
".ras" || dir_itr->path().extension() ==
".tiff" ||
138 dir_itr->path().extension() ==
".exr" || dir_itr->path().extension() ==
".jp2") &&
139 filename.find(
"ColorCamRGB_8U3_" + sCameraIndex, 0 ) != std::string::npos)
154 catch (
const std::exception &ex )
156 std::cerr <<
"ERROR - VirtualColorCam::Open:" << std::endl;
157 std::cerr <<
"\t ... Exception catch of '" << ex.what() <<
"'" << std::endl;
161 std::cout <<
"INFO - VirtualColorCam::Open:" << std::endl;
162 std::cerr <<
"\t ... Extracted '" << colorImageCounter <<
"' color images (8*3 bit/color)\n";
166 std::cerr <<
"ERROR - VirtualColorCam::Open:" << std::endl;
167 std::cerr <<
"\t .... Path '" << absoluteDirectoryName.file_string() <<
"' is not a directory." << std::endl;
171 if (colorImageCounter == 0)
173 std::cerr <<
"ERROR - VirtualColorCam::Open:" << std::endl;
174 std::cerr <<
"\t ... Could not detect any color images" << std::endl;
175 std::cerr <<
"\t ... from the specified directory. Check directory" << std::endl;
176 std::cerr <<
"\t ... and filenames (i.e. ColorCamRGB_8U3_*_*.jpg)." << std::endl;
180 std::cout <<
"*******************************************************" << std::endl;
181 std::cout <<
"VirtualColorCam::Open: Virtual color camera device OPEN" << std::endl;
182 std::cout <<
"*******************************************************" << std::endl << std::endl;
221 std::cerr <<
"VirtualColorCam::SetProperty: Function not implemented.";
233 std::cerr <<
"ERROR - VirtualColorCam::SetProperty:" << std::endl;
234 std::cerr <<
"\t ... Property " << cameraProperty->
propertyID <<
" unspecified.";
262 std::cerr <<
"ERROR - VirtualColorCam::SetProperty:" << std::endl;
263 std::cerr <<
"\t ... Property " << cameraProperty->
propertyID <<
" unspecified.";
277 std::cerr <<
"ERROR - VirtualColorCam::GetColorImage:" << std::endl;
278 std::cerr <<
"\t ... Color camera not open." << std::endl;
288 char* f_color_ptr = &((
char*) (colorImage->imageData + row*colorImage->widthStep))[col*3];
289 ((
char*) (colorImageData + row*colorImage->widthStep))[col*3 + 0] = f_color_ptr[0];
290 ((
char*) (colorImageData + row*colorImage->widthStep))[col*3 + 1] = f_color_ptr[1];
291 ((
char*) (colorImageData + row*colorImage->widthStep))[col*3 + 2] = f_color_ptr[2];
295 cvReleaseImage(&colorImage);
312 std::cerr <<
"ERROR - VirtualColorCam::GetColorImage:" << std::endl;
313 std::cerr <<
"\t ... Color camera not open." << std::endl;
317 CV_Assert(colorImage != 0);
321 return GetColorImage((
char*)(colorImage->ptr<
unsigned char>(0)), getLatestFrame);
345 if (!p_configXmlDocument->LoadFile())
347 std::cerr <<
"ERROR - VirtualColorCam::LoadParameters:" << std::endl;
348 std::cerr <<
"\t ... Error while loading xml configuration file (Check filename and syntax of the file):\n" << filename << std::endl;
351 std::cout <<
"INFO - VirtualColorCam::LoadParameters:" << std::endl;
352 std::cout <<
"\t ... Parsing xml configuration file:" << std::endl;
353 std::cout <<
"\t ... '" << filename <<
"'" << std::endl;
355 if ( p_configXmlDocument )
362 TiXmlElement *p_xmlElement_Root = NULL;
363 p_xmlElement_Root = p_configXmlDocument->FirstChildElement(
"LibCameraSensors" );
364 if ( p_xmlElement_Root )
371 TiXmlElement *p_xmlElement_Root_VirtualColorCam = NULL;
372 std::stringstream ss;
373 ss <<
"VirtualColorCam_" << cameraIndex;
374 p_xmlElement_Root_VirtualColorCam = p_xmlElement_Root->FirstChildElement( ss.str() );
375 if ( p_xmlElement_Root_VirtualColorCam )
382 TiXmlElement *p_xmlElement_Child = NULL;
383 p_xmlElement_Child = p_xmlElement_Root_VirtualColorCam->FirstChildElement(
"CameraDataDirectory" );
384 if ( p_xmlElement_Child )
387 std::string tempString;
388 if ( p_xmlElement_Child->QueryValueAttribute(
"relativePath", &tempString ) != TIXML_SUCCESS)
390 std::cerr <<
"VirtualColorCam::LoadParameters: Can't find attribute 'relativePath' of tag 'CameraDataDirectory'." << std::endl;
398 std::cerr <<
"ERROR - VirtualColorCam::LoadParameters:" << std::endl;
399 std::cerr <<
"\t ... Can't find tag 'CameraDataDirectory'." << std::endl;
408 std::cerr <<
"ERROR - VirtualColorCam::LoadParameters:" << std::endl;
409 std::cerr <<
"\t ... Can't find tag '" << ss.str() <<
"'" << std::endl;
419 std::cerr <<
"ERROR - VirtualColorCam::LoadParameters:" << std::endl;
420 std::cerr <<
"\t ... Can't find tag 'LibCameraSensors'." << std::endl;
425 std::cout <<
"\t [OK] Parsing xml configuration file " << std::endl;
int m_CameraIndex
Index of the specified camera. Important, when several cameras of the same type are present...
unsigned long TestCamera(const char *filename)
unsigned long PrintCameraInformation()
t_cameraResolution cameraResolution
boost::shared_ptr< AbstractColorCamera > AbstractColorCameraPtr
virtual unsigned long TestCamera(const char *filename)
RET_FUNCTION_NOT_IMPLEMENTED
unsigned long SetProperty(t_cameraProperty *cameraProperty)
unsigned long LoadParameters(const char *filename, int cameraIndex)
unsigned long GetProperty(t_cameraProperty *cameraProperty)
unsigned long Init(std::string directory, int cameraIndex=0)
bool m_initialized
True, when the camera has sucessfully been initialized.
__DLL_LIBCAMERASENSORS__ AbstractColorCameraPtr CreateColorCamera_VirtualCam()
RET_CAMERA_ALREADY_INITIALIZED
virtual bool isInitialized()
unsigned long SetPathToImages(std::string path)
unsigned long GetColorImage(char *colorImageData, bool getLatestFrame)
std::vector< std::string > m_ColorImageFileNames
unsigned int u_integerData
t_cameraPropertyID propertyID
bool m_open
True, when the camera has sucessfully been opend.
unsigned long SetPropertyDefaults()
unsigned int m_BufferSize
Number of images, the camera buffers internally.
unsigned long SaveParameters(const char *filename)
t_cameraType m_CameraType
Camera Type.
unsigned long propertyType
unsigned int m_ImageCounter
Holds the index of the image that is extracted during the next call of AcquireImages ...
#define __DLL_LIBCAMERASENSORS__
std::string m_CameraDataDirectory
Directory where the image data resides.