Skip to content

Instantly share code, notes, and snippets.

@atinfinity
Created September 29, 2016 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atinfinity/86664603b3141fc3e79cfd79eb1118ad to your computer and use it in GitHub Desktop.
Save atinfinity/86664603b3141fc3e79cfd79eb1118ad to your computer and use it in GitHub Desktop.
visionworks_demo
#include <VX/vx.h>
#include <VX/vxu.h>
#include <NVX/nvx.h>
#include <opencv2/core.hpp>
#include <iostream>
#define VX_SAFE_CALL(vxOp) \
do \
{ \
vx_status status = (vxOp); \
if(status != VX_SUCCESS) \
{ \
std::cout << " failure [status = " << status << "]" << " in file " << __FILE__ << " line " << __LINE__ << std::endl; \
} \
} while (0)
#define VX_ASSERT(cond) \
do \
{ \
bool status = (cond); \
if (!status) \
{ \
std::cout << " failure in file " << __FILE__ << " line " << __LINE__ << std::endl; \
} \
} while (0)
struct SGMParams
{
// disparity range
vx_int32 min_disparity;
vx_int32 max_disparity;
// discontinuity penalties
vx_int32 P1;
vx_int32 P2;
// SAD window size
vx_int32 sad;
// BT-cost clip value
vx_int32 bt_clip_value;
// validation threshold
vx_int32 max_diff;
vx_int32 uniqueness_ratio;
vx_enum scanlines_mask;
};
int main(int argc, char *argv[])
{
vx_context context = vxCreateContext();
vx_uint32 width = 1920;
vx_uint32 height = 1080;
vx_image vx_left = vxCreateImage(context, width, height, VX_DF_IMAGE_U8);
vx_image vx_right = vxCreateImage(context, width, height, VX_DF_IMAGE_U8);
vx_image vx_disparity = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);
SGMParams params;
params.min_disparity = 0;
params.max_disparity = 64;
params.P1 = 8;
params.P2 = 109;
params.sad = 5;
params.bt_clip_value = 31;
params.max_diff = 32000;
params.uniqueness_ratio = 0;
params.scanlines_mask = 255;
double f = 1000.0f / cv::getTickFrequency();
int64 start = 0, end = 0;
double time = 0.0;
const int loop_num = 5;
for (int i = 0; i <= loop_num; i++){
start = cv::getTickCount();
vx_status status = nvxuSemiGlobalMatching(
context,
vx_left,
vx_right,
vx_disparity,
params.min_disparity,
params.max_disparity,
params.P1,
params.P2,
params.sad,
params.bt_clip_value,
params.max_diff,
params.uniqueness_ratio,
params.scanlines_mask);
end = cv::getTickCount();
time += (i > 0) ? ((end - start) * f) : 0;
if (status != VX_SUCCESS){
goto error;
}
}
time /= loop_num;
std::cout << "time: " << time << " ms." << std::endl;
error:
VX_SAFE_CALL(vxReleaseImage(&vx_left));
VX_SAFE_CALL(vxReleaseImage(&vx_right));
VX_SAFE_CALL(vxReleaseImage(&vx_disparity));
VX_SAFE_CALL(vxReleaseContext(&context));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment