SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SENSCameraRecorderDataHandler Class Reference

#include <SENSRecorderDataHandler.h>

Inheritance diagram for SENSCameraRecorderDataHandler:
[legend]

Public Member Functions

 SENSCameraRecorderDataHandler ()
 
void writeOnThreadStart () override
 called in thread store routine when thread starts More...
 
void writeLineToFile (ofstream &file, const FrameInfo &data) override
 called in thread store routine for every new line More...
 
void writeOnThreadFinish () override
 called in thread store routine when thread finished More...
 
void updateConfig (const SENSCameraConfig &config)
 
- Public Member Functions inherited from SENSRecorderDataHandler< FrameInfo >
 SENSRecorderDataHandler (const std::string &name)
 
virtual ~SENSRecorderDataHandler ()
 
void start (const std::string &outputDir)
 start the store thread More...
 
void stop ()
 stop the store thread and clear values in queue More...
 
void add (FrameInfo &&item)
 add new value to store queue More...
 
bool getErrorMsg (std::string &msg)
 get error msg (valid if function returns true) More...
 

Private Attributes

cv::VideoWriter _videoWriter
 
int _frameIndex = 0
 

Additional Inherited Members

- Protected Member Functions inherited from SENSRecorderDataHandler< FrameInfo >
virtual void writeHeaderToFile (ofstream &file)
 called in thread store routine when file could be opened More...
 
- Protected Attributes inherited from SENSRecorderDataHandler< FrameInfo >
std::string _outputDir
 output directory More...
 

Detailed Description

Constructor & Destructor Documentation

◆ SENSCameraRecorderDataHandler()

SENSCameraRecorderDataHandler::SENSCameraRecorderDataHandler ( )

Definition at line 163 of file SENSRecorderDataHandler.cpp.

164  : SENSRecorderDataHandler("camera")
165 {
166 }
SENSRecorderDataHandler(const std::string &name)

Member Function Documentation

◆ updateConfig()

void SENSCameraRecorderDataHandler::updateConfig ( const SENSCameraConfig config)

Definition at line 211 of file SENSRecorderDataHandler.cpp.

212 {
213  //write config to file in directory
214  std::string fileName = _outputDir + "cameraConfig.json";
215  if (Utils::fileExists(fileName))
216  Utils::removeFile(fileName);
217 
218  cv::FileStorage fs;
219  fs.open(fileName, cv::FileStorage::WRITE);
220  if (fs.isOpened())
221  {
222  fs << "deviceId" << config.deviceId;
223  fs << "widthPix" << config.streamConfig.widthPix;
224  fs << "heightPix" << config.streamConfig.heightPix;
225  fs << "focalLengthPix" << config.streamConfig.focalLengthPix;
226  fs << "focusMode" << (int)config.focusMode;
227  fs << "facing" << (int)config.facing;
228  }
229 }
Config config
The configuration set in App::run.
Definition: AppAndroid.cpp:34
bool fileExists(const string &pathfilename)
Returns true if a file exists.
Definition: Utils.cpp:894
void removeFile(const string &path)
RemoveFile deletes a file with given path.
Definition: Utils.cpp:872

◆ writeLineToFile()

void SENSCameraRecorderDataHandler::writeLineToFile ( ofstream &  file,
const FrameInfo data 
)
overridevirtual

called in thread store routine for every new line

Implements SENSRecorderDataHandler< FrameInfo >.

Definition at line 173 of file SENSRecorderDataHandler.cpp.

174 {
175  if (data.first.empty())
176  {
177  SENS_WARN("SENSCameraRecorderDataHandler::writeLineToFile: frame is empty");
178  return;
179  }
180 
181  if (!_videoWriter.isOpened())
182  {
183  std::string filename = _outputDir + "video.avi";
184  _videoWriter.open(filename, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 30, data.first.size(), true);
185  //_videoWriter.open(filename, cv::VideoWriter::fourcc('X', 'V', 'I', 'D'), 30, data.first.size(), true);
186  SENS_DEBUG("Opening video for writing: %s", filename.c_str());
187  }
188 
189  if (!_videoWriter.isOpened())
190  {
191  SENS_WARN("SENSCameraRecorderDataHandler::writeLineToFile: video writer not opened");
192  }
193  else
194  {
195  long long timePt = std::chrono::time_point_cast<SENSMicroseconds>(data.second).time_since_epoch().count();
196  //write time and frame index
197  file << timePt << " " << _frameIndex << "\n";
198  //SENS_DEBUG("SENSCameraRecorderDataHandler: time point for frame %d is %s", _frameIndex, timeStr.c_str());
199  _frameIndex++;
200 
201  _videoWriter.write(data.first);
202  }
203 }
#define SENS_DEBUG(...)
Definition: SENS.h:60
#define SENS_WARN(...)
Definition: SENS.h:64

◆ writeOnThreadFinish()

void SENSCameraRecorderDataHandler::writeOnThreadFinish ( )
overridevirtual

called in thread store routine when thread finished

Reimplemented from SENSRecorderDataHandler< FrameInfo >.

Definition at line 205 of file SENSRecorderDataHandler.cpp.

206 {
207  if (_videoWriter.isOpened())
208  _videoWriter.release();
209 }

◆ writeOnThreadStart()

void SENSCameraRecorderDataHandler::writeOnThreadStart ( )
overridevirtual

called in thread store routine when thread starts

Reimplemented from SENSRecorderDataHandler< FrameInfo >.

Definition at line 168 of file SENSRecorderDataHandler.cpp.

169 {
170  _frameIndex = 0;
171 }

Member Data Documentation

◆ _frameIndex

int SENSCameraRecorderDataHandler::_frameIndex = 0
private

Definition at line 116 of file SENSRecorderDataHandler.h.

◆ _videoWriter

cv::VideoWriter SENSCameraRecorderDataHandler::_videoWriter
private

Definition at line 115 of file SENSRecorderDataHandler.h.


The documentation for this class was generated from the following files: