# Path: pyKinectTools/algs/BackgroundSubtraction.py
# def constrain(img, mini=-1, maxi=-1): #500, 4000
# 	if mini == -1:
# 		min_ = np.min(img[np.nonzero(img)])
# 	else:
# 		min_ = mini
# 	if maxi == -1:
# 		max_ = img.max()
# 	else:
# 		max_ = maxi
# 
# 	img = np.clip(img, min_, max_)
# 	img -= min_
# 	if max_ == 0:
# 		max_ = 1
# 	img = np.array((img * (255.0 / (max_-min_))), dtype=np.uint8)
# 
# 	img[img==img.max()] = 0
# 
# 	return img


import os, time, sys
import numpy as np
import cv, cv2
import pyKinectTools.utils.SkeletonUtils as SR
from math import floor
from pyKinectTools.algs.BackgroundSubtraction import constrain
					displayUsers.append(users[i]['Img'])

				#eliminate bad skeleton data (joint data is linked to old data)
				# pdb.set_trace()
				deleteInd = []
				for i in users.keys():
					# print users[i]['Img']
					if users[i]['Img'][2] == 0:
						deleteInd.append(i)
				deleteInd.sort(reverse=1)
				for i in deleteInd:
					# print "Del", i
					del users[i]
					del skels[i]
					del displayUsers[i-1]

			if len(depthFilename) > 0:
				## 1
				# depthRaw = open(depthFilename, 'rb').read().split()
				# depthRaw = np.fromfile(depthFilename, dtype=np.uint16, sep=" ")
				# self.depthData = np.array(depthRaw, dtype=int).reshape([480,640])[:,::-1]
				# self.depthData = self.depthData[:,::-1]
				## 2
				# self.depthData = np.fromfile(depthFilename, dtype=np.uint16, sep=" ").reshape([480, 640])[:,::-1]
				# self.depthDataRaw = self.depthData
				## 3
				x = open(depthFilename).read()
				self.depthDataRaw = np.fromstring(x, dtype=np.uint16, sep=" ").reshape([480, 640])[:,::-1]	
				self.depthIm = self.depthDataRaw
				if self.constrain != []:

# Path: pyKinectTools/algs/BackgroundSubtraction.py
# def constrain(img, mini=-1, maxi=-1): #500, 4000
# 	if mini == -1:
# 		min_ = np.min(img[np.nonzero(img)])
# 	else:
# 		min_ = mini
# 	if maxi == -1:
# 		max_ = img.max()
# 	else:
# 		max_ = maxi
# 
# 	img = np.clip(img, min_, max_)
# 	img -= min_
# 	if max_ == 0:
# 		max_ = 1
# 	img = np.array((img * (255.0 / (max_-min_))), dtype=np.uint8)
# 
# 	img[img==img.max()] = 0
# 
# 	return img


# Path: pyKinectTools/utils/DepthReader.py
import os, time, sys
import numpy as np
import cv, cv2
import pyKinectTools.utils.SkeletonUtils as SR
from math import floor
from pyKinectTools.algs.BackgroundSubtraction import constrain

					displayUsers.append(users[i]['Img'])

				#eliminate bad skeleton data (joint data is linked to old data)
				# pdb.set_trace()
				deleteInd = []
				for i in users.keys():
					# print users[i]['Img']
					if users[i]['Img'][2] == 0:
						deleteInd.append(i)
				deleteInd.sort(reverse=1)
				for i in deleteInd:
					# print "Del", i
					del users[i]
					del skels[i]
					del displayUsers[i-1]

			if len(depthFilename) > 0:
				## 1
				# depthRaw = open(depthFilename, 'rb').read().split()
				# depthRaw = np.fromfile(depthFilename, dtype=np.uint16, sep=" ")
				# self.depthData = np.array(depthRaw, dtype=int).reshape([480,640])[:,::-1]
				# self.depthData = self.depthData[:,::-1]
				## 2
				# self.depthData = np.fromfile(depthFilename, dtype=np.uint16, sep=" ").reshape([480, 640])[:,::-1]
				# self.depthDataRaw = self.depthData
				## 3
				x = open(depthFilename).read()
				self.depthDataRaw = np.fromstring(x, dtype=np.uint16, sep=" ").reshape([480, 640])[:,::-1]	
				self.depthIm = self.depthDataRaw
				if self.constrain != []:

					self.depthIm8 = constrain(self.depthIm, self.constrain[0], self.constrain[1])