Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ofxDabVideoTracker/src/dab_tracker_camera.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
172 lines (126 sloc)
6.38 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** \file dab_tracker_camera.h | |
*/ | |
#pragma once | |
#include <iostream> | |
#include <array> | |
#include <map> | |
#include "ofxVideoRecorder.h" | |
#include "ofxCVImage.h" | |
#include "dab_parameter.h" | |
#include "dab_exception.h" | |
#include "dab_parameter.h" | |
namespace dab | |
{ | |
namespace tracker | |
{ | |
class Camera : public ParameterListener | |
{ | |
public: | |
Camera(); | |
Camera(std::array<unsigned int, 2> pFrameSize, unsigned int pChannelCount) throw (dab::Exception); | |
Camera(const std::string& pMoviePlayFileName, unsigned int pChannelCount, unsigned int pFrameRate) throw (dab::Exception); // TODO: is it really impossible to read frame rate from movie?? | |
virtual ~Camera() throw (dab::Exception); | |
const array<unsigned int, 2>& frameSize() const; | |
unsigned int channelCount() const; | |
float frameRate() const; | |
ofxCvImage* frame(); | |
void setSettingsFileName(const std::string& pSettingsFileName); | |
void setMovieRecordFileName(const std::string& pMovieRecordFileName); | |
bool checkControl(const std::string& pControlName) const; | |
bool checkControlValue(const std::string& pControlName) const; | |
template<typename DataType> bool checkControlValueType(const std::string& pControlName) const; | |
std::map<std::string,AbstractParameter*>& controls(); | |
const std::map<std::string,AbstractParameter*>& controls() const; | |
AbstractParameter& getControl(const std::string& pControlName ) throw (dab::Exception); | |
const AbstractParameter& getControl(const std::string& pControlName ) const throw (dab::Exception); | |
template<typename DataType> Parameter<DataType>& getControl(const std::string& pControlName ) throw (dab::Exception); | |
template<typename DataType>const Parameter<DataType>& getControl(const std::string& pControlName ) const throw (dab::Exception); | |
const AbstractValue& getControlValue(const std::string& pControlName) const throw (dab::Exception); | |
template<typename DataType> const DataType& getControlValue(const std::string& pControlName) const throw (dab::Exception); | |
virtual void setControlValue(const std::string& pControlName) throw (dab::Exception); | |
virtual void setControlValue(const std::string& pControlName, const AbstractValue& pValue ) throw (dab::Exception); | |
void notifyParameterChange( const AbstractParameter& pParameter ); | |
virtual void start() throw (dab::Exception); | |
virtual void stop() throw (dab::Exception); | |
virtual void capture() throw (dab::Exception); | |
virtual void startRecording() throw (dab::Exception); | |
virtual void stopRecording() throw (dab::Exception); | |
void recordStill(const std::string& pFileName) throw (dab::Exception); | |
void saveStill(ofxCvImage* pImage, const std::string& pFileName) throw (dab::Exception); | |
virtual void saveSettings() throw (dab::Exception); | |
virtual void restoreSettings() throw (dab::Exception); | |
protected: | |
void createBaseParameters(); | |
// camera frame | |
ofxCvImage* mFrame; | |
ofxCvColorImage* mColorConversionFrame; // necessary for movie playback and recording in case of gray scale image | |
//CvRect mROI; | |
// camera basic settigs | |
std::array<unsigned int, 2> mFrameSize; | |
unsigned int mChannelCount; | |
static float sFrameRate; | |
float mFrameRate; | |
bool mLoadSettings; | |
bool mSaveSettings; | |
std::string mSettingsFileName; | |
// camera controls | |
std::map< std::string, AbstractParameter* > mControls; | |
std::vector< std::string> mDontSaveControlNames; | |
std::shared_ptr<Camera> mSelf; | |
// camera state | |
bool mBlocked; | |
bool mCapturing; | |
bool mMovieRecording; | |
bool mMoviePlaying; | |
bool mCaptureStill; | |
std::string mCaptureStillFileName; | |
// movie playback | |
std::string mMoviePlayFileName; | |
ofVideoPlayer* mMoviePlayer; | |
// movie recording | |
std::string mMovieRecordFileName; | |
std::string mMovieRecordFileSuffix; | |
ofxVideoRecorder* mMovieRecorder; | |
}; | |
template<typename DataType> | |
bool | |
Camera::checkControlValueType(const std::string& pControlName) const | |
{ | |
auto controlIter = mControls.find(pControlName); | |
if( controlIter == mControls.end() ) return false; | |
return controlIter->second->hasDataType<DataType>(); | |
} | |
template<typename DataType> | |
Parameter<DataType>& | |
Camera::getControl(const std::string& pControlName ) throw (dab::Exception) | |
{ | |
auto controlIter = mControls.find(pControlName); | |
if( controlIter == mControls.end() ) throw dab::Exception("TRACKER ERROR: Camera has no control named " + pControlName, __FILE__, __FUNCTION__, __LINE__); | |
Parameter<DataType>* controlParameter = dynamic_cast< Parameter<DataType>* >( controlIter->second ); | |
if( controlParameter == nullptr ) throw dab::Exception("TRACKER ERROR: Camera control" + pControlName + " is not of the requested DataType", __FILE__, __FUNCTION__, __LINE__); | |
return *controlParameter; | |
} | |
template<typename DataType> | |
const Parameter<DataType>& | |
Camera::getControl(const std::string& pControlName ) const throw (dab::Exception) | |
{ | |
auto controlIter = mControls.find(pControlName); | |
if( controlIter == mControls.end() ) throw dab::Exception("TRACKER ERROR: Camera has no control named " + pControlName, __FILE__, __FUNCTION__, __LINE__); | |
Parameter<DataType>* controlParameter = dynamic_cast< Parameter<DataType>* >( controlIter->second ); | |
if( controlParameter == nullptr ) throw dab::Exception("TRACKER ERROR: Camera control" + pControlName + " is not of the requested DataType", __FILE__, __FUNCTION__, __LINE__); | |
return *controlParameter; | |
} | |
template<typename DataType> | |
const DataType& | |
Camera::getControlValue(const std::string& pControlName) const throw (dab::Exception) | |
{ | |
auto controlIter = mControls.find(pControlName); | |
if( controlIter == mControls.end() ) throw dab::Exception("TRACKER ERROR: Camera has no control named " + pControlName, __FILE__, __FUNCTION__, __LINE__); | |
AbstractParameter* abstractControlParameter = controlIter->second; | |
if(abstractControlParameter->hasValue() == false) throw dab::Exception("TRACKER ERROR: Camera control " + pControlName + " has no value", __FILE__, __FUNCTION__, __LINE__); | |
Parameter<DataType>* controlParameter = dynamic_cast< Parameter<DataType>* >( abstractControlParameter ); | |
if( controlParameter == nullptr ) throw dab::Exception("TRACKER ERROR: Camera control" + pControlName + " is not of the requested DataType", __FILE__, __FUNCTION__, __LINE__); | |
return controlParameter->getValue(); | |
} | |
}; | |
}; |