C/C++
Xvisio SDK Documentation Home Page

all_stream


1 Overview

"all_stream" demonstrates all the basic functions of Xvisio device and the corresponding SDK API, which also provides the sample code that corresponds to the execution function.

2 Build and Run

2.1 Linux/Ubuntu

2.1.1 Build Cmake
  1. Install Xvisio SDK in host Linux/Ubuntu. Refer to SDK Install Guide
  2. Start the terminal and navigate to the installation path ("/usr/share/xvsdk/all_stream") of all_stream , or copy "/usr/share/xvsdk/all_stream" to work directory and then navigate to “all_stream".
    cp -r /usr/share/xvsdk/all_stream <path_to_work>
    cd <path_to_work>/all_stream
  3. Cmake generates Makefile
    mkdir build
    cd build
    cmake ..
  4. Build
    make
    A successful build will generate an executable binary program called "all_stream".
2.1.2 Run
  1. Connect Xvisio device with Ubuntu host via USB cable.
  2. Check USB status, open terminal and input:
    lsusb
    Observe the terminal output usb status information where VID:PID is "040e:f408", and "MCCI XVisio vSLAM" indicates Xvisio device.
    Confirm that the current device enumeration is USB3.0 or USB2.0 by the USB Bus number of the Xvisio device and the corresponding BUS HUB type.
    Please ensure proper enumeration of Xvisio device
    The above description is shown in the following figure:
    image
  3. Start the terminal and navigate to <path_to_work>/all_stream/build
    ./all_stream
    Before performing this step, you need to ensure that the program has been successfully built and generated an executable binary program named "all_stream".
    After opening successfully, all function screens supported by the Xvisio device will be displayed.
    image

2.2 Windows10/11

2.2.1 Build
  1. Install Xvisio SDK in Windows host. Refer to SDK Installation Guide
  2. Enter into example catalog "all_stream" after SDK installed successfully. For example:C:\Program Files\xvsdk\samples\all_stream.
  3. Compile with visual studio
  1. "cmake" to generate file "sln".
  • Start tool "windows powershell" and navigate to "all_stream" catalogue.
  • Execute the corresponding generate project command according to the current visual studio version:
    Version cmake commands
    VS2019 6bit cmake -G "Visual Studio 16 2019" -A x64
    VS2019 32bit cmake -G "Visual Studio 16 2019" -A Win32
    VS2017 64bit cmake -G "Visual Studio 15 2017" -A x64
    VS2017 32bit cmake -G "Visual Studio 15 2017" -A Win32
  • Catalogue "all_stream" will generate file "all_stream.sln"
  • Open "all_stream.sln" with visual studio.
  • "all_stream.exe" will be generated in the corresponding directory once build successfully.
2.2.2 Run
  1. Connect Xvisio device with Windows host via USB cable.
  2. Connect the Xvisio device to PC via USB cable. Three devices should be listed if the Xvisio device is connected normally. You can check the device status through the device manager of the system:
    image
    Please check status of "VSC interface","XVisio vSLAM" or "USB Composite Device" if error appears. If the status is abnormal, please check whether the USB cable and Xvisio device firmware are normal, or whether the USB status of the Windows host meets the requirements. or contact with Xvisio FAE for help
  3. Start tool "windows powershell" to navigate to the installation directory "bin", input the .exe name and press "Enter":
    ./all_stream.exe
    After opening successfully, all function screens supported by the Xvisio device will be displayed.
    image

3 Code Introduction

3.1 Directory

Platform Directory
Windows Installation directory samples\all_stream,for example:C:\Program Files\xvsdk\samples\all_stream\
Linux/Ubuntu /usr/share/xvsdk/all_stream/

3.2 File

File Description
all_stream.cpp all_stream main file
fps_count.hpp Class implementation file for calculating frame rate
raw2opencv.cpp Dependent opencv implementation file
CMakeLists.txt Cmake project file (valid with Android platform)

3.3 Code Analysis and Introduction

"main(....)" is entry function in file "all_stream":

int main( int argc, char* argv[] ) try

"enableDevMap" controls the enable functions of "all_stream":

