← C/C++
← Xvisio SDK Documentation Home Page
"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.
cp -r /usr/share/xvsdk/all_stream <path_to_work>
cd <path_to_work>/all_stream
mkdir build
cd build
cmake ..
make
lsusb
./all_stream
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 |
./all_stream.exe
Platform | Directory |
---|---|
Windows | Installation directory samples\all_stream,for example:C:\Program Files\xvsdk\samples\all_stream\ |
Linux/Ubuntu | /usr/share/xvsdk/all_stream/ |
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) |
"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.rowsright.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++ ){ 2;
auto p = keypoints->descriptors[s].keypoints.get() + i
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) );
}
}
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 |