예제 #1
0
def showLabeledImage(data, ind_j, dir_, rgb=0):
	cv.NamedWindow("a")
	if rgb:
		file_ = data['data']['filename'][ind_j]
		img = icuReader.getRGBImage(dir_+file_[:file_.find(".depth")]+".rgb")
		# imgD=img[:,::-1, :]
		imgD=img
	else:
		img = icuReader.getDepthImage(dir_+data['data']['filename'][ind_j])
		imgD = icuReader.constrain(img, 500, 5000)
		imgD = np.dstack([imgD, imgD, imgD])

	# com_xyz =  np.array(data['data']['com'])
	com_xyz =  np.array(data['data']['moving_com'])
	com = list(world2depth(com_xyz).T) #COM in image coords
	# Add previous location markers
	r = 5
	for jj in range(ind_j):
		s = (slice(com[jj][0]-r, com[jj][0]+r),slice(com[jj][1]-r, com[jj][1]+r))
		imgD[s[0], s[1], 0] = 100
		imgD[s[0], s[1], 1:3] = 0
	# Add current location marker
	r = 10
	s = (slice(com[ind_j][0]-r, com[ind_j][0]+r),slice(com[ind_j][1]-r, com[ind_j][1]+r))
	colorInd = 2#randint(0, 2)
	if colorInd==0: # Vary the colors every new person
		r=255; g=0; b=0
	elif colorInd==1:
		r=0; g=255; b=0
	elif colorInd==2:
		r=0; g=0; b=255				
	imgD[s[0], s[1], 0] = r
	imgD[s[0], s[1], 1] = g
	imgD[s[0], s[1], 2] = b	
	# Add touch boxes
	touchEnabled = 1
	if touchEnabled:
		rad = 13
		cv2.putText(imgD, "Touches", (5, 30), cv2.FONT_HERSHEY_SIMPLEX, .75, (255,255,255), thickness=1)
		for i in range(2):
			cv2.rectangle(imgD, (60-rad, 40*i+60-rad), (60+rad, 40*i+60+rad), [255, 255, 255])
	if 'touches' in data['data'].keys():
		rad = 10
		times = [x[1] for x in data['data']['touches']]
		if any(np.equal(times,ind_j)):
			for i in data['data']['touches'][np.argwhere(np.equal(times,ind_j))[0]][0]:
				cv2.circle(imgD, (60, 40*i+60), rad, [0, 255, 0], thickness=4)
	# Print time on screen
	time_ = data['data']['time'][ind_j]
	hours = int(time_ / 3600)
	minutes = int(time_ / 60) - hours*60
	seconds = int(time_) - 60*minutes - 3600*hours
	text = str(hours) + "hr " + str(minutes) + "min " + str(seconds) + "s"
	cv2.putText(imgD, text, (10, 470), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0), thickness=2)
	# Print duration to screen
	text = "Dur: " + str(data['elapsed'])
	cv2.putText(imgD, text, (450, 470), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0), thickness=2)
	#Show image
	cv2.imshow("a", imgD)
	cv2.waitKey(1)
예제 #2
0
	# Get counts for each label
	counts = [[], []]
	counts = np.histogram(truthLabels, 9, [.5,9.5])


	# Get indices for each label
	labelInds = []
	for i in xrange(len(labelNames)):
		labelInds.append([y for x,y in zip(p, range(0,len(p))) if 'label' in x.keys() and int(x['label'])==labelNames[i]])

	# Show label images
	for lab in xrange(len(labelNames)):
		figure(lab)
		for i in xrange(len(inds[lab])):
			subplot(2,int(len(inds[lab])/2),i)	
			img = icuReader.getDepthImage(dir_+p[inds[lab][i]]['data']['filename'][0])
			imshow(img)
			axis('off')
			title(labelNames[lab])

	### Time ###
	# Get time for each label
	labeledTimes = []
	for i in xrange(len(labelNames)):
		labeledTimes.append(np.sum([p[x]['elapsed'] for x in inds[i]]))

	# Time histogram
	times = [x['elapsed'] for x in p if x['elapsed'] > 10]
	times_hist = np.histogram(times, bins=20, range=[10,250])
	plot(times_hist[0])
	title('Histogram of action durations (Median: 37 sec)')