Skip to content

Instantly share code, notes, and snippets.

@danilogr
Created February 18, 2018 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilogr/f20ac003e7fd3eb61dfb7c3566e49866 to your computer and use it in GitHub Desktop.
Save danilogr/f20ac003e7fd3eb61dfb7c3566e49866 to your computer and use it in GitHub Desktop.
Microsoft Kinect Timelapse: saves a picture every minute
'''
This script uses PyKinectV2 to capture Microsoft Kinect v2 frames,
and OpenCV (>=2) to save those as JPG images every minute.
Dependencies: PyKinectV2 (https://github.com/Kinect/PyKinect2/) and OpenCV.
Running the script
1) Make sure that you have a 32 bit version of Python. PyKinectV2 does not run on the 64 bit alternative.
If you need to install python on Windows, consider using Anaconda.
2) Install OpenCV using conda
$ conda install -c conda-forge opencv
3) Install PyKinectV2 from the source (see https://github.com/Kinect/PyKinect2/issues/45)
$ git clone https://github.com/Kinect/PyKinect2.git
$ python -m easy_install PyKinect2
'''
from pykinect2 import PyKinectV2
from pykinect2 import PyKinectRuntime
import cv2
from time import sleep
import datetime
kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Color)
while (True):
colorFrame = kinect.get_last_color_frame() # PyKinect2 returns a color frame in a linear array of size (8294400,)
colorFrame = colorFrame.reshape((1080, 1920 ,4)) # pictures are 1920 columns x 1080 rows with 4 bytes (BGRA) per pixel
now = datetime.datetime.now() # You know it
cv2.imwrite(now.strftime("%Y-%m-%d-%H-%M") + '.jpg',colorFrame) # saves the pictures
sleep(60) # rests for a minute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment