Example #1
0
def chog(img):
	''' Hand Contour Based Histograms of Oriented Gradients '''

	img = ip.normalize(img)
	num_contours = 10
	num_bins = 16

	con = ip.hand_contour(img, num_contours)

	features = np.array([])

	mid_x = img.shape[1] / 2
	mid_y = img.shape[0] / 2

	for i in range(1,num_contours+1):

		con_img = img.copy()
		con_img[con!=i] = 0

		gx = cv2.Sobel(con_img, cv2.CV_32F, 1, 0)
		gy = cv2.Sobel(con_img, cv2.CV_32F, 0, 1)
		mag, ang = cv2.cartToPolar(gx, gy)

		bins = np.int32(num_bins*ang/(2*np.pi))

		bin_cells = bins[:mid_y,:mid_x], bins[mid_y:,:mid_x], bins[:mid_y,mid_x:], bins[mid_y: mid_x:]
		mag_cells = mag[:mid_y,:mid_x], mag[mid_y:,:mid_x], mag[:mid_y,mid_x:], mag[mid_y: mid_x:]

		hists = [np.bincount(b.ravel(), m.ravel(), num_bins) for b, m in zip(bin_cells, mag_cells)]
		features = np.concatenate((features, np.hstack(hists)))	

	return features
Example #2
0
def hod(img):
	''' Contour based Histograms of Depth Data '''

	img = ip.normalize(img)

	num_contours = 10	# number of contours to be used for each hand
	num_bins = 20		# number of depth bins for the histograms

	con = ip.hand_contour(img, num_contours)

	features = np.array([])		# initialize features

	for i in range(1,num_contours+1):		# get features for each contour

		hist = np.histogram(img[con==i], bins=num_bins, range=(0, 255))	# get hist of depth values for contour
		features = np.concatenate((features, hist[0]))										# update features

	return features