26 #include <Base\Common\W32Compat.hh>
28 #include "ShowCamWxThreads.hh"
29 #include <Filter/Rescale.hh>
30 #include <Base/Common/FileHandling.hh>
33 #include <Base/Common/W32Compat.hh>
35 #include <VideoSource/VideoSource_DCAM_BumbleBee.hh>
37 #ifdef BIAS_HAVE_SWISSRANGER
38 #include <VideoSource/VideoSource_SwissRanger.hh>
40 #include <VideoSource/VideoSource_Kinect_Base.hh>
41 #ifdef BIAS_HAVE_PMD_PMDTec
42 #include <VideoSource/VideoSource_PMD.hh>
44 #ifdef BIAS_HAVE_PMD_PMDZess
45 #include <VideoSource/VideoSource_PMDZess.hh>
48 #include <VideoSource/VideoSource_uEye.hh>
50 #ifdef BIAS_HAVE_DSHOW
51 #include <VideoSource/VideoSource_DSHOW.hh>
53 #ifdef BIAS_HAVE_KINECT2
54 #include <VideoSource/VideoSource_Kinect2.hh>
57 #include <VideoSource/VideoSource_V4L.hh>
64 #define BUFFER_CAPACITY_MIN 0.8
65 #define BUFFER_GRAB_SLEEP 500
66 #define BUFFER_SAVE_SLEEP 2500
73 const int& downsample,
74 wxMutex* BufferAccessMutex,
76 unsigned int& readIndex,
77 unsigned int& writeIndex,
91 : wxThread(wxTHREAD_DETACHED)
94 cameraName_ = cameraName;
95 DownSample_ = downsample;
96 BufferAccess_ = BufferAccessMutex;
99 WriteToBuffer_= &writeToBuffer;
102 ReadIndex_ = &readIndex;
103 WriteIndex_ = &writeIndex;
106 ImgCenter_ = imgCenter;
107 ImgRight_ = imgRight;
108 ImgDepth_ = imgDepth;
112 ImageBuffer_ = imageBuffer;
113 ImageBufferCenter_ = imageBufferCenter;
114 ImageBufferRight_ = imageBufferRight;
116 ImageBufferPMDDepth_ = imageBufferPmdDepth;
117 ImageBufferPMDAmp_ = imageBufferPmdAmp;
118 ImageBufferPMDInt_ = imageBufferPmdInt;
122 stream_ = saveToStream;
124 for (
unsigned int i=0;i<10;i++) {
126 bStreamOpen_.push_back(
false);
138 while(!TestDestroy()){
141 BufferAccess_->Lock();
143 if((*WriteIndex_ != ((*ReadIndex_ + 1) % ImageBuffer_->size()))){
145 *ReadIndex_ = (*ReadIndex_ + 1) % ImageBuffer_->size();
147 BufferAccess_->Unlock();
149 if((*ImageBuffer_)[*ReadIndex_] != NULL)
150 SaveImage_((*ImageBuffer_)[*ReadIndex_],
"");
151 if((*ImageBufferCenter_)[*ReadIndex_] != NULL)
152 SaveImage_((*ImageBufferCenter_)[*ReadIndex_],
"Center");
153 if((*ImageBufferRight_)[*ReadIndex_] != NULL)
154 SaveImage_((*ImageBufferRight_)[*ReadIndex_],
"Right");
155 if((*ImageBufferPMDDepth_)[*ReadIndex_] != NULL)
156 SaveImage_((*ImageBufferPMDDepth_)[*ReadIndex_],
"Depth");
157 if((*ImageBufferPMDAmp_)[*ReadIndex_] != NULL)
158 SaveImage_((*ImageBufferPMDAmp_)[*ReadIndex_],
"Amp");
159 if((*ImageBufferPMDInt_)[*ReadIndex_] != NULL)
160 SaveImage_((*ImageBufferPMDInt_)[*ReadIndex_],
"Int");
167 BufferAccess_->Unlock();
169 usleep(BUFFER_SAVE_SLEEP);
171 Sleep(BUFFER_SAVE_SLEEP/1000);
178 if(ImgCenter_ != NULL)
179 SaveImage_(ImgCenter_,
"Center");
180 if(ImgRight_ != NULL)
181 SaveImage_(ImgRight_,
"Right");
182 if(ImgDepth_ != NULL)
183 SaveImage_(ImgDepth_,
"Depth");
185 SaveImage_(ImgAmp_,
"Amp");
187 SaveImage_(ImgInt_,
"Int");
201 BufferAccess_->Lock();
203 while((*WriteIndex_ != ((*ReadIndex_ + 1) % ImageBuffer_->size()))){
204 cout<<
"finishing:"<<endl<<flush;
205 *ReadIndex_ = (*ReadIndex_ + 1) % ImageBuffer_->size();
207 if((*ImageBuffer_)[*ReadIndex_] != NULL)
208 SaveImage_((*ImageBuffer_)[*ReadIndex_],
"");
209 if((*ImageBufferCenter_)[*ReadIndex_] != NULL)
210 SaveImage_((*ImageBufferCenter_)[*ReadIndex_],
"Center");
211 if((*ImageBufferRight_)[*ReadIndex_] != NULL)
212 SaveImage_((*ImageBufferRight_)[*ReadIndex_],
"Right");
213 if((*ImageBufferPMDDepth_)[*ReadIndex_] != NULL)
214 SaveImage_((*ImageBufferPMDDepth_)[*ReadIndex_],
"Depth");
215 if((*ImageBufferPMDAmp_)[*ReadIndex_] != NULL)
216 SaveImage_((*ImageBufferPMDAmp_)[*ReadIndex_],
"Amp");
217 if((*ImageBufferPMDInt_)[*ReadIndex_] != NULL)
218 SaveImage_((*ImageBufferPMDAmp_)[*ReadIndex_],
"Int");
223 BufferAccess_->Unlock();
225 for (
unsigned int i=0; i<10;i++) {
226 if (bStreamOpen_[i]) {
227 bStreamOpen_[i]=
false;
238 void ImageSaveThread::
242 string FilenameOut = cameraName_ + name + text.str();
246 idx = mapNameToStreamIdx_(name);
248 if (!bStreamOpen_[idx]) {
249 string fname = saveDirectory_ + cameraName_ + name;
250 ips_[idx]->Create(fname);
251 bStreamOpen_[idx] =
true;
255 if(DownSample_ != 0){
259 (
int)(im->
GetWidth() / DownSample_),
264 if (ips_[idx]->AddImage(rescaledImage, FilenameOut)!=0) {
265 BIASERR(
"Failed saving image to stream");
278 if (ips_[idx]->AddImage(*im, FilenameOut)!=0) {
279 BIASERR(
"Failed saving image to stream");
294 void ImageSaveThread::
298 string FilenameOut = cameraName_ + name + text.str();
301 idx = mapNameToStreamIdx_(name);
303 if (!bStreamOpen_[idx]) {
304 string fname = saveDirectory_ + cameraName_ + name;
305 ips_[idx]->Create(fname);
306 bStreamOpen_[idx] =
true;
310 if(DownSample_ != 0){
314 (
int)(imF->
GetWidth() / DownSample_),
319 if (ips_[idx]->AddImage(rescaledImage, FilenameOut)!=0) {
320 BIASERR(
"Failed saving image to stream");
333 if (ips_[idx]->AddImage(*imF, FilenameOut)!=0) {
334 BIASERR(
"Failed saving image to stream");
346 int ImageSaveThread::mapNameToStreamIdx_(
string name) {
347 if (name.length() == 0)
349 if (name.find(
"Center")!=string::npos)
351 if (name.find(
"Right")!=string::npos)
353 if (name.find(
"Amp")!=string::npos)
355 if (name.find(
"Depth")!=string::npos)
357 if (name.find(
"Int")!=string::npos)
367 wxCondition *ClientCondition,
368 wxCondition *ServerCondition,
369 wxMutex *mutexClientCondition,
370 wxMutex *mutexServerCondition,
371 unsigned int threadNumber,
372 wxMutex *BufferAccessMutex,
374 unsigned int& readIndex,
375 unsigned int& writeIndex,
392 :wxThread(wxTHREAD_DETACHED)
396 ImgCenter_ = imgCenter;
397 ImgRight_ = imgRight;
398 ImgDepth_ = imgDepth;
402 threadNumber_ = threadNumber;
405 mutexClientCondition_= mutexClientCondition;
406 mutexServerCondition_= mutexServerCondition;
409 ClientCondition_ = ClientCondition;
410 ServerCondition_ = ServerCondition;
413 BufferAccess_ = BufferAccessMutex;
416 ImageBuffer_ = imageBuffer;
417 ImageBufferCenter_ = imageBufferCenter;
418 ImageBufferRight_ = imageBufferRight;
419 ImageBufferPMDDepth_ = imageBufferPMDDepth;
420 ImageBufferPMDAmp_ = imageBufferPMDAmp;
421 ImageBufferPMDInt_ = imageBufferPMDInt;
424 WriteToBuffer_ = &writeToBuffer;
426 ReadIndex_ = &readIndex;
427 WriteIndex_ = &writeIndex;
429 BufferSize_ = ImageBuffer_->size();
444 #ifdef BIAS_HAVE_DCAM
450 #ifdef BIAS_HAVE_SWISSRANGER
454 #ifdef BIAS_HAVE_UEYE
458 #ifdef BIAS_HAVE_PMD_PMDTec
462 #ifdef BIAS_HAVE_PMD_PMDZess
471 #ifdef BIAS_HAVE_DSHOW
478 #ifdef BIAS_HAVE_DCAM
489 #ifdef BIAS_HAVE_SWISSRANGER
494 #ifdef BIAS_HAVE_UEYE
499 #ifdef BIAS_HAVE_PMD_PMDTec
505 #ifdef BIAS_HAVE_PMD_PMDZess
507 if(usbpmdcam !=NULL){
511 #ifdef BIAS_HAVE_DSHOW
512 if (webcam != NULL) {
517 if (webcam != NULL) {
521 #ifdef BIAS_HAVE_KINECT
522 if (kinect != NULL) {
527 #ifdef BIAS_HAVE_OPENNI
528 if (kinect != NULL) {
533 #ifdef BIAS_HAVE_KINECT2
536 if (kinect2 != NULL) {
542 mutexClientCondition_->Lock();
544 while(!TestDestroy()){
548 double bufferPercent = 0.0;
549 if(*WriteIndex_ >= *ReadIndex_){
550 bufferPercent = (double)((*WriteIndex_ + 1) -
551 (*ReadIndex_ + 1) ) / (double)BufferSize_;
553 bufferPercent = (double)(((*WriteIndex_ + 1)+BufferSize_)-
554 (*ReadIndex_ + 1)) / (
double)BufferSize_;
557 while(*WriteToBuffer_ && bufferPercent > BUFFER_CAPACITY_MIN){
559 if(*WriteIndex_ >= *ReadIndex_){
560 bufferPercent = (double)((*WriteIndex_ + 1) -
561 (*ReadIndex_ + 1) ) / (double)BufferSize_;
563 bufferPercent = (double)(((*WriteIndex_ + 1)+BufferSize_)-
564 (*ReadIndex_ + 1)) / (
double)BufferSize_;
568 usleep(BUFFER_GRAB_SLEEP);
570 Sleep(BUFFER_GRAB_SLEEP/1000);
576 gettimeofday(&t1,NULL);
579 #ifdef BIAS_HAVE_DCAM
586 xb3cam->
GrabSingle(*AllImages_,*Img_,*ImgCenter_,*ImgRight_);
589 #ifdef BIAS_HAVE_SWISSRANGER
600 #ifdef BIAS_HAVE_UEYE
605 #ifdef BIAS_HAVE_PMD_PMDTec
614 #ifdef BIAS_HAVE_PMD_PMDZess
621 #ifdef BIAS_HAVE_DSHOW
631 #ifdef BIAS_HAVE_KINECT2
641 BIASWARN(
"Camera type not supported.");
646 gettimeofday(&t2,NULL);
647 long duration = ((t2.tv_sec-t1.tv_sec)*1000000) + (t2.tv_usec-t1.tv_usec);
650 int sec=t1.tv_sec + duration/1000000;
651 int usec=t1.tv_usec + duration%1000000;
652 if (usec > 1000000) {
660 #ifdef BIAS_HAVE_DCAM
662 AllImages_->
SetTime(sec, usec);
663 ImgCenter_->
SetTime(sec, usec);
667 #ifdef BIAS_HAVE_SWISSRANGER
674 #ifdef BIAS_HAVE_PMD_PMDTec
681 #ifdef BIAS_HAVE_PMD_PMDZess
687 #ifdef BIAS_HAVE_KINECT2
703 BufferAccess_->Lock();
705 if((*WriteIndex_ + 1) % ImageBuffer_->size() != *ReadIndex_ ){
707 BufferAccess_->Unlock();
710 if((*ImageBuffer_)[*WriteIndex_] == NULL)
712 *(*ImageBuffer_)[*WriteIndex_] = *Img_;
714 if(ImgCenter_ != NULL){
715 if((*ImageBufferCenter_)[*WriteIndex_] == NULL)
717 *(*ImageBufferCenter_)[*WriteIndex_] = *ImgCenter_;
719 if(ImgRight_ != NULL){
720 if((*ImageBufferRight_)[*WriteIndex_] == NULL)
722 *(*ImageBufferRight_)[*WriteIndex_] = *ImgRight_;
724 if(ImgDepth_ != NULL){
725 if((*ImageBufferPMDDepth_)[*WriteIndex_] == NULL)
727 *(*ImageBufferPMDDepth_)[*WriteIndex_] = *ImgDepth_;
730 if((*ImageBufferPMDAmp_)[*WriteIndex_] == NULL)
732 *(*ImageBufferPMDAmp_)[*WriteIndex_] = *ImgAmp_;
735 if((*ImageBufferPMDInt_)[*WriteIndex_] == NULL)
737 *(*ImageBufferPMDInt_)[*WriteIndex_] = *ImgInt_;
741 BufferAccess_->Lock();
742 *WriteIndex_ = (*WriteIndex_ + 1) % ImageBuffer_->size();
744 BufferAccess_->Unlock();
747 BufferAccess_->Unlock();
753 usleep(BUFFER_GRAB_SLEEP);
755 Sleep(BUFFER_GRAB_SLEEP/1000);
766 mutexServerCondition_->Lock();
767 ServerCondition_->Signal();
768 mutexServerCondition_->Unlock();
769 ClientCondition_->Wait();
772 mutexClientCondition_->Unlock();
782 std::vector<wxCondition*> *ClientCondition,
783 std::vector<wxCondition*> *ServerCondition,
784 std::vector<wxMutex*> *mutexClientCondition,
785 std::vector<wxMutex*> *mutexServerCondition)
787 :wxThread(wxTHREAD_DETACHED)
791 mutexClientCondition_= mutexClientCondition;
792 mutexServerCondition_= mutexServerCondition;
795 ClientCondition_ = ClientCondition;
796 ServerCondition_ = ServerCondition;
814 for (
unsigned int i = 0; i < ServerCondition_->size(); i++)
815 (*mutexServerCondition_)[i]->Lock();
817 while(!TestDestroy()){
831 for (
unsigned int i = 0; i < ServerCondition_->size(); i++) {
832 if ((*Cameras_)[i] != NULL) {
834 (*ServerCondition_)[i]->Wait();
842 for (
unsigned int i = 0; i < ServerCondition_->size(); i++) {
844 if ((*Cameras_)[i] != NULL) {
845 (*mutexClientCondition_)[i]->Lock();
846 (*ClientCondition_)[i]->Signal();
847 (*mutexClientCondition_)[i]->Unlock();
GrabSingleThread(BIAS::VideoSource *cam, wxCondition *ClientCondition, wxCondition *ServerCondition, wxMutex *mutexClientCondition, wxMutex *mutexServerCondition, unsigned int threadNumber, wxMutex *BufferAccessMutex, bool &writeToBuffer, unsigned int &readIndex, unsigned int &writeIndex, BIAS::Camera< unsigned char > *img, BIAS::Camera< unsigned char > *imgCenter, BIAS::Camera< unsigned char > *imgRight, BIAS::Camera< float > *imgDepth, BIAS::Camera< float > *imgAmp, BIAS::Camera< float > *imgInt, BIAS::Camera< unsigned char > *imgAll, std::vector< Camera< unsigned char > * > *imageBuffer, std::vector< Camera< unsigned char > * > *imageBufferCenter, std::vector< Camera< unsigned char > * > *imageBufferRight, std::vector< Camera< float > * > *imageBufferPMDDepth, std::vector< Camera< float > * > *imageBufferPMDAmp, std::vector< Camera< float > * > *imageBufferPMDInt)
int GrabSingle(BIAS::Camera< unsigned char > &image)
virtual int GrabSingleDepth(BIAS::Camera< float > &image)
grab the depth image (slow).
represents Zess PMD camera driver interface TODO: include support for normal images (2DImg_)...
Defines a common interface to different devices.
int GrabSingleModCoeff(Camera< float > &image)
Returns the amplitude image.
Use the Kinect2 class to grab images from the Microsoft Kinect2.
int GrabSingle(BIAS::Camera< unsigned char > &image)
Select the port (bus-id) to use, only valid before OpenDevice()
virtual int GrabSingle(BIAS::Camera< unsigned char > &allImages, BIAS::Camera< unsigned char > &imageLeft, BIAS::Camera< unsigned char > &imageMiddle, BIAS::Camera< unsigned char > &imageRight)
Grab single images.
virtual int GrabSingleIR(BIAS::Camera< float > &image)
grab the raw ir data dump (very fast).
virtual int GrabSingle(BIAS::Camera< unsigned char > &image)=0
grab single color image
virtual int GrabSingle(BIAS::Camera< unsigned char > &image)
grab single color image. Note: This image has already been jpeg compressed
Support for SwissRanger usb cam.
This class VideoSource_DCAM implements access to IEEE1394 (Firewire, iLink) cameras following the DCa...
int Downsample(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
generic downsample function.
unsigned int GetWidth() const
virtual int GrabSingle(Camera< unsigned char > &image)
Returns the 2D image, and reads depth and modulation coefficients.
int GrabSingleModCoeff(Camera< float > &image)
Returns the amplitude image.
This class extends VideoSource for the use of DirectShow devices you need Microsoft Windows SDK versi...
virtual int GrabSingleDepth(BIAS::Camera< float > &image)=0
depth according to formula by Stephane Magnenat, see http://openkinect.org/wiki/Imaging_Information, todo: needs validation!
Support for CamCube usb cam.
int GrabSingleDepth(Camera< float > &image)
Returns the depth image.
unsigned int FrameCounter_
static std::string LeadingZeroString(const int &n, const unsigned int &digits=DEFAULT_LEADING_ZEROS)
Create a string with leading zeroes from number.
unsigned int GetHeight() const
An Image Package is multiple .mip images in one file.
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
double GetRealTime() const
return real time (=wall time clock) in usec JW For Win32: real-time is measured differently from user...
int UpdateMetaData()
copy P_ and co.
int GrabSingleIntensity(Camera< float > &image)
Returns the amplitude image.
int GrabSingleDepth(Camera< float > &image)
Returns the depth image.
virtual int GrabSingle(Camera< unsigned char > &image)
Returns the 2D image, and reads depth and modulation coefficients.
GrabMasterThread(std::vector< BIAS::VideoSource * > *Cameras, std::vector< wxCondition * > *ClientCondition, std::vector< wxCondition * > *ServerCondition, std::vector< wxMutex * > *mutexClientCondition, std::vector< wxMutex * > *mutexServerCondition)
void SetTime(unsigned long long int sec, unsigned long long int usec)
Set time and ensure correct format (seconds and useconds after 'sec')
This class extends VideoSource for the use of IDS uEye devices.
int GrabSingle(BIAS::Camera< unsigned char > &image)
This class extends VideoSource for the use of Video4Linux supported devices like framegrabber, USB cameras.
virtual int GrabSingle(Camera< unsigned char > &image)
Returns the 2D image, and reads depth and modulation coefficients.
int GrabSingleDepth(Camera< float > &image)
Returns the depth image.
Use Kinect just like the ToF Cameras.
int GrabSingleModCoeff(Camera< float > &image)
Returns the amplitude image.
ImageSaveThread(std::string cameraName, const int &downsample, wxMutex *BufferAccessMutex, bool &writeToBuffer, unsigned int &readIndex, unsigned int &writeIndex, BIAS::Camera< unsigned char > *img, BIAS::Camera< unsigned char > *imgCenter, BIAS::Camera< unsigned char > *imgRight, BIAS::Camera< float > *imgDepth, BIAS::Camera< float > *imgAmp, BIAS::Camera< float > *imgInt, std::vector< Camera< unsigned char > * > *imageBuffer, std::vector< Camera< unsigned char > * > *imageBufferCenter, std::vector< Camera< unsigned char > * > *imageBufferRight, std::vector< Camera< float > * > *imageBufferPmdDepth, std::vector< Camera< float > * > *imageBufferPmdAmp, std::vector< Camera< float > * > *imageBufferPmdInt, bool saveToStream=false)