Linux example: This example shows the usage of the external reference probe BR 20AR.
Linux example: This example shows the usage of the external reference probe BR 20AR.
#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"
#include "ImageBuilder.h"
#include <opencv2/opencv.hpp>
using namespace std;
using namespace evo;
unsigned int measurementFieldTopLeftU = 10;
unsigned int measurementFieldTopLeftV = 10;
unsigned int measurementFieldWidth = 100;
unsigned int measurementFieldHeight = 100;
bool _keepCapturing = true;
unsigned int _lastReferenceCounterHW = 0;
float _tempAvgMeasurementField = 0;
float _tempAvgProbe = 0;
char _measurementsCount = 0;
unsigned char *_paletteImage = NULL;
void sigHandler(int dummy = 0)
{
_keepCapturing = false;
}
void onThermalFrame(
unsigned short *thermal,
unsigned int w,
unsigned int h,
IRFrameMetadata meta,
void *arg)
{
cout <<
"Frameid: " << meta.
counter << endl;
{
std::cout << "Please enable external probe through setting IRDeviceParams::useExternalProbeForReferencing to true!" << std::endl;
return;
}
float tempExternalProbe = meta.
pifAIs[0];
if (tempExternalProbe > 511)
{
std::cout << "Check connection to external probe!" << std::endl;
return;
}
_tempAvgProbe = (_tempAvgProbe * 4 + tempExternalProbe) / 5.f;
cout << "Reference Temperature of external Probe: " << tempExternalProbe << " °C" << endl;
iBuilder.setData(w, h, thermal);
unsigned int paletteWidth = iBuilder.getStride();
unsigned int paletteHeight = h;
if (_paletteImage == NULL)
_paletteImage = new unsigned char[paletteWidth * h * 3];
iBuilder.convertTemperatureToPaletteImage(_paletteImage);
cv::Mat cv_img(cv::Size(paletteWidth, paletteHeight), CV_8UC3, &_paletteImage[0], cv::Mat::AUTO_STEP);
cv::rectangle(cv_img,
cv::Rect2i(measurementFieldTopLeftU, measurementFieldTopLeftV, measurementFieldWidth, measurementFieldHeight),
cv::Scalar(255, 0, 0));
cv::cvtColor(cv_img, cv_img, CV_BGR2RGB);
cv::imshow("palette image", cv_img);
if (meta.
flagState == 0 && thermal[0] > 0 && thermal[0] != 0xcdcd)
{
if (_measurementsCount < 5)
_measurementsCount++;
float meanTempMeasurementField = iBuilder.getMeanTemperature(
measurementFieldTopLeftU, measurementFieldTopLeftV, measurementFieldTopLeftU + measurementFieldWidth, measurementFieldTopLeftV + measurementFieldHeight);
_tempAvgMeasurementField = (std::abs(_tempAvgMeasurementField - meanTempMeasurementField) < 0.5f) ? ((_tempAvgMeasurementField * 4 + meanTempMeasurementField) / 5.f) : meanTempMeasurementField;
float tempDiff = std::abs(_tempAvgMeasurementField - _tempAvgProbe);
cout << "Camera avg. Temperature of external probe: " << _tempAvgMeasurementField << endl;
long long diffTime = avgTimePerFrame * ((
long int)meta.
counterHW - _lastReferenceCounterHW);
const long long waitInterval = 500 * 1000 * 10;
if (_measurementsCount > 4 && (diffTime < 0 || diffTime > waitInterval) && tempDiff >= ((_imager.
getTemprangeDecimal() <= 1) ? 0.2f : 0.04f))
{
cout << "setReferenceTemperature: " << tempDiff << " " << _tempAvgProbe << " " << _tempAvgMeasurementField << endl;
}
}
}
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));
dev->startStreaming();
do
{
dev->getFrame(bufferRaw);
} while (cv::waitKey(1) != 'q');
}
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;
}
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
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.
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 process(unsigned char *buffer, void *arg=NULL)
Process raw data.
void setReferenceTemperature(float referenceTemperature, float measuredTemperature, float tAmbient=-999.f)
Set a reference temperature to a known reference source inside the view of the camera to improve came...
long long getAvgTimePerFrame() const
Get average time per frame.
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.
Image creation module for displaying purposes.
Definition: ImageBuilder.h:66
Structure containing device parameters.
Definition: IRDeviceParams.h:125
bool useExternalProbeForReferencing
Definition: IRDeviceParams.h:148