Obi Zhongguang VisualStdio 2019 documentation , I wrote this a few days ago. I didn't compile it. I'll write it today.
https://developer.orbbec.com.cn/download.html?id=65
SDK download location, download, unzip and remember the path

These are the Demo for. Let's use one

Create an empty project

Create a new CPP file
#include <stdio.h> #include <OpenNI.h> #include "OniSampleUtilities.h" #define SAMPLE_READ_WAIT_TIMEOUT 2000 //2000ms using namespace openni; int main(int argc, char* argv[]) { //initialize openni sdk Status rc = OpenNI::initialize(); if (rc != STATUS_OK) { printf("Initialize failed\n%s\n", OpenNI::getExtendedError()); return 1; } Device device; //open device rc = device.open(ANY_DEVICE); if (rc != STATUS_OK) { printf("Couldn't open device\n%s\n", OpenNI::getExtendedError()); return 2; } VideoStream depth; //create depth stream if (device.getSensorInfo(SENSOR_DEPTH) != NULL) { rc = depth.create(device, SENSOR_DEPTH); if (rc != STATUS_OK) { printf("Couldn't create depth stream\n%s\n", OpenNI::getExtendedError()); return 3; } } //start depth stream rc = depth.start(); if (rc != STATUS_OK) { printf("Couldn't start the depth stream\n%s\n", OpenNI::getExtendedError()); return 4; } VideoFrameRef frame; while (!wasKeyboardHit()) { int changedStreamDummy; VideoStream* pStream = &depth; //wait a new frame rc = OpenNI::waitForAnyStream(&pStream, 1, &changedStreamDummy, SAMPLE_READ_WAIT_TIMEOUT); if (rc != STATUS_OK) { printf("Wait failed! (timeout is %d ms)\n%s\n", SAMPLE_READ_WAIT_TIMEOUT, OpenNI::getExtendedError()); continue; } //get depth frame rc = depth.readFrame(&frame); if (rc != STATUS_OK) { printf("Read failed!\n%s\n", OpenNI::getExtendedError()); continue; } //check if the frame format is depth frame format if (frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_1_MM && frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_100_UM) { printf("Unexpected frame format\n"); continue; } DepthPixel* pDepth = (DepthPixel*)frame.getData(); int middleIndex = (frame.getHeight() + 1) * frame.getWidth() / 2; //print the depth value of the middle pixel of the frame printf("[%08llu] %8d\n", (long long)frame.getTimestamp(), pDepth[middleIndex]); } //stop depth stream depth.stop(); //destroy depth stream depth.destroy(); //close device device.close(); //shutdown OpenNI OpenNI::shutdown(); return 0; }
Copy my code in
Then start configuring the library, or the location of the header.

It mainly indicates these places

Project - > Properties

SDK content

What does the downloaded SDK look like

Configure this at the beginning

Add two directories
C:\orbbec\Windows_V2.3.0.66\windows\Samples\samples\Common C:\orbbec\Windows_V2.3.0.66\windows\SDK\x64\Include

common is the header file of this

This adds the library

Link library - > General


Add the path of DLL file

Then the input

Write this

Remember to click the app!!! Otherwise, you can't save your settings

If you do not save, an error will be reported

If you configure it correctly, there are no wavy lines in these places

F12

It can be opened

Look at our device manager

We can compile it now. It should not report errors and pass the compilation
If it runs, you need to add something.
C:\orbbec\Windows_V2.3.0.66\windows\Samples\bin_x64
Open the bin location of an SDK

These are

Then you open the current project location

Copy it

Operation results
It seems that you want to copy the past and compile... I think I'm in the wrong order...

Make a breakpoint

Look at the content

result
https://developer.orbbec.com.cn/technical_library/OpenNI2/html/autotoc_md25.html
Let's take a look at the meaning of the program. The above is the location of the demo

Let's first look at the introduction of three header files
Then there is a macro with a time of 2000ms
Here is a namespace, namespace

This is introduced in the header file of OponNI2, where I refer to the namespace

The initialization method is used for the device at the beginning, and then the return value is determined
To determine if the equipment is ready


This is the correct and wrong definition position

This initialization method

These are possible error values

After the above is completed, start creating a device object

This is the location

Turn on the device, if ok

Then a video streaming device is created. If the device information above is not empty. Then execute the following statement to create a device and add two parameters, one is the device at that time and the color information.

Look at the code written by others. It's really delicious. This is the industrial code, compatibility MAX

See for yourself, the depth flow is 3

The following is the established object

Color transfer started!

I didn't look at it very carefully

Xiao Zhang really can't understand it here. It's the function inside

Then continue to enter


Get stuck

Next, wait a frame and look at this function

The second parameter is the flow count

Look at the flow of this parameter. It's interesting

These are some incorrect structure encapsulation information

Get a color frame

Look at this frame reading function

The format of mode + pixel then matches the following string
Look down

Look at this function


colour

Let's take another look at this initialization



It all points to a structure

Maybe so

Then print it by component

This is the pixel structure

Stop the color stream, destroy the color stream object, turn off the device, turn off OpenNI, and send 0 to SYS
