예제 #1
0
	def KSCheck(self,trigger):
		if trigger=='timercheck':
			if self.KSAvailable!=True and KS.deviceAvailable():
				####Here may also fail
				KS.startAll()
				self.KSAvailable=True
				self.refreshThread.KinectReady.emit()
		elif trigger=='failurecheck':
			print "failurecheck"
			KS.reInit()
			if not KS.deviceAvailable():
				print "failurecheck failed"
				self.KSAvailable=False
				self.refreshThread.KinectFail.emit()
예제 #2
0
	def refresh(self):
		#self.m.angleInfo.swingAngleV+=0.05
		#self.m.angleInfo.armAngleV=math.pi/6;
		#self.m.angleInfo.armSpringAngleV=math.pi/6;
		#self.m.angleInfo.armFrontAngleV=math.pi/6;

		refreshDepthImage=None
		refreshImageImage=None
		
		if self.m.KSAvailable!=True:
			refreshDepthImage=self.m.imgBlank
			refreshImageImage=self.m.imgBlank
		else:
			try:
				#RGB Image
				imageFrame=KS.readImage()
				self.m.imageList[self.m.imgpos]=(
						QImage(imageFrame,640,480,
							QImage.Format_RGB888).rgbSwapped())
				refreshImageImage=self.m.imageList[self.m.imgpos]

				#Depth image
				frame=KS.readDepth()
				f=np.fromstring(frame,dtype=np.uint8)
				self.m.depthList[self.m.imgpos]=QImage(
						f.repeat(4),640,480,QImage.Format_RGB32)
				refreshDepthImage=self.m.depthList[self.m.imgpos]

				#Draw points on depth image
				skeleton_list = []
				KS.ctx.wait_and_update_all()
				user_list=[]
				for u_id in KS.userNode.users:
					readRet=KS.readSkeleton(self.joint_request, u_id)
					user_list.append(readRet)
					
				max_u=[[],[]]
				for u in user_list:
					if len(u[0])>=len(max_u[0]):
						max_u=u
				skeleton_list = max_u[0]
				self.joint_list=max_u[1]
				modifier = QPainter()
				color=QColor()
				modifier.begin(refreshDepthImage)
				for ske_joint in skeleton_list:
					if ske_joint[1] < 0:
						continue
					depth=self.hmapping(ske_joint[2])
					color.setHsv(depth,255,255)
					modifier.setPen(
							QPen(color,
								15, 
								cap=Qt.RoundCap)
							)
					modifier.drawPoint(ske_joint[0],ske_joint[1])

				modifier.end()	

			except openni.OpenNIError:
				self.m.KSAvailable=False
				print 'Kinect Sensor disconnected.'
				self.m.KSCheck('failurecheck');
				return 
		self.armTranspose()
		#Depth	
		self.m.depthLabel.setPixmap(
				QPixmap.fromImage(refreshDepthImage.scaled(
						self.m.depthLabel.width(),self.m.depthLabel.height(),
						Qt.KeepAspectRatio))
				)
		#Image
		self.m.imageLabel.setPixmap(
				QPixmap.fromImage(refreshImageImage.scaled(
					self.m.imageLabel.width(),self.m.imageLabel.height(),
					Qt.KeepAspectRatio))
				)
		
		self.m.imgpos=1-self.m.imgpos;