Record a datacube with a Pika NIR GigE imager (Allied Camera using Vimba API) and save it to disk in a format readable by ENVI or Spectronon.
#include <iostream>
#include <fstream>
#include <exception>
#include <string>
#include <iomanip>
#include <assert.h>
#include <cstdlib>
#include "resonon_imager_allied.h"
int main()
{
const int LINE_COUNT = 100;
const std::string filename = "Pika_allied_test.bil";
std::string header_filename;
int framesize;
int cubesize;
unsigned short * buffer;
char imager_type_buffer[32];
bool free_buffer = false;
try
{
std::cout << "Imager Status:\n";
std::cout << "--------------\n";
std::cout << std::setw(18) << "Imager Type: " << imager_type_buffer << "\n";
std::cout << std::setw(18) <<
"Framerate: " << imager.
get_framerate();
std::cout << std::setw(18) <<
"Bands: " << imager.
get_band_count() <<
"\n";
cubesize = framesize * LINE_COUNT;
buffer = new unsigned short[cubesize];
if (buffer == 0)
{
std::cerr << "Error: memory could not be allocated for datacube";
exit(EXIT_FAILURE);
}
free_buffer = true;
std::cout << "\nRecording Datacube" << std::endl;
for (int i = 0; i < LINE_COUNT; i++)
{
std::cout << "Line " << i + 1 << " of " << LINE_COUNT << std::endl;
}
std::cout << "Recording Complete\nWriting Datacube to Disk" << std::endl;
header_filename = filename + ".hdr";
std::ofstream outfile(header_filename.c_str());
outfile << "ENVI\n";
outfile << "interleave = bil\n";
outfile << "data type = 12\n";
outfile << "bit depth = 14\n";
outfile << "lines = " << LINE_COUNT << "\n";
outfile << "wavelength = {";
outfile << std::setprecision(6);
for(int i = 0; i < num_bands - 1; i++)
{
}
outfile.close();
std::ofstream cubefile;
cubefile.open(filename.c_str(), std::ios::out | std::ios::binary);
cubefile.write((const char*) buffer, cubesize * sizeof(unsigned short));
cubefile.close();
std::cout << "Done." << std::endl;
delete [] buffer;
} catch (std::exception const & e)
{
std::cerr << "Error: " << e.what() << std::endl;
if (free_buffer == true)
delete [] buffer;
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}