PointSpread® Vidu™ Software Development Kit  V1
Vidu SDK
Code Sample

Generate executable samples To run the code samples, use CMake Tool to generate executable samples of Vidu SDK::

>>> #under ViduSdk
>>> mkdir build && cd build
>>> cmake ../
>>> make -j
>>> ./example/streamShow

Get Camera Parameters

#include "GenICam/GenTL.h"
#include "basic/inc/camParaDef.h"
#include "debug.h"
#include "inc/PDdevice.h"
#include "inc/PDstream.h"
#include "stringFormat.h"
int main()
{
PDdevice devInst;
intrinsics intrin;
extrinsics extrin;
if (devInst.init())
{
size_t streamNum = devInst.getStreamNum();
for (int i = 0; i < streamNum; i++)
{
PDstream streamInst(devInst, i);
streamInst.init();
PD_INFO("stream : %s\n", streamInst.getStreamName().c_str());
if (streamInst.getCamPara(intrin, extrin))
{
print_intrinsics(&intrin);
print_extrinsics(&extrin);
}
}
return system("pause");
}
return 0;
}
GenICam Transport Layer Client Interface.

We first initialize a PDdevice object named as devInst, and retrieve its streamNum through the member function PDdevice::getStreamNum(). Then we use the devInst and stream index starting from 0 to streamNum - 1, to instantiate the stream class PDstream's object streamInst. Each stream physically corresponds to an RGB or ToF pipeline that has its optics, sensors and ISPs. As a result, each stream has its intrinsics and extrinsics. We call the PDstream class's member function PDstream::getCamPara to retrieve the intrinsics and extrinsics. Finally, we print them with the wrapped function print_intrinsics and print_extrinsics correspondingly.

RGB Streaming Demo

Below lists the code to grab and show the RGB image captured by the Okulo P1 camera.

#include "inc/PDdevice.h"
#include "inc/PDstream.h"
#include "stringFormat.h"
#include "timeTest.h"
#include <chrono>
#include <thread>
int rgbDemo()
{
PDdevice devInst;
if (devInst)
{
auto stream = PDstream(devInst, "RGB");
if (stream)
{
bool isAutoExposure = false;
stream.get("AutoExposure", isAutoExposure);
if (isAutoExposure)
{
stream.set("AutoExposure", false);
}
stream.set("Exposure", 1.0f);
stream.set("Gain", 1.0f);
while (1)
{
auto frame = stream.waitFrames();
char key = cv::waitKey(1);
if (frame)
{
const cv::Mat &rgb = frame->getMat(0);
cv::imshow("rgb", rgb);
if (key == 'c')
{
GenTL::PDBufferSave(*frame, nullptr, 0);
printf("saved \n");
}
}
if (key == 'q')
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
return true;
}
}
return false;
}
GC_API PDBufferSave(BUFFER_HANDLE hBuffer, const char *filesName, int opt)
Write the buffer to disk.

We instantiate the rgb stream with PDdevice devInst and the string name RGB. Once the stream object is successfully created (not a null pointer), we set the exposure mode, exposure time and ADC gain through stream.set() function. Then, we unterminatedly invoke stream.waitFrames() to refresh the current frame and use cv::imshow() to draw it in a window. Furthermore, with the "rgb" window selected, once clicking the keyboard's c key, we will save an RGB frame to disk.

Pointcloud Streaming Demo

#include "inc/PDdevice.h"
#include "inc/PDstream.h"
#include "stringFormat.h"
#include "timeTest.h"
#include <chrono>
#include <thread>
int pclDemo()
{
PDdevice devInst;
if (devInst)
{
auto pclstream = PDstream(devInst, "PCL");
if (pclstream)
{
bool isTofAutoExposure = false;
bool isRGBAutoExposure = false;
pclstream.get("ToF::AutoExposure", isTofAutoExposure);
pclstream.get("RGB::AutoExposure", isRGBAutoExposure);
if (isTofAutoExposure)
{
pclstream.set("ToF::AutoExposure", false);
}
if (isRGBAutoExposure)
{
pclstream.set("RGB::AutoExposure", false);
}
pclstream.set("ToF::Distance", 7.5f);
pclstream.set("ToF::StreamFps", 50.0f);
pclstream.set("ToF::Threshold", 100);
pclstream.set("ToF::Exposure", 1.0f);
pclstream.set("RGB::Exposure", 10.0f);
pclstream.set("RGB::Gain", 20.0f);
bool saveReq = false;
int count = 0;
float DistRange = 0.0f;
while (1)
{
// pcl frames work only when tof && rgb stream grab frames!!!
auto pPclFrame = pclstream.waitFrames();
char key = cv::waitKey(1);
if (key == 'c')
{
saveReq = true;
}
if (key == 'q')
{
break;
}
if (pPclFrame)
{
if (DistRange < 1e-5) // DistRange should be inited
{
size_t varSize = sizeof(varSize);
GenTL::PDBufferGetMetaByName(pPclFrame->getPort(),
"Range", &DistRange,
&varSize, nullptr);
printf("max distance %f for distanceMap\n", DistRange);
}
const cv::Mat &xyz = pPclFrame->getMat(0);
const cv::Mat &infrared = pPclFrame->getMat(1);
const cv::Mat &color = pPclFrame->getMat(2);
std::vector<cv::Mat> channels(3);
cv::split(xyz, channels);
const cv::Mat &depth = channels[2];
cv::Mat u16Depth;
depth.convertTo(u16Depth, CV_16UC1, 65535.0 / DistRange);
cv::imshow("xyz", xyz);
cv::imshow("infrared", infrared);
cv::imshow("color", color);
cv::imshow("depth", depth);
if (saveReq)
{
saveReq = false;
GenTL::PDBufferSave(*pPclFrame, nullptr, 0);
cv::imwrite(stringFormat("depth-%d.png", count), u16Depth);
printf("saved \n");
count++;
}
}
pPclFrame.reset(); // release frame buffer immediately
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
return true;
}
}
return false;
}
GC_API PDBufferGetMetaByName(BUFFER_HANDLE hBuffer, const char *varName, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize)
Get stream metadata information of the buffer.

We show the code for the streaming of Point-Cloud, in this application, we need to use both RGB and ToF streams to support color mapping to 3D space. We directly, instantiate the pclstream with PDstream(devInst, "PCL"), and the PCL string name will be recognized.