static std::map<std::string,int> enableDevMap;
enableDevMap["rgb"] = true;
enableDevMap["tof"]= true;
enableDevMap["fisheye"] = true;
enableDevMap["sgbm"] = true;
enableDevMap["slam"] = true;
enableDevMap["slam_edge"] = true;
enableDevMap["imu"] = true;
enableDevMap["eyetracking"] = true;
enableDevMap["sync"] = false;
enableDevMap["dewarp"] = true;
enableDevMap["VGA"] = true;
enableDevMap["720P"] = false;
enableDevMap["tof_mode"] = 3;//default lablize sf
enableDevMap["tof_point_cloud"] = false;
enableDevMap["log"]=true;
enableDevMap["ir"]=true;

The device description information can be set by adjusting the run-time parameters to control enable/disable function,see section 4 for a detailed description(Character control description):

if (argc >1 && *argv[1]!='\0') {
  std::ifstream ifs( argv[1] );
  if( !ifs.is_open() ){
    std::cerr << "Failed to open: " << argv[1] << std::endl;
  }
  else
  {
    std::stringstream fbuf;
    fbuf << ifs.rdbuf();
    json = fbuf.str();
  }
}

if (argc == 3)
{
  std::string enableDevStr(argv[2]);
  enableDevStr+=" ";
  int index,index2;
  while(true)
  {
    index = enableDevStr.find(' ');
    if(index == std::string::npos)
    {
      break;
    }
    auto one = enableDevStr.substr(0,index);
    index2 = one.find('':'');
    auto key = one.substr(0,index2);
    auto value = one.substr(index2+1,one.size()-index2-1)=="1"true:false;
    enableDevStr = enableDevStr.substr(index+1);
    std::cout<<key<<" : "<<value<<std::endl;
    enableDevMap[key] = value;
  }
}

Examples:

./all_stream test.json "rgb:1 tof:0 tof_mode:3"

Input control instruction, see section 4 for a detailed description(Character control description):

while(true)
{
  if(res == xv::FisheyeCamerasEx::ResolutionMode::MEDIUM)
    std::cerr << "ENTER 'f' to switch FE to HIGH res" << std::endl;
  else
    std::cerr << "ENTER 'f' to switch FE to MEDIUM res" << std::endl;
  if(sgbm_ctl == true){
    std::cerr << "ENTER 's' to stop SGBM to res" << std::endl;
    std::cerr << "ENTER 'r' to modify SGBM resolution" << std::endl;
  }
  else{
    std::cerr << "ENTER 's' to start SGBM to res" << std::endl;
  }
  std::cerr << "ENTER 'q' to exit" << std::endl;
  std::cin >> getkey;
  //getkey = std::cin.get();
  if(getkey == "f")
  {
    res = (res == xv::FisheyeCamerasEx::ResolutionMode::MEDIUM)?(xv::FisheyeCamerasEx::ResolutionMode::HIGH):(xv::FisheyeCamerasEx::ResolutionMode::MEDIUM);
    std::cout<<"device->fisheyeCameras())->setResolutionMode:"<<static_cast<int>(res)<<std::endl;
    std::dynamic_pointer_cast<xv::FisheyeCamerasEx>(device->fisheyeCameras())->setResolutionMode(res);
  }
  else if(getkey == "s")
  {
    if(sgbm_ctl == false)
    {
      std::cout<<"device->sgbmCamera()->start(global_config)"<<static_cast<int>(res)<<std::endl;
      device->sgbmCamera()->start(global_config);
    }
    else
    {
      std::cout<<"device->sgbmCamera()->stop()"<<static_cast<int>(res)<<std::endl;
      device->sgbmCamera()->stop();
    }
    sgbm_ctl = !sgbm_ctl;
  }
  else if(getkey == "r")
  {
    sgbmres = (sgbmres == xv::SgbmCamera::Resolution::SGBM_640x480) ?   xv::SgbmCamera::Resolution::SGBM_1280x720 :   xv::SgbmCamera::Resolution::SGBM_640x480;
    bool ret = device->sgbmCamera()->setSgbmResolution(sgbmres);
    if(ret){
      std::cout << "device->sgbmCamera()->setSgbmResolution: " << static_cast<int>(res)<<std::endl;
    }else{
      std::cout << "device->sgbmCamera()->setSgbmResolution failed"<<std::endl;
    }
  }
  else if(getkey == "q")
  {
    break;
  }
}

All the images in "all_stream" are all drawing by OpenCV. It draws corresponding images through different overloaded functions "raw_to_opencv" processes different data.

