This is cross-platform example source code showing how to use the file loading and exporting functionality of AxsunOCTCapture in a C++ client application. It uses the traditional polling approach to retrieve images from the Main Image Buffer.
#include <iostream>
#include <filesystem>
#include <algorithm>
#include <vector>
class AxsunOCTCapture {
private:
public:
AxsunOCTCapture(
float 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; }
};
void ExportCallback(int32_t image, void* userdata) {
if (!(image % 50))
std::cout << "Export Callback: Image # " << image << "\n";
}
int main(int argc, char* argv[]) {
char message[512]{""};
if (argc != 2) {
std::cout << "**** Please pass one argument: the path to a valid data file. ****\n";
return 0;
}
try {
std::cout << "Welcome to the AxsunOCTCapture Load & Export Example Application.\n";
auto AOC = AxsunOCTCapture{ 250.0f };
auto loadfile = std::filesystem::path(argv[1]);
auto parent_dir = loadfile.parent_path();
auto export_dir = parent_dir / "Exported";
std::cout << "Loading file at " << loadfile << "\n";
auto tempnumber = int32_t{ 0 };
if (
auto retval =
axLoadFile(AOC(), loadfile.string().c_str(), &tempnumber); retval != AxErr::NO_AxERROR)
throw retval;
std::cout << "Loaded " << tempnumber << " packets from disk.\n";
uint32_t imaging{ 0 }, last_packet{ 0 }, last_frame{ 0 }, last_image{ 0 }, dropped_packets{ 0 }, frames_since_sync{ 0 };
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";
.crop_width_total = 2000
};
constexpr auto buffer_size = size_t{ 2048 * 2000 * 4 };
auto image_buffer = std::vector<uint8_t>(buffer_size);
for (auto i = 1; i <= last_image; ++i) {
if (
auto retval =
axGetImageInfo(AOC(), i, &info); retval != AxErr::NO_AxERROR) {
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 (!(i % 50)) {
std::for_each_n(image_buffer.begin(), 10, [](const auto& x) {std::cout << "\t" << +x; });
std::cout << "\n";
}
}
}
.crop_width_total = 700
};
.height = 480,
.contrast = 1.0,
.brightness = 0.0,
.colormap = AxColormap::SEPIA,
.movie_fps = 60
};
if (
auto retval =
axExportImagesAdv(AOC(), export_dir.string().c_str(), &tempnumber,
AxFileType::PNG, 1, last_image, 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";
}
AxErr
Error codes returned from AxsunOCTCapture or AxsunOCTControl_LW functions. Use axGetErrorString() in ...
Definition: AxsunCommonEnums.h:40
This header file contains all exported function prototypes, structures, and enums necessary for integ...
AxErr __cdecl axGetImageInfo(AOChandle session, uint32_t requested_image, image_info_t *image_info)
Get information on an image in the Main Image Buffer.
struct CaptureSession * AOChandle
Axsun OCT Capture handle - a pointer to the opaque structure used to manage created capture sessions.
Definition: AxsunOCTCapture.h:170
AxErr __cdecl axStopSession(AOChandle session)
Stop a capture session and deallocate all resources, including Main Image Buffer and interfaces.
AxErr __cdecl axExportImagesAdv(AOChandle session, const char *path_directory, int32_t *images_exported, AxFileType file_type, uint32_t start_image, uint32_t end_image, request_prefs_t request_prefs, export_prefs_t export_prefs)
Export images from the Main Image Buffer into individual graphics and movie files,...
AxErr __cdecl axRegisterExportCallback(AOChandle session, AxCallbackFunction_t callback_function, void *user_data)
Registers a callback function to be executed each time an image is exported using axExportImages(),...
AxErr __cdecl axStartSession(AOChandle *session, float capacity_MB)
Start an Axsun DAQ imaging session by allocating memory for the Main Image Buffer.
AxErr __cdecl axLoadFile(AOChandle session, const char *path_file, int32_t *packets_read)
Load contents from file on disk into Main Image Buffer.
AxErr __cdecl axRequestImage(AOChandle session, uint32_t requested_image, request_prefs_t prefs, uint32_t output_buf_len, uint8_t *image_data_out, image_info_t *image_info)
Retrieve and/or display an image from the Main Image Buffer.
@ RETRIEVE_TO_CALLER
Definition: AxsunOCTCapture.h:225
AxErr __cdecl axGetStatus(AOChandle session, uint32_t *imaging, uint32_t *last_packet_in, uint32_t *last_frame_in, uint32_t *last_image_in, uint32_t *dropped_packets, uint32_t *frames_since_sync)
Get imaging mode status and Main Image Buffer statistics.
void __cdecl axGetErrorString(AxErr errorcode, char *message_out)
Get a description of a specific AxErr error code.
@ PNG
Definition: AxsunOCTCapture.h:211
Structure for image export preferences (movie functionality requires installation of OpenCV).
Definition: AxsunOCTCapture.h:419
uint32_t width
Definition: AxsunOCTCapture.h:421
Structure for conveying metadata information about an image.
Definition: AxsunOCTCapture.h:452
Structure for image request preferences.
Definition: AxsunOCTCapture.h:386
uint32_t average_number
Definition: AxsunOCTCapture.h:393
AxRequestMode request_mode
Definition: AxsunOCTCapture.h:389