Skip to content

Instantly share code, notes, and snippets.

@mickm
Created September 13, 2019 16:19
Show Gist options
  • Save mickm/cc653229e43d74be1dd50ad88227c952 to your computer and use it in GitHub Desktop.
Save mickm/cc653229e43d74be1dd50ad88227c952 to your computer and use it in GitHub Desktop.
astra fps test case
// usage:
// run this with the mini and stereo s and compare the fps in different light conditions
// the fps will drop on the stereo s in low light
// the mini maintains 30 fps in all lighting conditions
// seems like the autoexposure works differently (aperture priority vs shutter priority maybe?) on the stereo s vs the mini
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <astra/capi/astra.h>
#include <astra_core/capi/astra_types.h>
int main(int argc, char* argv[])
{
const char *default_connstr = "device/default";
char *connstr = (char *)default_connstr;
if (argc >= 2) {
connstr = argv[1];
}
astra_streamsetconnection_t sensor;
astra_reader_t reader;
astra_depthstream_t depthstream;
astra_colorstream_t colorstream;
uint32_t chip_id;
astra_imagestream_mode_t mode;
astra_frame_index_t last_frame_index = -1;
printf("connection string: %s\n", connstr);
astra_initialize();
astra_streamset_open(connstr, &sensor);
astra_reader_create(sensor, &reader);
astra_reader_get_depthstream(reader, &depthstream);
astra_reader_get_colorstream(reader, &colorstream);
astra_depthstream_get_chip_id(depthstream, &chip_id);
astra_imagestream_get_mode(depthstream, &mode);
if (chip_id == ASTRA_CHIP_ID_DUAL_MX6000) {
// stereo s - 640x400@30 fps depth
printf("chip id: DUAL MX6000 (Stereo S)\n");
mode.width = 640;
mode.height = 400;
mode.pixelFormat = ASTRA_PIXEL_FORMAT_DEPTH_MM;
mode.fps = 30;
} else if (chip_id == ASTRA_CHIP_ID_MX6000) {
// mini - 640x480@30 fps depth
printf("chip id: MX6000 (Mini)\n");
mode.width = 640;
mode.height = 400;
mode.pixelFormat = ASTRA_PIXEL_FORMAT_DEPTH_MM;
mode.fps = 30;
} else {
// ?
printf("chip id: unknown, trying 640x480@30 depth...\n");
mode.width = 640;
mode.height = 400;
mode.pixelFormat = ASTRA_PIXEL_FORMAT_DEPTH_MM;
mode.fps = 30;
}
astra_imagestream_set_mode(depthstream, &mode);
// all - 320x240@30 fps color
astra_imagestream_get_mode(colorstream, &mode);
mode.width = 320;
mode.height = 240;
mode.pixelFormat = ASTRA_PIXEL_FORMAT_RGB888;
mode.fps = 30;
astra_imagestream_set_mode(colorstream, &mode);
astra_stream_start(depthstream);
astra_stream_start(colorstream);
auto start = std::chrono::steady_clock::now();
double fps = 0.;
while (1) {
astra_update();
astra_reader_frame_t frame;
astra_status_t rc = astra_reader_open_frame(reader, 0, &frame);
if (rc == ASTRA_STATUS_SUCCESS) {
auto end = std::chrono::steady_clock::now();
double interval = std::chrono::duration_cast<std::chrono::duration<double> >(end - start).count();
start = end;
fps = interval == 0. ? 0. : 1./interval;
astra_depthframe_t depthframe;
astra_frame_get_depthframe(frame, &depthframe);
astra_frame_index_t new_frame_index;
astra_depthframe_get_frameindex(depthframe, &new_frame_index);
if (last_frame_index == new_frame_index) {
printf("duplicate frame index: %d\n", last_frame_index);
}
last_frame_index = new_frame_index;
printf("fps %.1f\n", fps);
astra_reader_close_frame(&frame);
}
}
astra_reader_destroy(&reader);
astra_streamset_close(&sensor);
astra_terminate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment