//////////////////////////////////////////////////////// // // videoOptiTrack - Graphics Environment for Multimedia // // zmoelnig@iem.at // // Implementation file // // Copyright (c) 2012 IOhannes m zmölnig. forum::für::umläute. IEM. zmoelnig@iem.at // For information on usage and redistribution, and for a DISCLAIMER OF ALL // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. // ///////////////////////////////////////////////////////// #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef HAVE_LIBOPTITRACK /* when dynamically linking against camerlibrary, we have to set CAMERALIBRARY_IMPORTS * this is a safeguard */ #ifndef CAMERALIBRARY_IMPORTS # warning CAMERALIBRARY_IMPORTS #endif #include "videoOptiTrack.h" #include "Gem/RTE.h" #include "Gem/Exception.h" #include "plugins/PluginFactory.h" using namespace gem::plugins; REGISTER_VIDEOFACTORY("OptiTrack", videoOptiTrack); using namespace CameraLibrary; namespace { struct CMInitBase { CMInitBase(void) { std::cerr << "OptiTrack: enable development..."; cCameraLibraryStartupSettings::X().EnableDevelopment(); std::cerr << "done"<Release(); m_camera=NULL; } bool videoOptiTrack::open(gem::Properties&props) { if(!CameraManager::X().AreCamerasInitialized()) { return false; } CameraList list; if(!m_devname.empty()) { for(int i=0; i=0) { if(m_devnumWidth(); m_pixBlock.image.ysize = m_camera->Height(); m_camera->SetVideoType(MJPEGMode); m_quality=m_camera->MJPEGQuality(); setProperties(props); return true; } pixBlock*videoOptiTrack::getFrame(void) { if(!m_camera)return NULL; //m_frame = m_camera->GetFrame(); m_frame = m_camera->GetLatestFrame(); m_pixBlock.image.reallocate(); if(m_resize) { m_pixBlock.image.setBlack(); } m_resize=false; if(m_frame) { m_frame->Rasterize(m_pixBlock.image.xsize, m_pixBlock.image.ysize, m_pixBlock.image.xsize, m_pixBlock.image.csize*8, m_pixBlock.image.data); m_pixBlock.newimage=true; m_pixBlock.image.upsidedown=true; } return &m_pixBlock; } void videoOptiTrack::releaseFrame(void) { if(m_frame) m_frame->Release(); m_frame=NULL; } std::vectorvideoOptiTrack::enumerate(void) { std::vectorresult; if(!CameraManager::X().AreCamerasInitialized()) { CameraManager::X().WaitForInitialization(); } CameraList list; int i; for(i=0; i0) { m_pixBlock.image.xsize=d; m_resize=true; } } if(props.get("height", d)) { if(d>0) { m_pixBlock.image.ysize=d; m_resize=true; } } #define SETCAMERAPROP_BOOL(name) do { if(props.get(#name, d)) {bool b=(d>0.5); m_camera->Set##name(b); } } while(0) #define SETCAMERAPROP_INT(name) do { if(props.get(#name, d)) {int i=(int)d; m_camera->Set##name(i); } } while(0) #define SETCAMERAPROP_STR(name) do { if(props.get(#name, s)) {int i=(int)d; m_camera->Set##name(s.c_str()); } } while(0) SETCAMERAPROP_BOOL(AEC); SETCAMERAPROP_BOOL(AGC); SETCAMERAPROP_BOOL(ContinuousIR); SETCAMERAPROP_BOOL(EnableBlockingMask); SETCAMERAPROP_BOOL(HighPowerMode); SETCAMERAPROP_BOOL(IRFilter); SETCAMERAPROP_BOOL(MarkerOverlay); SETCAMERAPROP_BOOL(TextOverlay); SETCAMERAPROP_INT(Exposure); SETCAMERAPROP_INT(FrameDecimation); SETCAMERAPROP_INT(FrameRate); SETCAMERAPROP_INT(GrayscaleDecimation); SETCAMERAPROP_INT(Intensity); SETCAMERAPROP_INT(PrecisionCap); SETCAMERAPROP_INT(ShutterDelay); SETCAMERAPROP_INT(StatusIntensity); SETCAMERAPROP_INT(Threshold); SETCAMERAPROP_STR(Name); #undef SETCAMERAPROP_BOOL #undef SETCAMERAPROP_INT #undef SETCAMERAPROP_STR d=-1; if(props.get("quality", d)) { int quality=d; if(quality!=m_quality) { m_quality=quality; if(m_quality<0) { m_camera->SetVideoType(GrayscaleMode); } else { m_camera->SetVideoType(MJPEGMode); m_camera->SetMJPEGQuality(m_quality); } } } /* SetAllLED(eStatusLEDs); SetLED(eStatusLEDs, bool); SetVideoType(eVideoMode); SetLateMJPEGDecompression(bool); SetMJPEGQuality(int); SetName(const char*); SetNumeric(bool, int); SetWindow(int, int, int, int); SetObjectColor(int); SetBitMaskPixel(int x, int y, bool); SetCameraParameter(char*name, float value); */ } void videoOptiTrack::getProperties(gem::Properties&props) { std::vectorkeys=props.keys(); double d; std::string s; props.clear(); if(!m_camera)return; unsigned int i; for(i=0; iIsCameraFanSpeedValid()) { d=m_camera->CameraFanSpeed(); props.set(key, d); continue; } if("temperature"==key && m_camera->IsCameraTempValid()) { d=m_camera->CameraTemp(); props.set(key, d); continue; } #define GETCAMERAPROP_BOOL(name) if(#name == key) {d=m_camera->##name(); props.set(key, d); continue; } else d=0 #define GETCAMERAPROP_INT(name) if(#name == key) {d=m_camera->##name(); props.set(key, d); continue; } else d=0 #define GETCAMERAPROP_STR(name) if(#name == key) {s=m_camera->##name(); props.set(key, s); continue; } else d=0 GETCAMERAPROP_BOOL(AEC); GETCAMERAPROP_BOOL(AGC); GETCAMERAPROP_BOOL(ContinuousIR); GETCAMERAPROP_BOOL(HighPowerMode); GETCAMERAPROP_BOOL(IRFilter); GETCAMERAPROP_BOOL(MarkerOverlay); GETCAMERAPROP_BOOL(TextOverlay); GETCAMERAPROP_INT(Exposure); GETCAMERAPROP_INT(FrameDecimation); GETCAMERAPROP_INT(FrameRate); GETCAMERAPROP_INT(GrayscaleDecimation); GETCAMERAPROP_INT(Intensity); GETCAMERAPROP_INT(PrecisionCap); GETCAMERAPROP_INT(ShutterDelay); GETCAMERAPROP_INT(Threshold); GETCAMERAPROP_STR(Name); #undef GETCAMERAPROP_BOOL #undef GETCAMERAPROP_INT #undef GETCAMERAPROP_STR } } std::vectorvideoOptiTrack::dialogs(void) { std::vectorresult; return result; } bool videoOptiTrack::provides(const std::string name) { return (name==s_name); } std::vectorvideoOptiTrack::provides(void) { std::vectorresult; result.push_back(s_name); return result; } const std::string videoOptiTrack::getName(void) { return s_name; } bool videoOptiTrack::start(void) { //MARK; bool status = false; if(m_camera) { m_camera->Start(); status=m_camera->IsCameraRunning(); } return status; } bool videoOptiTrack::stop (void) { //MARK; bool status=false; if(m_camera) { status=m_camera->IsCameraRunning(); m_camera->Stop(); } return status; } bool videoOptiTrack::reset(void) { CameraLibrary::CameraManager::X().Shutdown(); CameraManager::X().WaitForInitialization(); return true; } #endif /* HAVE_LIBOPTITRACK */