Version 8.9.0
 
Loading...
Searching...
No Matches
examples/linux/oop/irimagerShowOOP.cpp

Linux example: This object-oriented example demonstrates how to acquire data from an PI imager and use callback methods of a derived class.

Linux example: This object-oriented example demonstrates how to acquire data from an PI imager and use callback methods of a derived class.

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <pthread.h>
#include <sys/time.h>
#include <signal.h>
// Optris device interface
#include "IRDevice.h"
// Optris imager interface
#include "IRImager.h"
// Optris frame rate counter
#include "FramerateCounter.h"
// Optris logging interface
#include "IRLogger.h"
// Class wrapping callback routines
#include "IRImagerHandler.h"
// Graphical User Interface
#include "IRImagerGUI.h"
using namespace std;
using namespace evo;
int main (int argc, char* argv[])
{
if(argc!=2)
{
cout << "usage: " << argv[0] << " <xml configuration file>" << endl;
return -1;
}
IRLogger::setVerbosity(IRLOG_ERROR, IRLOG_OFF);
IRDeviceParamsReader::readXML(argv[1], params);
IRDevice* dev = NULL;
dev = IRDevice::IRCreateDevice(params);
// Initialize Optris image processing chain
IRImager imager;
if(imager.init(&params, dev->getFrequency(), dev->getWidth(), dev->getHeight(), dev->controlledViaHID()))
{
unsigned int w = imager.getWidth();
unsigned int h = imager.getHeight();
if(w==0 || h==0)
{
cout << "Error: Image streams not available or wrongly configured. Check connection of camera and config file." << endl;
return -1;
}
cout << "Connected camera, serial: " << dev->getSerial()
<< ", HW(Rev.): " << imager.getHWRevision()
<< ", FW(Rev.): " << imager.getFWRevision() << endl;
cout << "Thermal channel: " << w << "x" << h << "@" << params.framerate << "Hz" << endl;
cout << "Visible channel: " << imager.getVisibleWidth() << "x" << imager.getVisibleHeight() << "@" << params.framerate << "Hz" << endl;
IRImagerHandler handler(dev, &imager);
if(dev->startStreaming()!=0)
{
cout << "Error occurred in starting stream ... aborting. You may need to reconnect the camera." << endl;
exit(-1);
}
IRImagerGUI gui(imager.hasBispectralTechnology(), imager.getTemprangeDecimal());
FramerateCounter fpsStream;
// Enter endless loop in order to pass raw data to Optris image processing library.
// Processed data are supported by the frame callback function.
while(gui.isAlive())
{
if(handler.checkForNewFrame())
{
if(gui.wantsThermalChannel())
gui.setThermalImage(handler.getThermalImage(), handler.getThermalWidth(), handler.getThermalHeight());
else
gui.setVisibleImage(handler.getVisibleImage(), handler.getVisibleWidth(), handler.getVisibleHeight());
}
if(gui.popManualFlagEvent())
imager.forceFlagEvent();
if(gui.popSerializeEvent())
{
unsigned char* ppm;
unsigned int size;
gui.getSnapshot(ppm, size);
ofstream file("/tmp/snapshot.ppm", std::ios::binary);
file.write((const char*) ppm, size);
delete [] ppm;
}
if(fpsStream.trigger())
cout << "Framerate: " << fpsStream.getFps() << " fps" << endl;
}
dev->stopStreaming();
}
cout << "Exiting application" << endl;
delete dev;
return 0;
}
Framerate calculation helper.
Definition: FramerateCounter.h:33
bool trigger(double *fps=NULL)
Trigger, i.e., integrate new measurement.
double getFps()
Accessor to current frames per second rate (no triggering is performed)
Wrapper for PI driver and image processing library.
Definition: IRImager.h:141
short getTemprangeDecimal() const
Returns the number of decimal places in thermal data.
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.
bool hasBispectralTechnology() const
Check if bispectral technology is available.
unsigned int getHeight() const
Get image height of thermal channel.
void forceFlagEvent(float time=0.f)
Force shutter flag event manually (close/open cycle)
unsigned int getVisibleWidth() const
Get image width of visible channel (if available)
unsigned int getVisibleHeight() const
Get image height of visible channel (if available)
unsigned int getFWRevision() const
Get firmware revision.
unsigned int getHWRevision() const
Get hardware revision.
unsigned int getWidth() const
Get image width of thermal channel.
Structure containing device parameters.
Definition: IRDeviceParams.h:125
float framerate
Definition: IRDeviceParams.h:134