C++ API#
Please find a working example of the C++ API in our samples repository. The detailed API documentation can be found here. Please refer to the C++ Example for further details.
The main interfaces are ICamera and IFrameObserver, please refer to the sample below.
C++ Example#
The following minimal example shows how to use the C++ ICamera and IFrameObserver to configure the camera hardware device and attach to a camera stream. Setup and bring up should be done in a docker environment, the sample in the repository comes with ready-to-use docker and CMake files.
Setup and run#
Log into the camera (see OS section for details) and issue the following commands:
## clone the git sample repository from 3dvl gitlab server
git clone https://git.3dvisionlabs.com/3dvisionlabs/software/ecm/vl-samples.git
## enter c++ sample folder
cd vl-samples/cpp/streaming
## build docker image; build c++ executable and run in docker context
./run.sh
C++ code#
Main: the main program handles setup and configuration of the camera instance as well as the "outer logic", e.g. waiting for user-input before stopping the application. "Streaming mode", as outlined in the sample is the recommended way of handling the camera - asynchronously waiting for new camera images in the FrameObserver, and keeping the camera handle and config "idle" in the main tread, e.g. for handling new configurations.
The FrameObserver is called from the camera (frame-related thread) to process incoming images.
#include <iostream>
#include <vl/camera.h>
// the frame listener defines the callback function, called for
// processing each frame
class FrameObserver: public vl::IFrameObserver
{
public:
virtual void onFrameReceived(const vl::Frame &frame) override {
std::cout << "received image" << std::endl;
std::cout << " timestamp: " << frame.timestamp() << std::endl;
std::cout << " width: " << frame.image().width() << std::endl;
std::cout << " height: " << frame.image().height() << std::endl;
}
};
int main(int argc, char *argv[])
{
// create camera instance (the correct hardware / low-level API are set up automatically)
auto cam = vl::makeCamera();
// instantiate your own frame observer (image processor) observer
auto frameObserver = std::make_shared<FrameObserver>();
// set up (default) image settings (post-processing options) for the frame listener
auto imageSettings = std::make_shared<vl::ImageSettings>();
// add frame listener as camera output stream
cam->addStream(frameObserver), imageSettings;
// start capture loop
cam->start();
// wait for user input
std::string input;
std::cin >> input;
// stop capture loop
cam->stop();
return 0;
}