View my account

Converting depth frames to OpenCV Mat CV_16UC1 in Java on Android

Comments

3 comments

  • MartyG

    Hi Karim. The link below has an example of a Java depth frame to CV_16U1 conversion script.

    https://github.com/IntelRealSense/librealsense/issues/5185#issuecomment-550266254

    0
    Comment actions Permalink
  • Karim

    MartyX Grover Thanks for the rapid response! This solved my issue. In context, here is the working version of the prior code fragment:

    DepthFrame depth = f.as(Extension.DEPTH_FRAME);
    final float depthValue = depth.getDistance(depth.getWidth()/2, depth.getHeight()/2);
    deflector = depthValue;

    //extract depth data
    int size = depth.getDataSize();
    buffer = new byte[size];
    depth.getData(buffer);

    //transform the buffer to make it compatible with CV_16UC1
    short[] shorts = new short[size/2];
    ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts);

    //put the depth frame data into a Mat for further processing
    cvDepth = new Mat(depth.getHeight(),depth.getWidth(), CvType.CV_16UC1);
    cvDepth.put(0,0,shorts);
    0
    Comment actions Permalink
  • MartyG

    You are very welcome, Karim - it's great to hear that you were successful.  Thanks very much for sharing your code fragment with the RealSense community!

    0
    Comment actions Permalink

Please sign in to leave a comment.