Version 8.9.0
 
Loading...
Searching...
No Matches
examples/linux/directbinding/direct_binding_usb_show.cpp

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 <iostream>
#include <memory>
#include <opencv2/highgui/highgui_c.h>
//--Code for displaying image -----------------
#include <opencv2/opencv.hpp>
#include "libirimager/direct_binding.h"
//---------------------------------------------
int main(int argc, char *argv[])
{
if(argc!=2)
{
std::cout << "usage: " << argv[0] << " <xml configuration file>" << std::endl;
return -1;
}
if(::evo_irimager_usb_init(argv[1], 0, 0) != 0) return -1;
int err;
int p_w;
int p_h;
if((err = ::evo_irimager_get_palette_image_size(&p_w, &p_h)) != 0)
{
std::cerr << "error on evo_irimager_get_palette_image_size: " << err << std::endl;
exit(-1);
}
int t_w;
int t_h;
if((err = ::evo_irimager_get_thermal_image_size(&t_w, &t_h)) != 0)
{
std::cerr << "error on evo_irimager_get_palette_image_size: " << err << std::endl;
exit(-1);
}
std::vector<unsigned char> palette_image(p_w * p_h * 3);
std::vector<unsigned short> thermal_data(t_w * t_h);
do
{
if((err = ::evo_irimager_get_thermal_palette_image(t_w, t_h, &thermal_data[0], p_w, p_h, &palette_image[0]))==0)
{
unsigned long int mean = 0;
//--Code for calculation mean temperature of image -----------------
for (int y = 0; y < t_h; y++)
{
for (int x = 0; x < t_w; x++)
{
mean += thermal_data[y*t_w + x];
}
}
std::cout << (mean / (t_h * t_w)) / 10.0 - 100 << std::endl;
//---------------------------------------------
//--Code for displaying image -----------------
cv::Mat cv_img(cv::Size(p_w, p_h), CV_8UC3, &palette_image[0], cv::Mat::AUTO_STEP);
cv::cvtColor(cv_img, cv_img, cv::COLOR_BGR2RGB);
cv::imshow("palette image daemon", cv_img);
//---------------------------------------------
}
else
{
std::cerr << "failed evo_irimager_get_thermal_palette_image: " << err << std::endl;
}
} while(cv::waitKey(1) != 'q');//cvGetWindowHandle("palette image daemon"));
return 0;
}
__IRDIRECTSDK_API__ int evo_irimager_usb_init(const char *xml_config, const char *formats_def, const char *log_file)
Initializes an IRImager instance connected to this computer via USB.
__IRDIRECTSDK_API__ int evo_irimager_terminate()
Disconnects the camera, either connected via USB or TCP.
__IRDIRECTSDK_API__ int evo_irimager_get_thermal_palette_image(int w_t, int h_t, unsigned short *data_t, int w_p, int h_p, unsigned char *data_p)
Accessor to an RGB palette image and a thermal image by reference.
__IRDIRECTSDK_API__ int evo_irimager_get_palette_image_size(int *w, int *h)
Accessor to width and height of false color coded palette image.
__IRDIRECTSDK_API__ int evo_irimager_get_thermal_image_size(int *w, int *h)
Accessor to image width and height.