graphics opencv video vision

OpenNI 2.x and OpenCV interoperability [w/ code]

A simple wrapper around OpenNI 2.x drives for interoperability with OpenCV

For those of you using OpenCV that are looking to upgrade from OpenNI 1.x to the new OpenNI 2.x, here’s a bit of code to make life a tiny bit easier. It simply wraps the OpenNI 2.x APIs to expose a simple frame grabber for OpenCV.

The usage is very simple:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
#include "OpenNI2OpenCVInterop.h"
int main(int argc, char** argv) {
    OpenNIOpenCVInterop::OpenNI2OpenCVInterop oni;
    if(oni.init() != openni::STATUS_OK)
        return 1;
    Mat cam_depthGRAY, cam_rgb;
    while(true) {
        oni.GrabDepthAndRGB(cam_depthGRAY, cam_rgb);
        if(waitKey(30)==27) break;


Grab the code: here

2 replies on “OpenNI 2.x and OpenCV interoperability [w/ code]”

Hi Roy, I’m working with OpenNI2 and OpenCV and I have just came across your wrapper. By chance don’t you have a Windows version of it?
Thanks in advance

Yes, I also have the same use case as Matias, a platform independent version (or just a Windows version) would be really helpful.
Thanks 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *