KinectPV2: get and import obj files


#1

Hi all!
I’m a beginner in Processing and my boss asked me to interface Kinect for XBOX ONE (or Kinect V2) to PC for record pointclouds’ videos (nothing easier…) and to record some coloured frames of a moving arm of a person.

I’ve found KinectPV2 libraries on GitHub and in one of examples I’ve found a Sketch (RecordPointCloud) to record frame and get it as OBJ files.
It’s not like a video, but works very well and with a Blender’s addon I can create a OBJ Sequence that is like a video.

For the second part, I tried to import these OBJ frames in Processing with an example in Basic/Shape folder (LoadDisplayOBJ) to avoid a second program and use only Processing.
But when I start the Sketch…there is nothing in the window.

In blender I can see the pointclouds, but if I import a frame in Processing or in another 3D program (like 3D Build) they don’t show me nothing.

Why?
There’s a better way to import OBJ in Processing? Or a better way to get an OBJ file from a frame compared to the RecordPointCloud skecth?

I hope I explained myself

Thank you for your help!


#2

Can you show us your code?


#3

Hi tony!
This is the sketch I used to import OBJ file in Processing

PShape rocket;

float ry;
  
public void setup() {
  size(640, 360, P3D);
    
  rocket = loadShape("frame00.obj");
}

public void draw() {
  background(0);
  lights();
  
  translate(width/2, height/2 + 100, -200);
  rotateZ(PI);
  rotateY(ry);
  shape(rocket);
  
  ry += 0.02;
}

frame00.obj is the name of file. Obviously, the file is in data folder of sketch folder


#4

I haven’t worked too often with .obj files. What does the pointcloud look like rendered in Blender?


#5

Hi elyon,
Is your object only dots?
I think you need to have surface to be able to see something.
(It is like the render mode in blender: you can’t see the points, you can see them only in edit mode)


#6

this is how the pointcloud frame caugth by kinect appears in Blender.


#7

Hi jb4x!
Yeah, my object is only points, as you can see from the picture above.
You’ve probably right, but it’s so strange that a file create by Processing its not readable by Processing itself, isn’t it?


#8

It is readable, it just not behave the way you expect it.

What you can try is to loop through all the point a draw a sphere at the position of each point.
You should get the result you expect this way.


#9

According to the loadShape() reference, your pointcloud is loaded as a PShape. Try iterating through all those points, like @jb4x says


#10

Ah that’s an idea, guys!
Can you guide me? I’m a beginner and I don’t know how to do that :sweat::sweat_smile:


#11

Let’s take a look at the PShape reference

We can use getVertex() to access the vertices. Give it an index and it will return to you a PVector.


#12

To complement @tony 's answer, you can use getVertexCount() to get the number of vertex in your object. It makes it super easy to loop through all of the vertices of your object :wink:


#13

Some examples here: https://github.com/n1ckfg/MeshSequencer


#14

Mh, so I have to use loadShape() to load the OBJ file, then use getVertexCount() to get vertex number, put them in a Vector and create a sphere on each vertex?


#15

Hi elyon,

try this:

PShape rocket;

void setup() {
  size(640, 360, P3D);
  rocket = loadShape("frame00.obj");
  lights();

  for (int i = 0; i < s.getVertexCount(); i++) {
    PVector v = s.getVertex(i);
    pushMatrix();
    translate(v.x, v.y, v.z);
    sphere(3);
    popMatrix();
  }
}

#16

it doesn’t work. I think that the problem is the way that RecordPointCloud in KinectPV2 example make the OBJ file, because this is the result when i execute loadShape("frame00.obj")

I found also jeremydouglass solution here but in debugger I see that the OBJ hasn’t children and childCount is 0


#17

This is really interesting - at this point I don’t know what to say.

Can I ask though: Can I ask though, have you checked out @shiffman’s Kinect Tutorial?


#18

Have you posted the file anywhere? Can you copy and paste some lines from the top of it?


#19

I’m happy to try to help if I can. Could you:

  1. confirm that this is the sketch generating your data? https://github.com/ThomasLengeling/KinectPV2/blob/master/KinectPV2/examples/RecordPointCloud/RecordPointCloud.pde

    There are some things going on here with PShader and OpenGL / PGL that I don’t fully understand. We might ask some of our form shader / OpenGL experts.

  2. Could you provide a sample of an actual OBJ you are producing? Ideally just a simple test example with dozens or hundreds of points – not thousands.

If you are using this code,

it looks like you should be saving an obj file that is just a list of verts, 1 per line, and nothing else.

v 0.123 0.234 0.345 1.0

If that is the case then even if you can’t get your current loader to work (which is odd) you could write your own loader in a few lines with loadStrings and split.


#20

tony I checked Kinect Tutorial page but I don’t think it talks about record point cloud. Do I skipped any step?

@neilcsmith the code is the one that jeremydouglass posted

@jeremydouglass HI! Yeah, I confirm that is the code I used. Here is the link where you can find the file but, as you said, is just a list of verts, 1 per line, and nothing else.

Mhh, do you think that I can create an OBJ loader my self?