This is example source code showing how to use the image capture functionality of AxsunOCTCapture in a C++ client application (Linux OS).
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
#include <filesystem>
#include <algorithm>
using namespace std::chrono_literals;
class AxsunOCTCapture {
private:
public:
AxsunOCTCapture(int32_t size) {
if (
auto retval =
axStartSession(&session_, size); retval != AxErr::NO_AxERROR)
throw retval; }
AOChandle operator()() {
if (session_)
return session_;
else throw AxErr::CAPTURE_SESSION_NOT_SETUP; }
};
auto imaging_global = bool{ false };
auto record_complete = bool{ false };
void DAQStateCallback(uint32_t state, void* userdata) {
std::cout << "callback: ";
std::cout << "DAQ/buffer state -> STOPPED\n";
imaging_global = false;
break;
std::cout << "DAQ/buffer state -> IMAGING\n";
imaging_global = true;
break;
std::cout << "DAQ/buffer state -> RECORD COMPLETE\n";
record_complete = true;
break;
std::cout << "DAQ/buffer state -> RECORDING\n";
break;
std::cout << "DAQ/buffer state -> LOADING COMPLETE\n";
break;
std::cout << "DAQ/buffer state -> LOADING FROM DISK\n";
break;
}
}
void ExportCallback(uint32_t image, void* userdata) {
if (!(image % 10))
std::cout << "callback: Exported image: " << image << "\n";
}
int main() {
char message[512]{""};
try {
std::cout << "Welcome to the AxsunOCTCapture Example Console Application.\n";
auto AOC = AxsunOCTCapture{ 250 };
if (
auto retval =
axGetMessage(AOC(), message); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << message << '\n';
uint32_t imaging{ 0 }, last_packet{ 0 }, last_frame{ 0 }, last_image{ 0 }, dropped_packets{ 0 }, frames_since_sync{ 0 };
.crop_width_total = 2000
};
constexpr auto buffer_size = size_t{ 2048 * 2000 * 4 };
auto image_buffer = std::vector<uint8_t>(buffer_size);
auto counter = int32_t{ 0 };
while (!record_complete && counter < 1000) {
if (
auto retval =
axGetStatus(AOC(), &imaging, &last_packet, &last_frame, &last_image, &dropped_packets, &frames_since_sync); retval != AxErr::NO_AxERROR)
throw retval;
if (imaging_global) {
if (
auto retval =
axGetImageInfo(AOC(), MOST_RECENT_IMAGE, &info); retval != AxErr::NO_AxERROR) {
if (retval != AxErr::DATA_NOT_FOUND_IN_BUFFER && retval != AxErr::DATA_RETURNED_IN_PREVIOUS_REQUEST) {
std::cout << "axGetImageInfo() returned " << static_cast<int32_t>(retval) << " " << message << '\n';
}
}
else {
retval =
axRequestImage(AOC(), info.image_number, prefs, buffer_size, image_buffer.data(), &info);
if (!(counter % 25)) {
std::cout << "Image number: " << info.image_number << ", Width: " << info.width <<", Drops: " << dropped_packets;
if (info.force_trig) std::cout << " *** FORCE TRIGGERED ***";
if (info.trig_too_fast) std::cout << " *** TRIGGER TOO FAST ***";
std::cout << '\n';
}
else {
;
}
}
}
else {
if (!(counter % 50)) {
std::cout << counter << "\tImaging is off. Turn on laser emission and set DAQ to Imaging On mode.\n";
}
}
++counter;
std::this_thread::sleep_for(20ms);
}
std::cout << "Exiting imaging loop...\n\n";
if (record_complete) {
auto tempnumber = int32_t{ 0 };
auto parent_path = std::filesystem::temp_directory_path() / "Axsun" / "OCT_Files";
auto savefile = parent_path / "example_savefile.dat";
auto export_dir = parent_path / "Exported";
if (
auto retval =
axGetStatus(AOC(), &imaging, &last_packet, &last_frame, &last_image, &dropped_packets, &frames_since_sync); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << "There are now " << last_image << " images in the Main Image Buffer.\n";
if (
auto retval =
axSaveFile(AOC(), savefile.c_str(), 0, &tempnumber); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << "Saved " << tempnumber << " packets to " << savefile << "\n";
if (
auto retval =
axResizeBuffer(AOC(), 0); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << "Main Image Buffer cleared.\n";
if (
auto retval =
axGetStatus(AOC(), &imaging, &last_packet, &last_frame, &last_image, &dropped_packets, &frames_since_sync); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << "There are now " << last_image << " images in the Main Image Buffer.\n";
if (
auto retval =
axLoadFile(AOC(), savefile.c_str(), &tempnumber); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << "Loaded " << tempnumber << " packets from disk.\n";
if (
auto retval =
axGetStatus(AOC(), &imaging, &last_packet, &last_frame, &last_image, &dropped_packets, &frames_since_sync); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << "There are now " << last_image << " images in the Main Image Buffer.\n";
.height = 256,
.contrast = 1.0,
.brightness = 0.0,
.colormap = AxColormap::SEPIA,
.movie_fps = 60
};
if (
auto retval =
axExportImagesAdv(AOC(), export_dir.c_str(), &tempnumber,
AxFileType::PNG, 1, 100, request_prefs, export_prefs); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << "Exported " << tempnumber << " individual images to " << export_dir << "\n";
}
}
std::cout << "ERROR: " << message << '\n';
}
catch (...) {
std::cout << "***** UNKNOWN ERROR. Program terminating.\n";
}
std::cout << "Done.\n\n";
}