Linux example: This example shows the usage of the C-style interface to access a locally attached camera via USB.
Linux example: This example shows the usage of the C-style interface to access a locally attached camera via USB.
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <signal.h>
#include "IRDevice.h"
#include "IRImager.h"
#include "IRLogger.h"
#include "IRFileWriter.h"
#include "FramerateCounter.h"
using namespace std;
using namespace evo;
bool _keepCapturing = true;
void sigHandler(int dummy = 0)
{
_keepCapturing = false;
}
for (
unsigned int i = 0; i < events.
size(); i++)
{
cout << "\tChannel: " << +event.channel << " Type: ";
switch (event.inputType)
{
case IREventInputType::DigitalInput:
cout << "DigitalInput";
break;
case IREventInputType::AnalogInput:
cout << "AnalogInput";
break;
case IREventInputType::Software:
cout << "Software";
break;
default:
cout << "Unknown";
break;
}
cout << endl;
}
}
void onThermalFrame(
unsigned short *thermal,
unsigned int w,
unsigned int h,
IRFrameMetadata meta,
void *arg)
{
cout <<
"Frameid: " << meta.
counter << endl;
cout << "DIs: ";
for (
unsigned int i = 0; i < meta.
pifDIs.
size(); i++)
{
cout << meta.
pifDIs[i] <<
" ";
}
cout << endl << "AIs: ";
for (
unsigned int i = 0; i < meta.
pifAIs.
size(); i++)
{
cout << meta.
pifAIs[i] <<
" ";
}
cout << endl;
}
{
cout << "onThermalFrameEvent" << endl;
displayEvents(events);
}
{
cout << "onVisibleFrameEvent" << endl;
displayEvents(events);
}
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 = IRDevice::IRCreateDevice(params);
if (dev)
{
if (imager.
init(¶ms, dev->getFrequency(), dev->getWidth(), dev->getHeight(), dev->controlledViaHID()))
{
{
if (!dev)
{
cout << "NO DEV" << endl;
exit(1);
}
if (dev->isOpen())
{
double timestamp;
unsigned char *bufferRaw = new unsigned char[dev->getRawBufferSize()];
char nmea[GPSBUFFERSIZE];
memset(nmea, 0, GPSBUFFERSIZE * sizeof(*nmea));
pifConfig = imager.
setPifType(IRPifType::Intern,1);
if(fwRevision >= 3000 && fwRevision < 3200 && pifType != IRPifType::Stackable){
pifConfig = imager.
setPifType(IRPifType::Stackable,1);
}
else{
}
{
pifConfig.
ChannelsDI[0].Mode = IRChannelInputMode::Snapshot;
}
{
pifConfig.
ChannelsAI[0].Mode = IRChannelInputMode::Snapshot;
}
{
pifConfig.
ChannelsAO[0].AnalogMode = IRChannelAnalogOutputMode::Range_0V_10V;
}
{
pifConfig.
ChannelsAO[1].AnalogMode = IRChannelAnalogOutputMode::Range_0V_10V;
}
{
pifConfig.
ChannelsAO[2].Mode = IRChannelOutputMode::Manual;
pifConfig.
ChannelsAO[2].AnalogMode = IRChannelAnalogOutputMode::Range_0V_10V;
}
{
pifConfig.
ChannelsAO[3].Mode = IRChannelOutputMode::Manual;
pifConfig.
ChannelsAO[3].AnalogMode = IRChannelAnalogOutputMode::Range_0mA_20mA;
}
dev->startStreaming();
while (_keepCapturing)
{
dev->getFrame(bufferRaw);
cout << "DIs: ";
for (
unsigned int i = 0; i < irFrameMetadata.
pifDIs.
size(); i++)
{
cout << irFrameMetadata.
pifDIs[i] <<
" ";
}
cout << endl << "AIs: ";
for (
unsigned int i = 0; i < irFrameMetadata.
pifAIs.
size(); i++)
{
cout << irFrameMetadata.
pifAIs[i] <<
" ";
}
cout << endl;
}
}
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;
}
C-Array wrapper for handle size, copy and memory.
Definition: IRArray.h:23
std::size_t size() const
Returns size of array.
Definition: IRArray.h:184
Wrapper for PI driver and image processing library.
Definition: IRImager.h:141
void setPifDO(unsigned char channel, bool value)
Set the Pif Digital Output.
const IRFrameMetadata & getLastMetadata()
Returns the last meta 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.
void setThermalFrameEventCallback(fptrIRThermalSnapshot callback)
Set callback function to be called for PIF or software trigger events.
void setThermalFrameCallback(fptrIRThermalFrame callback)
Set callback function to be called for new frames.
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 setVisibleFrameEventCallback(fptrIRVisibleSnapshot callback)
Set callback function to be called for PIF or software trigger events.
void process(unsigned char *buffer, void *arg=NULL)
Process raw data.
IRPifConfig getPifConfig() const
Get the Pif Config object.
IRPifType::Value getPifType() const
Returns the current pif type.
void setPifAO(unsigned char channel, float value)
Set the Pif Analog Output.
void setPifConfig(IRPifConfig config)
Set the Pif Config.
float getMaxFramerate() const
Get maximum frame rate of device return frame rate (in frames/second)
unsigned int getFWRevision() const
Get firmware revision.
IRPifConfig setPifType(IRPifType::Value pifType, unsigned char pifDeviceCount)
Currently only for Xi80.
unsigned int getWidth() const
Get image width of thermal channel.
Structure containing device parameters.
Definition: IRDeviceParams.h:125
Structure containing event data information.
Definition: IRDeviceParams.h:77
Config for pif.
Definition: IRPifConfig.h:37
IRArray< IRChannelConfigAI > ChannelsAI
Channel config of analog input channel's.
Definition: IRPifConfig.h:160
float AnalogValueMoving
Analog Output Voltage/Milliampere when Flag is moving.
Definition: IRPifConfig.h:118
IRArray< IRChannelConfigDO > ChannelsDO
Channel config of digital output channel's.
Definition: IRPifConfig.h:166
IRChannelConfig Channel
Output channel for flag.
Definition: IRPifConfig.h:124
float AnalogValueClosed
Analog Output Voltage/Milliampere when Flag is closed.
Definition: IRPifConfig.h:112
IRArray< IRChannelConfigDI > ChannelsDI
Channel config of digital input channel's.
Definition: IRPifConfig.h:154
IRArray< IRChannelConfigAO > ChannelsAO
Channel config of analog output channel's.
Definition: IRPifConfig.h:172
float AnalogValue
Analog Output Voltage/Milliampere on Frame for syncing.
Definition: IRPifConfig.h:133
float AnalogValueOpen
Analog Output Voltage/Milliampere when Flag is open.
Definition: IRPifConfig.h:106
Value
Definition: IRDeviceParams.h:61