简体   繁体   中英

Zed Camera - Get data in c++ with openCV

I used with Zed-Camera for get depth ( https://www.stereolabs.com/ ). I want to get the data in c++ (using the OpenCV library).

I took the code from here: https://www.stereolabs.com/blog/index.php/2015/06/28/zed-with-opencv/

The code on the website is not working, because one line does not compile:

sl::zed::ERRCODE err = zed->init(sl::zed::MODE::PERFORMANCE, 0, true);

I get 2 errors:

  1. initial value of reference to non-const must be an lvalue

  2. too many arguments in function call.

I looked in the function, the function get:

ERRCODE init(InitParams &parameters);

I would appreciate your help

Yes as you can see the parameters was changed to InitParams.

sl::zed::InitParams params;
params.verbose = true;
sl::zed::ERRCODE err = camera->init(params);

You can do something similar to this.

m_pZed = new sl::Camera();
sl::InitParameters zedInit;
zedInit.camera_buffer_count_linux = 4;
zedInit.camera_disable_self_calib = false;
zedInit.camera_fps = m_zedFPS;
zedInit.camera_image_flip = m_bZedFlip;
zedInit.camera_linux_id = 0;
zedInit.camera_resolution = (sl::RESOLUTION) m_zedResolution;
zedInit.coordinate_system = sl::COORDINATE_SYSTEM::COORDINATE_SYSTEM_IMAGE;
zedInit.coordinate_units = sl::UNIT::UNIT_METER;
zedInit.depth_minimum_distance = m_zedMinDist;
zedInit.depth_mode = (sl::DEPTH_MODE) m_zedDepthMode;
zedInit.sdk_gpu_id = -1;
zedInit.sdk_verbose = true;

sl::ERROR_CODE err = m_pZed->open(zedInit);
if (err != sl::SUCCESS)
{
    LOG(ERROR)<< "ZED Error code: " << sl::errorCode2str(err) << std::endl;
    return false;
}

m_pZed->setConfidenceThreshold(m_zedConfidence);
m_pZed->setDepthMaxRangeValue((float) m_zedMaxDist);

// Set runtime parameters after opening the camera
m_zedRuntime.sensing_mode = (sl::SENSING_MODE) m_zedSenseMode;
m_zedRuntime.enable_depth = true;
m_zedRuntime.enable_point_cloud = false;
m_zedRuntime.move_point_cloud_to_world_frame = false;

// Create sl and cv Mat to get ZED left image and depth image
sl::Resolution zedImgSize = m_pZed->getResolution();

// Initialize color image and depth
m_width = zedImgSize.width;
m_height = zedImgSize.height;
m_centerH = m_width / 2;
m_centerV = m_height / 2;

// Best way of sharing sl::Mat and cv::Mat :
// Create a sl::Mat and then construct a cv::Mat using the ptr to sl::Mat data.

m_pzDepth = new sl::Mat(zedImgSize, sl::MAT_TYPE_32F_C1, sl::MEM_GPU);
m_gDepth = slMat2cvGpuMat(*m_pzDepth);
m_gDepth2 = GpuMat(m_gDepth.size(), m_gDepth.type());

More details can be found here( https://github.com/yankailab/OpenKAI/blob/master/src/Vision/_ZED.cpp )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM