# KinectPV2: get and import obj files

**URL:** <https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424>\
**Category:** Beginners\
**Created:** [September 10, 2018, 1:33pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424 "2018-09-10T13:33:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![elyon](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@elyon](https://discourse.processing.org/u/elyon)\
**Post date:** [September 10, 2018, 1:33pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/1 "2018-09-10T13:33:41Z")

</div>

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](https://github.com/ThomasLengeling/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](https://github.com/processing/processing-docs/blob/master/content/examples/Basics/Shape/LoadDisplayOBJ/LoadDisplayOBJ.pde)) 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!

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [September 10, 2018, 4:12pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/2 "2018-09-10T16:12:43Z")

</div>

> [@elyon](#):
>
> ut when I start the Sketch…there is nothing in the window.

Can you show us your code?

---

<div class="post-metadata">

**Author:** ![elyon](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@elyon](https://discourse.processing.org/u/elyon)\
**Post date:** [September 10, 2018, 4:16pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/3 "2018-09-10T16:16:03Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [September 10, 2018, 4:25pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/4 "2018-09-10T16:25:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 10, 2018, 4:25pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/5 "2018-09-10T16:25:49Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![elyon](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@elyon](https://discourse.processing.org/u/elyon)\
**Post date:** [September 10, 2018, 4:40pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/6 "2018-09-10T16:40:03Z")

</div>

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

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0947cd11822732b15dc416baa5b2589d37f63818.png)

---

<div class="post-metadata">

**Author:** ![elyon](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@elyon](https://discourse.processing.org/u/elyon)\
**Post date:** [September 10, 2018, 4:42pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/7 "2018-09-10T16:42:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 10, 2018, 4:43pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/8 "2018-09-10T16:43:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [September 10, 2018, 4:51pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/9 "2018-09-10T16:51:05Z")

</div>

According to the [loadShape()](https://processing.org/reference/loadShape_.html) reference, your pointcloud is loaded as a PShape. Try iterating through all those points, like @jb4x says

---

<div class="post-metadata">

**Author:** ![elyon](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@elyon](https://discourse.processing.org/u/elyon)\
**Post date:** [September 10, 2018, 4:56pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/10 "2018-09-10T16:56:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [September 10, 2018, 6:21pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/11 "2018-09-10T18:21:27Z")

</div>

Let’s take a look at the [PShape](https://processing.org/reference/PShape.html) reference

We can use [getVertex()](https://processing.org/reference/PShape_getVertex_.html) to access the vertices. Give it an index and it will return to you a PVector.

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 10, 2018, 6:31pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/12 "2018-09-10T18:31:37Z")

</div>

To complement @tony 's answer, you can use [getVertexCount()](https://processing.org/reference/PShape_getVertexCount_.html) to get the number of vertex in your object. It makes it super easy to loop through all of the vertices of your object 😉

---

<div class="post-metadata">

**Author:** ![n1ckfg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/n1ckfg/32/119_2.png) [@n1ckfg](https://discourse.processing.org/u/n1ckfg)\
**Post date:** [September 11, 2018, 4:36am UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/13 "2018-09-11T04:36:10Z")

</div>

Some examples here: [https://github.com/n1ckfg/MeshSequencer](https://github.com/n1ckfg/MeshSequencer)

---

<div class="post-metadata">

**Author:** ![elyon](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@elyon](https://discourse.processing.org/u/elyon)\
**Post date:** [September 11, 2018, 7:59am UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/14 "2018-09-11T07:59:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 11, 2018, 8:18am UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/15 "2018-09-11T08:18:33Z")

</div>

Hi elyon,

try this:

```auto
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();
  }
}

```

---

<div class="post-metadata">

**Author:** ![elyon](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@elyon](https://discourse.processing.org/u/elyon)\
**Post date:** [September 11, 2018, 8:26am UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/16 "2018-09-11T08:26:59Z")

</div>

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")`

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/ae4817bd6a3a1676daf511aade7d97bd2737ddf2.png)

I found also jeremydouglass solution [here](https://forum.processing.org/two/discussion/18087/get-vertex-from-an-obj-file) but in debugger I see that the OBJ hasn’t `children` and `childCount` is 0

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [September 12, 2018, 6:43am UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/17 "2018-09-12T06:43:10Z")

</div>

> [@elyon](#):
>
> I found also jeremydouglass solution [here](https://forum.processing.org/two/discussion/18087/get-vertex-from-an-obj-file) but in debugger I see that the OBJ hasn’t `children` and `childCount` is 0

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](https://shiffman.net/p5/kinect/)?

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [September 12, 2018, 12:37pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/18 "2018-09-12T12:37:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 12, 2018, 7:11pm UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/19 "2018-09-12T19:11:38Z")

</div>

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](https://github.com/ThomasLengeling/KinectPV2/blob/master/KinectPV2/examples/RecordPointCloud/RecordPointCloud.pde)

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,

> <https://github.com/ThomasLengeling/KinectPV2/blob/master/KinectPV2/examples/RecordPointCloud/Frame.pde#L22-L36>

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.

---

<div class="post-metadata">

**Author:** ![elyon](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@elyon](https://discourse.processing.org/u/elyon)\
**Post date:** [September 13, 2018, 7:09am UTC](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424/20 "2018-09-13T07:09:54Z")

</div>

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](https://drive.google.com/file/d/1cawrp_7epJ2YQHq-bz3xpUAyHlgGBjln/view?usp=sharing) 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?

[Next page](https://discourse.processing.org/t/kinectpv2-get-and-import-obj-files/3424.md?page=2)
