Version 8.9.0
 
Loading...
Searching...
No Matches
examples/linux/minimal/serializeRaw.cpp

Linux example: This minimal example demonstrates how to acquire raw data from an PI imager and serialize it to disk.

Linux example: This minimal example demonstrates how to acquire raw data from an PI imager and serialize it to disk. Raw data can be imported to PIConnect.

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <pthread.h>
#include <sys/time.h>
#include <fstream>
#include <vector>
#include <list>
#include <signal.h>
// Optris device interfaces
#include "IRDevice.h"
// Optris imager interfaces
#include "IRImager.h"
// Optris logging interface
#include "IRLogger.h"
// Optris raw image file writer
#include "IRFileWriter.h"
using namespace std;
using namespace evo;
bool _keepCapturing = true;
void sigHandler(int dummy=0)
{
_keepCapturing = false;
}
int main (int argc, char* argv[])
{
if(argc!=2)
{
cout << "usage: " << argv[0] << " <xml configuration file>" << endl;
return -1;
}
signal(SIGINT, sigHandler);
IRLogger::setVerbosity(IRLOG_ERROR, IRLOG_OFF);
IRDeviceParamsReader::readXML(argv[1], params);
IRDevice* dev = NULL;
dev = IRDevice::IRCreateDevice(params);
if(dev)
{
IRImager imager;
if(imager.init(&params, dev->getFrequency(), dev->getWidth(), dev->getHeight(), dev->controlledViaHID()))
{
if(imager.getWidth()!=0 && imager.getHeight()!=0)
{
cout << "Thermal channel: " << imager.getWidth() << "x" << imager.getHeight() << "@" << imager.getMaxFramerate() << "Hz" << endl;
// Start UVC streaming
if(dev->startStreaming()==0)
{
// Enter loop in order to pass raw data to Optris image processing library.
// Processed data are supported by the frame callback function.
double timestamp;
unsigned char* bufferRaw = new unsigned char[dev->getRawBufferSize()];
RawdataHeader header;
imager.initRawdataHeader(header);
IRFileWriter writer(time(NULL), "/tmp", header);
writer.open();
char nmea[GPSBUFFERSIZE];
memset(nmea, 0, GPSBUFFERSIZE*sizeof(*nmea));
imager.forceFlagEvent(1000.0);
int serializedImages = 0;
int chunk = 1;
while(_keepCapturing)
{
if(dev->getFrame(bufferRaw, &timestamp)==IRIMAGER_SUCCESS)
{
imager.process(bufferRaw, NULL);
if(writer.canDoWriteOperations())
writer.write(timestamp, bufferRaw, chunk, dev->getRawBufferSize(), nmea);
// In order to avoid too large files, the user can split the records into chunks of equal size.
// Here, a fixed number of images should be recorded to each chunk.
if((++serializedImages)%1000==0)
{
chunk++;
}
}
}
delete [] bufferRaw;
}
else
{
cout << "Error occurred in starting stream ... aborting. You may need to reconnect the camera." << endl;
}
}
}
else
{
cout << "Error: Image streams not available or wrongly configured. Check connection of camera and config file." << endl;
}
delete dev;
}
return 0;
}
Wrapper for PI driver and image processing library.
Definition: IRImager.h:141
bool init(IRDeviceParams *params, unsigned int frequency, unsigned int width, unsigned int height, bool useHID, unsigned short hwRev=0, unsigned short fwRev=0)
Initializing routine, to be called after instantiation.
unsigned int getHeight() const
Get image height of thermal channel.
void forceFlagEvent(float time=0.f)
Force shutter flag event manually (close/open cycle)
void process(unsigned char *buffer, void *arg=NULL)
Process raw data.
void initRawdataHeader(RawdataHeader &header) const
Initialize Rawdata header with camera specific parameters.
float getMaxFramerate() const
Get maximum frame rate of device return frame rate (in frames/second)
unsigned int getWidth() const
Get image width of thermal channel.
Structure containing device parameters.
Definition: IRDeviceParams.h:125
Meta data structure describing camera parameters of image stream.
Definition: IRImager.h:54