Skip to content

Python 3.12.4 and 64-bit environments compatibility #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# PyKinect2
Summrized update for compatibility with Python 3.12 and 64-bit environments based based on previous pull requests.

Enables writing Kinect applications, games, and experiences using Python. Inspired by the original [PyKinect project on CodePlex](http://pytools.codeplex.com/wikipage?title=PyKinect).

Expand Down
26 changes: 11 additions & 15 deletions pykinect2/PyKinectRuntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
from pykinect2.PyKinectV2 import *

import ctypes
import _ctypes
from _ctypes import COMError
import comtypes
import sys
import numpy
import time

import importlib

if sys.hexversion >= 0x03000000:
import _thread as thread
Expand Down Expand Up @@ -163,7 +159,7 @@ def __init__(self, frame_source_types):
self._last_long_exposure_infrared_frame = None
self._last_audio_frame = None

start_clock = time.clock()
start_clock = time.perf_counter()
self._last_color_frame_access = self._last_color_frame_time = start_clock
self._last_body_frame_access = self._last_body_frame_time = start_clock
self._last_body_index_frame_access = self._last_body_index_frame_time = start_clock
Expand Down Expand Up @@ -243,7 +239,7 @@ def get_last_color_frame(self):
with self._color_frame_lock:
if self._color_frame_data is not None:
data = numpy.copy(numpy.ctypeslib.as_array(self._color_frame_data, shape=(self._color_frame_data_capacity.value,)))
self._last_color_frame_access = time.clock()
self._last_color_frame_access = time.perf_counter()
return data
else:
return None
Expand All @@ -252,7 +248,7 @@ def get_last_infrared_frame(self):
with self._infrared_frame_lock:
if self._infrared_frame_data is not None:
data = numpy.copy(numpy.ctypeslib.as_array(self._infrared_frame_data, shape=(self._infrared_frame_data_capacity.value,)))
self._last_infrared_frame_access = time.clock()
self._last_infrared_frame_access = time.perf_counter()
return data
else:
return None
Expand All @@ -261,7 +257,7 @@ def get_last_depth_frame(self):
with self._depth_frame_lock:
if self._depth_frame_data is not None:
data = numpy.copy(numpy.ctypeslib.as_array(self._depth_frame_data, shape=(self._depth_frame_data_capacity.value,)))
self._last_depth_frame_access = time.clock()
self._last_depth_frame_access = time.perf_counter()
return data
else:
return None
Expand All @@ -270,15 +266,15 @@ def get_last_body_index_frame(self):
with self._body_index_frame_lock:
if self._body_index_frame_data is not None:
data = numpy.copy(numpy.ctypeslib.as_array(self._body_index_frame_data, shape=(self._body_index_frame_data_capacity.value,)))
self._last_body_index_frame_access = time.clock()
self._last_body_index_frame_access = time.perf_counter()
return data
else:
return None

def get_last_body_frame(self):
with self._body_frame_lock:
if self._body_frame_bodies is not None:
self._last_body_frame_access = time.clock()
self._last_body_frame_access = time.perf_counter()
return self._body_frame_bodies.copy()
else:
return None
Expand Down Expand Up @@ -340,7 +336,7 @@ def handle_color_arrived(self, handle_index):
try:
with self._color_frame_lock:
colorFrame.CopyConvertedFrameDataToArray(self._color_frame_data_capacity, self._color_frame_data, PyKinectV2.ColorImageFormat_Bgra)
self._last_color_frame_time = time.clock()
self._last_color_frame_time = time.perf_counter()
except:
pass
colorFrame = None
Expand All @@ -358,7 +354,7 @@ def handle_depth_arrived(self, handle_index):
try:
with self._depth_frame_lock:
depthFrame.CopyFrameDataToArray(self._depth_frame_data_capacity, self._depth_frame_data)
self._last_depth_frame_time = time.clock()
self._last_depth_frame_time = time.perf_counter()
except:
pass
depthFrame = None
Expand All @@ -378,7 +374,7 @@ def handle_body_arrived(self, handle_index):
with self._body_frame_lock:
bodyFrame.GetAndRefreshBodyData(self._body_frame_data_capacity, self._body_frame_data)
self._body_frame_bodies = KinectBodyFrameData(bodyFrame, self._body_frame_data, self.max_body_count)
self._last_body_frame_time = time.clock()
self._last_body_frame_time = time.perf_counter()

# need these 2 lines as a workaround for handling IBody referencing exception
self._body_frame_data = None
Expand All @@ -402,7 +398,7 @@ def handle_body_index_arrived(self, handle_index):
try:
with self._body_index_frame_lock:
bodyIndexFrame.CopyFrameDataToArray(self._body_index_frame_data_capacity, self._body_index_frame_data)
self._last_body_index_frame_time = time.clock()
self._last_body_index_frame_time = time.perf_counter()
except:
pass
bodyIndexFrame = None
Expand All @@ -419,7 +415,7 @@ def handle_infrared_arrived(self, handle_index):
try:
with self._infrared_frame_lock:
infraredFrame.CopyFrameDataToArray(self._infrared_frame_data_capacity, self._infrared_frame_data)
self._last_infrared_frame_time = time.clock()
self._last_infrared_frame_time = time.perf_counter()
except:
pass
infraredFrame = None
Expand Down
18 changes: 12 additions & 6 deletions pykinect2/PyKinectV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from comtypes import *
from comtypes import GUID
from ctypes import HRESULT
from comtypes import helpstring
from comtypes import COMMETHOD
from comtypes import dispid
STRING = c_char_p
INT_PTR = c_int
from ctypes.wintypes import _LARGE_INTEGER
Expand All @@ -18,10 +16,9 @@
from ctypes.wintypes import _FILETIME
WSTRING = c_wchar_p

from _ctypes import COMError
comtypes.hresult.E_PENDING = 0x8000000A

import numpy.distutils.system_info as sysinfo



class _event(object):
Expand Down Expand Up @@ -2216,7 +2213,15 @@ class ICoordinateMappingChangedEventArgs(comtypes.IUnknown):
('grfStateBits', c_ulong),
('reserved', c_ulong),
]
required_size = 64 + sysinfo.platform_bits / 4

# Test version to replace numpy.distutils which is deprecated
import struct

def get_platform_bits():
return 64 if struct.calcsize('P') * 8 == 64 else 32

platform_bits = get_platform_bits()
required_size = 64 + platform_bits / 4

assert sizeof(tagSTATSTG) == required_size, sizeof(tagSTATSTG)
assert alignment(tagSTATSTG) == 8, alignment(tagSTATSTG)
Expand Down Expand Up @@ -2865,7 +2870,8 @@ class IMultiSourceFrameReader(comtypes.IUnknown):
'JointType_HipLeft', 'ColorImageFormat_Rgba',
'IColorCameraSettings', '_DetectionResult',
'IColorFrameReader', 'ColorImageFormat_Yuy2', '_Activity']
from comtypes import _check_version; _check_version('')

# from comtypes import _check_version; _check_version('')


KINECT_SKELETON_COUNT = 6
Expand Down