Drawing Fisheye data by OpenCV:

cv::Mat left;
cv::Mat right;
if (stereo) {
  auto const& leftInput = stereo->images[0];
  auto const& rightInput = stereo->images[1];
  if( leftInput.data != nullptr ){
    left = cv::Mat::zeros(leftInput.height, leftInput.width, CV_8UC1);
    std::memcpy(left.data, leftInput.data.get(), static_cast<size_t>(left.rowsleft.cols));
  }
  if( rightInput.data != nullptr ){
    right = cv::Mat::zeros(rightInput.height, rightInput.width, CV_8UC1);
    std::memcpy(right.data, rightInput.data.get(), static_cast<size_t>(right.rows
right.cols));
  }
} else {
  left = cv::Mat::zeros(400, 640, CV_8UC1);
  right = cv::Mat::zeros(400, 640, CV_8UC1);
}
cv::cvtColor(left, left, cv::COLOR_GRAY2BGR);
cv::cvtColor(right, right, cv::COLOR_GRAY2BGR);

Drawing according to feature points:

if (keypoints) {
  const int size = 2;
  int s=0;
  for(unsigned int i=0; idescriptors[s].size; i++ ){
    auto p = keypoints->descriptors[s].keypoints.get() + i*2;
    cv::Point pt(*p, (p+1));
    cv::line(left, pt - cv::Point(size,0), pt + cv::Point(size,0),     cv::Scalar(0,0,255) );
    cv::line(left, pt - cv::Point(0,size), pt + cv::Point(0,size),   cv::Scalar(0,0,255) );
  }
  s=1;
  for(unsigned int i=0; idescriptors[s].size; i++ ){
    auto p = keypoints->descriptors[s].keypoints.get() + i
2;
    cv::Point pt(*p, *(p+1));
    cv::line(right, pt - cv::Point(size,0), pt + cv::Point(size,0),     cv::Scalar(0,0,255) );
    cv::line(right, pt - cv::Point(0,size), pt + cv::Point(0,size),     cv::Scalar(0,0,255) );
  }
}

4 Character control description

Before all_stream starting, you can set runtime parameters to control whether the feature is enabled or disabled, as described below:

Parameters Default Value Remark
rgb true Adjust this parameter to enable or disable rgb
tof true Adjust this parameter to enable or disable tof
fisheye true Adjust this parameter to enable or disable fisheye
sgbm true Adjust this parameter to enable or disable sgbm
slam true Adjust this parameter to enable or disable slam
slam_edge true Adjust this parameter to enable Edge mode or Mixed mode if it is false
imu true Adjust this parameter to enable or disable imu
eyetracking true Adjust this parameter to enable or disable eyetracking
sync false This parameter determines whether to enable the synchronization mode. By default, the synchronization mode is disabled
dewarp true Adjust this parameter to determine whether image distortion is enabled. This parameter is enabled by default. If flat angle lenses are used, this parameter is not required
VGA true Adjust this parameter to set the fisheye camera resolution to VGA(640*400)
720P false Adjust this parameter to set the fisheye camera resolution to 720P(1280*720)
tof_mode 3 Adjust this parameter to set tof mode,IQMIX_DF = 0,IQMIX_SF = 1, LABELIZE_DF = 2,LABELIZE_SF = 3,M2MIX_DF = 4,M2MIX_SF = 5. By default is LABELIZE_SF mode
tof_point_cloud false Adjust this parameter to determine whether to obtain TOF point cloud data. The default value is not obtained
log true Adjust this parameter to determine whether to output log
ir true Adjust this parameter to enable or disable tof IR

Examples:

./all_stream test.json "rgb:0 tof:1 tof_mode:3"

Note that if the parameter is set to 1, it is true. If the other parameters are set to false, they must be separated by Spaces.

WHen all_stream is running, some functions can be controlled by typing characters:

Input key Function
f Switch fisheye resolution to 720P if currentyly is VGA, or VGA if it is 720P
s Controls the switch of the Sgbm camera. If the current sgbm camera is on, the switch is off. If the current sgbm camera is off, the switch is on
r Adjust the resolution of sgbm camera to 1280*720 if currently is 640*480, 640*480 if currently is 1280*720 (Note:function requires firmware support)
q Exit all_stream program

C/C++
Xvisio SDK Documentation Home Page