The third version of the kinect application series based on the Dragonboard 410c - an example of obtaining a depth map

In the last article, we introduced the SimpleOpenNI development platform. Today, Xiaobian continues to explain the specific operation process of drawing depth maps and drawing human torso instances with kinect!

First, draw a depth map with kinect

Kinect+OpenNI allows the user to obtain depth images, one infrared emitter is responsible for emitting infrared and the other is responsible for accepting, so that we get how many pixels from the camera, ie how far.

Every project in processing is called sketch instead of the general software Project. Because the Processing program runs more like a sketch drawn by the painter on paper, the sketch is obvious.

In order to display the depth map on the computer and get the data the user wants, we must import OpenNI in order to import and package the OpenNI data, so first import the data package (the idea of ​​the library).

-------------------------------------------------- ------

Import SimpleOpenNI.*;

-------------------------------------------------- -------

Next we declare a global object, context and Kinect to get data contact

-------------------------------------------------- ------

SimpleOpenNI context;

-------------------------------------------------- -------

Next, let's take a look at the setup() function. One thing to know is that all the contents of the setup() function are executed only once, and only the first stage of the program is executed.

-------------------------------------------------- ------

Void setup()

{

// Create a new object

Context = new SimpleOpenNI(this);

// enable depth impact

context.enableDepth();

// Create a size that guarantees all the information about the depth

Size(context.depthWidth(), context.depthHeight());

}

-------------------------------------------------- -------

Next, let's take a look at the function in Draw(). There is a draw() function, which runs in an infinite loop with a frequency of 60 times per second.

-------------------------------------------------- -----

Void draw()

{

//Continuously update data from Kinect Camera

Context.update();

// draw a depth map

Image(context.depthImage(),0,0);

}

-------------------------------------------------- -------

The Context.update() function updates the data for each frame.

The result of running the sketch is as shown:

The result of running sketch

The code is resolved as follows:

Import SimpleOpenNI.*;

SimpleOpenNI context;

Void setup()

{

// instanTIate a new context

Context = new SimpleOpenNI(this);

// enable depth image generaTIon

context.enableDepth();

// create a window the size of the depth informaTIon

Size(context.depthWidth(), context.depthHeight());

}

Void draw()

{

// update the camera

Context.update();

// draw depth image

Image(context.depthImage(),0,0);

}

-------------------------------------------------- -------------------

If you know the depth information, what do you think?

This question is worth it here. Think carefully. What are you going to do?

Or now you don't have much thought, but in the next case I ask you to have your own ideas, even if you don't code.

Second, draw the human torso

First of all, first spread the knowledge, there is knowledge about 3D space distance calculation,

In the three D space, the calculation of the distance, and the vector calculation we have in high school is a reason, the following from the 2D space:

X1=2 X2=9

The line consists of two points and the coordinates are given in the figure above.

---------------------------------- (Right-angle relationship)

-------------------------------- (coordinate distance representation of a)

---------------------------------(coordinate distance representation of b)

-- (also in line with the relationship of the triangle side)

-------- (transition to 2D space distance)

The key is the 3D space distance, plus a Z coordinate

The above formula is the formula between points in 3D space.

So how to calculate the distance between two points in the 3D space in the code.

First, define a new function

distances3D( )

Void distance3D(PVector point1, PVector point2)

{

}

First in the function we need to add some variables to store the values ​​of x, y and z. We also need a variable to store the final result, which is the return value.

Float diff_x, diff_y, diff_z; // store the values ​​of x, y, z

Float distance; // to store the last return value (result is the distance)

Next, calculate the difference between x, y, and z between two points.

Diff_x = point1.x - point2.x;

Diff_y = point1.y - point2.y;

Diff_z = point1.z - point2.z;

After that is a simple calculation

Return distance; // return the distance as a float

The code after finishing is:

Float distance3D(PVector point1, PVector point2

){

Float diff_x, diff_y, diff_z;

Float distance;

Diff_x = point1.x - point2.x;

Diff_y = point1.y - point2.y;

Diff_z = point1.z - point2.z;

Distance = sqrt(pow(diff_x,2)+pow(diff_y,2)+pow(diff_z,2));

Return distance;

}

After writing the program, the result of the operation is the depth map and the shape of the human torso, where black is post-processed and the human body color is also processed.

Successful operation

Third, look forward to thinking

Don't be indifferent after reading this example, this time you must have good ideas, such as you want to get keyboard mapping, manipulate the keyboard, get mouse mapping, control the mouse, or directly get the graphics map and control the graphics changes, maybe you can Write a fun game.

This topic will be put aside first, and the platform of the Snake Snake will be very simple, so we must try it in the future. The final result is: use gestures to control the direction of the snake to control the snake to eat more food.

The basic tutorial is done here, and the basic tutorial is finished. Please look forward to the next few updates!

Lithium Batteries

Lithium Batteries 72V,Lithium Batteries 200A Rechargeable,Customized Rechargeable Lithium Battery,Lithium Ion Battery

Shaoxing Honyo International Trading Co., Ltd , https://www.honyopower.com

Posted on