#include <astra/astra.hpp>
#include <cstdio>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <key_handler.h>
{
private:
using buffer_ptr = std::unique_ptr<int16_t []>;
buffer_ptr buffer_;
unsigned int lastWidth_;
unsigned int lastHeight_;
public:
{
{
print_depth(depthFrame, depthStream.coordinateMapper());
check_fps();
}
}
{
{
int width = depthFrame.
width();
int height = depthFrame.
height();
if (width != lastWidth_ || height != lastHeight_)
{
buffer_ = buffer_ptr(
new int16_t[depthFrame.
length()]);
lastWidth_ = width;
lastHeight_ = height;
}
size_t index = ((width * (height / 2.0f)) + (width / 2.0f));
short middle = buffer_[index];
float worldX, worldY, worldZ;
float depthX, depthY, depthZ;
std::cout << "depth frameIndex: " << frameIndex
<< " value: " << middle
<< " wX: " << worldX
<< " wY: " << worldY
<< " wZ: " << worldZ
<< " dX: " << depthX
<< " dY: " << depthY
<< " dZ: " << depthZ
<< std::endl;
}
}
void check_fps()
{
const float frameWeight = 0.5;
auto newTimepoint = clock_type::now();
float frameDuration = std::chrono::duration_cast<duration_type>(newTimepoint - lastTimepoint_).count();
frameDuration_ = frameDuration * frameWeight + frameDuration_ * (1 - frameWeight);
lastTimepoint_ = newTimepoint;
double fps = 1.0 / frameDuration_;
auto precision = std::cout.precision();
std::cout << std::fixed
<< std::setprecision(1)
<< fps << " fps ("
<< std::setprecision(2)
<< frameDuration_ * 1000.0 << " ms)"
<< std::setprecision(precision)
<< std::endl;
}
private:
using duration_type = std::chrono::duration<float>;
float frameDuration_{ 0.0 };
using clock_type = std::chrono::system_clock;
std::chrono::time_point<clock_type> lastTimepoint_{clock_type::now()};
};
int main(int argc, char** argv)
{
set_key_handler();
SampleFrameListener listener;
char serialnumber[256];
depthStream.serial_number(serialnumber, 256);
std::cout << "depthStream -- hFov: "
<< " vFov: "
<< " serial number: "
<< serialnumber
<< std::endl;
const uint32_t chipId = depthStream.
chip_id();
switch (chipId)
{
case ASTRA_CHIP_ID_MX400:
std::cout << "Chip ID: MX400" << std::endl;
break;
case ASTRA_CHIP_ID_MX6000:
std::cout << "Chip ID: MX6000" << std::endl;
break;
case ASTRA_CHIP_ID_UNKNOWN:
default:
std::cout << "Chip ID: Unknown" << std::endl;
break;
}
std::cout <<
"usbInfo ---pid:" << usbinfo.
pid<<
" vid: "<< usbinfo.
vid<< std::endl;
do
{
astra_update();
} while (shouldContinue);
}
CoordinateMapper
Definition: Depth.hpp:40
Vector3f convert_world_to_depth(Vector3f worldPosition) const
convert depth coor to world coor
Definition: Depth.hpp:90
astra::Vector3f convert_depth_to_world(astra::Vector3f depthPosition) const
convert depth coor to world coor
Definition: Depth.hpp:72
void start()
start stream
Definition: DataStream.hpp:71
A Depth Frame
Definition: Depth.hpp:287
A Depth Stream
Definition: Depth.hpp:147
std::uint32_t chip_id() const
get chip id
Definition: Depth.hpp:243
Frame class
Definition: Frame.hpp:32
Frame Listener class
Definition: FrameListener.hpp:31
const int height() const
get height
Definition: Image.hpp:444
void copy_to(TDataType *buffer) const
copy to buffer
Definition: Image.hpp:507
const astra_frame_index_t frame_index() const
get frame index
Definition: Image.hpp:465
const size_t length() const
get length
Definition: Image.hpp:500
const int width() const
get width
Definition: Image.hpp:437
const bool is_valid() const
get is vaild
Definition: Image.hpp:430
Stream Reader class
Definition: StreamReader.hpp:39
void add_listener(FrameListener &listener)
add listener
Definition: StreamReader.hpp:87
void remove_listener(FrameListener &listener)
remove listener
Definition: StreamReader.hpp:101
Stream Set Class
Definition: StreamSet.hpp:36
astra_status_t terminate()
Terminate the library, destroying all its streams.
Definition: astra_core.hpp:45
astra_status_t initialize()
Initializes the library.
Definition: astra_core.hpp:35
Definition: astra_ctypes.h:44