# Kinect¶

It is possible to use the Xbox kinect with SimpleCV. This makes it much easier to filter things out of the image based on depth. It is possible get a 3D image from two cameras (called Stereopsis) just as how humans see objects with their eyes. Unfornately this method is very computationally intensive, which means without a powerful computer you probably won’t be able to do it in real time.

The xbox significantly helps solve that computational problem by using infrared dots in the image to do some detection of the depth.

In the first example we will do exactly that, just load up the kinect and then get the depth image, where black is closer to the camera, and white is further away.:

```from SimpleCV import *
cam = Kinect()

while True:
depth = cam.getDepth()
depth.show()
```

`Download the script`

You should get an image similiar to:

There is a little trick SimpleCV does to make the depth image play nice is converts it to a greyscale image. So normally the depth image is 11bit depth and a greyscale image is 8 bit depth. A greyscale image has a color from 0 to 255. This is just like a color image, except a color image has three channels that go from 0-255, and a greyscale only one. What this means is if you have 640 by 480 pixel image, each pixel on that image will be represent with a number between 0 and 255.

For us this becomes useful because SimpleCV converts it from 11bit depth to 8bit depth so you can treat the image just like a greyscale image. This is useful as mentioned before, for things like filtering on depth. We can use a normal image manipulation function to filter items out. In our case we will use the stretch() function to “stretch” the image pixel color from the filter values.

So lets make an example, where we filter out things that are further away. To do this just add the following to the loop so you have:

```while True:
depth = cam.getDepth()
filtered = depth.stretch(0,150)
depth.show()
```

As you can see things in the distance are no longer in the picture.

Note

If you want 11 bit depth for higher accuracy you can use cam.getDepthMatrix(), although keep in mind that standard image functions no longer work
{"ft_lang_label":"__label__en","ft_lang_prob":0.925656,"math_prob":0.84847534,"size":2129,"snap":"2019-35-2019-39","text_gpt3_token_len":486,"char_repetition_ratio":0.12564705,"word_repetition_ratio":0.005235602,"special_character_ratio":0.22639737,"punctuation_ratio":0.090697676,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95667166,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-08-20T13:03:14Z\",\"WARC-Record-ID\":\"<urn:uuid:6466e105-f3d5-44cd-8f40-5f3ade1d1eb1>\",\"Content-Length\":\"11078\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2717ac43-8038-4584-90db-f077b4624955>\",\"WARC-Concurrent-To\":\"<urn:uuid:04003823-cfc7-4d7c-9fd4-10e97f50bd5a>\",\"WARC-IP-Address\":\"23.100.69.251\",\"WARC-Target-URI\":\"http://example.simplecv.org/en/latest/examples/kinect.html\",\"WARC-Payload-Digest\":\"sha1:R3KF4SNDAGR2RATLIO75AEEIPXTTPFIH\",\"WARC-Block-Digest\":\"sha1:3GFKSRCR6RI5465E2QU3ODJIBC46JOBG\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-35/CC-MAIN-2019-35_segments_1566027315329.55_warc_CC-MAIN-20190820113425-20190820135425-00222.warc.gz\"}"}