So what I'm trying to do is this, but I cant even get the Kinect to take a screenshot!
I have installed the drivers for Kinect, Python 2.6 and PIL for it. When I try to start the getSnapshot scrip this is what I get back:
CODETraceback (most recent call last):
ÂÂFile "C:\Users\Atle\Desktop\Minecraft Kinect Hack\getSnapshot.py", line 40, in
ÂÂÂÂkinect = ctypes.cdll.CLNUIDevice
ÂÂFile "C:\Python26\lib\ctypes\__init__.py", line 423, in __getattr__
ÂÂÂÂdll = self._dlltype(name)
ÂÂFile "C:\Python26\lib\ctypes\__init__.py", line 353, in __init__
ÂÂÂÂself._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
Anybody have a clue?
Here's the getSnapshot script btw:
I have installed the drivers for Kinect, Python 2.6 and PIL for it. When I try to start the getSnapshot scrip this is what I get back:
CODETraceback (most recent call last):
ÂÂFile "C:\Users\Atle\Desktop\Minecraft Kinect Hack\getSnapshot.py", line 40, in
ÂÂÂÂkinect = ctypes.cdll.CLNUIDevice
ÂÂFile "C:\Python26\lib\ctypes\__init__.py", line 423, in __getattr__
ÂÂÂÂdll = self._dlltype(name)
ÂÂFile "C:\Python26\lib\ctypes\__init__.py", line 353, in __init__
ÂÂÂÂself._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
Anybody have a clue?
Here's the getSnapshot script btw:
CODE# Requires at least Python 2.5, PIL
#ÂÂÂÂa Kinect, and CL NUI drivers from http://codelaboratories.com/get/nui
# By Nathan Viniconis
# You can use this code freely without any obligation to the original or myself
import ctypes
import time
import Image
import math
import sys
import os
#######################
# Editable globals
#######################
# base file names to be used to store the depth and color info.
colorImageName = "OutputColor" # .png
depthImageName = "OutputDepth" # .tiff
# number of images to take
numImages = 20
# seconds to wait between the images
imageWait = 2ÂÂÂÂ# less than 2 causes wierd results
###########################
## Global inits
###########################
curImageIndex = 0
maxDigits = 5 # 00000 to 99999 should be plenty
# Kinect frame buffers
clrBuffer = ctypes.create_string_buffer(640*480*3)
dpthBuffer = ctypes.create_string_buffer(640*480*2)
# Init the Kinect
kinect = ctypes.cdll.CLNUIDevice
serial = kinect.GetNUIDeviceSerial(0)
camera = kinect.CreateNUICamera(serial)
if (str(camera) == "0"):
ÂÂÂÂprint "could not connect to kinect"
ÂÂÂÂsys.exit(0)
ÂÂÂÂ
# starts the cameras so that frames can be extracted
def startKinect():
ÂÂÂÂkinect.StartNUICamera(camera)
# stops the camera, call before closing or it can freeze
def endKinect():
ÂÂÂÂkinect.StopNUICamera(camera)
ÂÂÂÂkinect.DestroyNUICamera(camera)
# Create the filenames to use
def getFilenamesFromIndex():
ÂÂÂÂglobal curImageIndex
ÂÂÂÂprefix = ""
ÂÂÂÂif (len(str(curImageIndex)) < maxDigits):
ÂÂÂÂÂÂÂÂnumZeros = maxDigits - len(str(curImageIndex))
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂwhile (numZeros > 0):
ÂÂÂÂÂÂÂÂÂÂÂÂprefix = "0" + prefix
ÂÂÂÂÂÂÂÂÂÂÂÂnumZeros -= 1
ÂÂÂÂÂÂÂÂÂÂÂÂ
ÂÂÂÂclrImage = prefix + str(curImageIndex) + colorImageName + ".png"
ÂÂÂÂdpthImage = prefix + str(curImageIndex) + depthImageName + ".tiff"
ÂÂÂÂ
ÂÂÂÂreturn clrImage, dpthImage
# find the index to use so each image independently so that they are not overwritten
def getFilenamesToUse():
ÂÂÂÂglobal curImageIndex
ÂÂÂÂclrFileUsed = True
ÂÂÂÂdepthFileUsed = True
ÂÂÂÂwhile clrFileUsed or depthFileUsed:
ÂÂÂÂÂÂÂÂ# see if either the depth or color index has already been used
ÂÂÂÂÂÂÂÂfileNames = getFilenamesFromIndex()
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ# check the two files
ÂÂÂÂÂÂÂÂclrFileUsed = os.path.exists(fileNames[0])
ÂÂÂÂÂÂÂÂdepthFileUsed = os.path.exists(fileNames[1])
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ# if either exist, try the next index
ÂÂÂÂÂÂÂÂif (clrFileUsed or depthFileUsed):
ÂÂÂÂÂÂÂÂÂÂÂÂcurImageIndex += 1
ÂÂÂÂreturn getFilenamesFromIndex()
# actually take the snapshots
def takeSnapshot(fileNames):
ÂÂÂÂ# Get the Kinect data
ÂÂÂÂkinect.GetNUICameraColorFrameRGB24(camera, clrBuffer)
ÂÂÂÂkinect.GetNUICameraDepthFrameRAW(camera, dpthBuffer)
ÂÂÂÂ# Output with PIL
ÂÂÂÂclrImage = Image.fromstring('RGB', [640, 480], clrBuffer, 'raw', 'BGR', 0, 1)
ÂÂÂÂclrImage.save(fileNames[0])
ÂÂÂÂdpthImage = Image.fromstring('I;16', [640, 480], dpthBuffer)
ÂÂÂÂdpthImage.save(fileNames[1])
def main():
ÂÂÂÂ# turn on the kinect
ÂÂÂÂstartKinect()
ÂÂÂÂ# take the images
ÂÂÂÂimagesTaken = 0
ÂÂÂÂwhile (imagesTaken < numImages):
ÂÂÂÂÂÂÂÂtime.sleep(imageWait)
ÂÂÂÂÂÂÂÂfileNames = getFilenamesToUse()
ÂÂÂÂÂÂÂÂtakeSnapshot(fileNames)
ÂÂÂÂÂÂÂÂprint "Saving: " + fileNames[0] + " and " + fileNames[1]
ÂÂÂÂÂÂÂÂimagesTaken += 1
ÂÂÂÂ
ÂÂÂÂ# turn off the kinect
ÂÂÂÂendKinect()
if __name__ == "__main__":
ÂÂÂÂmain()
#ÂÂÂÂa Kinect, and CL NUI drivers from http://codelaboratories.com/get/nui
# By Nathan Viniconis
# You can use this code freely without any obligation to the original or myself
import ctypes
import time
import Image
import math
import sys
import os
#######################
# Editable globals
#######################
# base file names to be used to store the depth and color info.
colorImageName = "OutputColor" # .png
depthImageName = "OutputDepth" # .tiff
# number of images to take
numImages = 20
# seconds to wait between the images
imageWait = 2ÂÂÂÂ# less than 2 causes wierd results
###########################
## Global inits
###########################
curImageIndex = 0
maxDigits = 5 # 00000 to 99999 should be plenty
# Kinect frame buffers
clrBuffer = ctypes.create_string_buffer(640*480*3)
dpthBuffer = ctypes.create_string_buffer(640*480*2)
# Init the Kinect
kinect = ctypes.cdll.CLNUIDevice
serial = kinect.GetNUIDeviceSerial(0)
camera = kinect.CreateNUICamera(serial)
if (str(camera) == "0"):
ÂÂÂÂprint "could not connect to kinect"
ÂÂÂÂsys.exit(0)
ÂÂÂÂ
# starts the cameras so that frames can be extracted
def startKinect():
ÂÂÂÂkinect.StartNUICamera(camera)
# stops the camera, call before closing or it can freeze
def endKinect():
ÂÂÂÂkinect.StopNUICamera(camera)
ÂÂÂÂkinect.DestroyNUICamera(camera)
# Create the filenames to use
def getFilenamesFromIndex():
ÂÂÂÂglobal curImageIndex
ÂÂÂÂprefix = ""
ÂÂÂÂif (len(str(curImageIndex)) < maxDigits):
ÂÂÂÂÂÂÂÂnumZeros = maxDigits - len(str(curImageIndex))
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂwhile (numZeros > 0):
ÂÂÂÂÂÂÂÂÂÂÂÂprefix = "0" + prefix
ÂÂÂÂÂÂÂÂÂÂÂÂnumZeros -= 1
ÂÂÂÂÂÂÂÂÂÂÂÂ
ÂÂÂÂclrImage = prefix + str(curImageIndex) + colorImageName + ".png"
ÂÂÂÂdpthImage = prefix + str(curImageIndex) + depthImageName + ".tiff"
ÂÂÂÂ
ÂÂÂÂreturn clrImage, dpthImage
# find the index to use so each image independently so that they are not overwritten
def getFilenamesToUse():
ÂÂÂÂglobal curImageIndex
ÂÂÂÂclrFileUsed = True
ÂÂÂÂdepthFileUsed = True
ÂÂÂÂwhile clrFileUsed or depthFileUsed:
ÂÂÂÂÂÂÂÂ# see if either the depth or color index has already been used
ÂÂÂÂÂÂÂÂfileNames = getFilenamesFromIndex()
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ# check the two files
ÂÂÂÂÂÂÂÂclrFileUsed = os.path.exists(fileNames[0])
ÂÂÂÂÂÂÂÂdepthFileUsed = os.path.exists(fileNames[1])
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ# if either exist, try the next index
ÂÂÂÂÂÂÂÂif (clrFileUsed or depthFileUsed):
ÂÂÂÂÂÂÂÂÂÂÂÂcurImageIndex += 1
ÂÂÂÂreturn getFilenamesFromIndex()
# actually take the snapshots
def takeSnapshot(fileNames):
ÂÂÂÂ# Get the Kinect data
ÂÂÂÂkinect.GetNUICameraColorFrameRGB24(camera, clrBuffer)
ÂÂÂÂkinect.GetNUICameraDepthFrameRAW(camera, dpthBuffer)
ÂÂÂÂ# Output with PIL
ÂÂÂÂclrImage = Image.fromstring('RGB', [640, 480], clrBuffer, 'raw', 'BGR', 0, 1)
ÂÂÂÂclrImage.save(fileNames[0])
ÂÂÂÂdpthImage = Image.fromstring('I;16', [640, 480], dpthBuffer)
ÂÂÂÂdpthImage.save(fileNames[1])
def main():
ÂÂÂÂ# turn on the kinect
ÂÂÂÂstartKinect()
ÂÂÂÂ# take the images
ÂÂÂÂimagesTaken = 0
ÂÂÂÂwhile (imagesTaken < numImages):
ÂÂÂÂÂÂÂÂtime.sleep(imageWait)
ÂÂÂÂÂÂÂÂfileNames = getFilenamesToUse()
ÂÂÂÂÂÂÂÂtakeSnapshot(fileNames)
ÂÂÂÂÂÂÂÂprint "Saving: " + fileNames[0] + " and " + fileNames[1]
ÂÂÂÂÂÂÂÂimagesTaken += 1
ÂÂÂÂ
ÂÂÂÂ# turn off the kinect
ÂÂÂÂendKinect()
if __name__ == "__main__":
ÂÂÂÂmain()