import torch


def cvToTorch(frame, device):
	"""
	Transforms an image from the openCV format to the pytorch format
	inputs : 	frame -> The image in the opencv format to transform to a torch tensor
				device -> The device on which to perform the transformation
	return : 	The pytorch tensor
	"""

	# Transform the array into a torch tensor
	tensor = torch.from_numpy(frame)

	# Sending the tensor to the GPU
	tensor = tensor.to(device)

	# Transform the type of the data from uint8 to float
	tensor = tensor.type(torch.float)

	# Transpose to [Channels, Height, Width]
	tensor = tensor.transpose(0,2).transpose(1,2)

	# Add the batch dimension
	tensor.unsqueeze_(0)

	return tensor