예제 #1
0
def augment_sample(I,pts, dim_w, dim_h, cls):

	maxsum,maxangle = 50,np.array([20.,20.,25.])
	angles = np.random.rand(3)*maxangle
	if angles.sum() > maxsum:
		angles = (angles/angles.sum())*(maxangle/maxangle.sum())

	I = im2single(I)
	iwh = getWH(I.shape)
	# codigo original
	# whratio = random.uniform(2., 4.)
	# wsiz = random.uniform(dim * .2, dim * 1.)

	# carro
	if cls=='0':
		whratio = random.uniform(2.75, 3.25)
		wsiz = random.uniform(dim_w * .2, dim_w * 0.7)
	else:
		whratio = random.uniform(0.7, 1.2)
		wsiz = random.uniform(dim_w * .2, dim_w * 0.7)
	# whratio = 1.
	# wsiz = random.uniform(dim_w*.2, dim_w*1.)
	# moto
	# whratio = random.uniform(0.7, 1.2)
	# wsiz = random.uniform(dim_w * .3, dim_w * 0.7)
	
	hsiz = wsiz/whratio

	dx = random.uniform(0.,dim_w - wsiz)
	dy = random.uniform(0.,dim_h - hsiz)

	pph = getRectPts(dx,dy,dx+wsiz,dy+hsiz)
	pts = pts*iwh.reshape((2,1))
	T = find_T_matrix(pts2ptsh(pts),pph)

	H = perspective_transform((dim_w,dim_h),angles=angles)
	H = np.matmul(H,T)

	Iroi,pts = project(I,H,pts,dim_w, dim_h)
	
	# hsv_mod = np.random.rand(3).astype('float32')
	# hsv_mod = (hsv_mod - .5)*.3
	# hsv_mod[0] *= 360
	# Iroi = hsv_transform(Iroi,hsv_mod)
	Iroi = np.clip(Iroi,0.,1.)

	pts = np.array(pts)

	# if random.random() > .5:
	# 	Iroi,pts = flip_image_and_pts(Iroi,pts)

	tl,br = pts.min(1),pts.max(1)
	llp = Label(0,tl,br)

	return Iroi,llp,pts
예제 #2
0
	def updatePerspectiveMatrix(self):
		zf  = self.zoom_factor
		w,h = getWH(self.Iorig.shape)

		self.dx = self.cx*w*zf - self.width/2.
		self.dy = self.cy*h*zf - self.height/2.

		R = np.eye(3)
		R = np.matmul(R,np.matrix([[zf,0,-self.dx],[0,zf,-self.dy],[0,0,1]],dtype=float))
		R = np.matmul(R,perspective_transform((w,h),angles=self.angles))

		self.R = R
		self.Rinv = np.linalg.inv(R)
예제 #3
0
def augment_sample(I,pts,dim):

	maxsum,maxangle = 120,np.array([80.,80.,45.])
	angles = np.random.rand(3)*maxangle
	if angles.sum() > maxsum:
		angles = (angles/angles.sum())*(maxangle/maxangle.sum())

	I = im2single(I)  # /255.0 归一化
	iwh = getWH(I.shape) #得到宽高

	whratio = random.uniform(2.,4.) # 随即取一个2-4的值作为宽高比
	wsiz = random.uniform(dim*.2,dim*1.) # 宽取0.2*208 到 208之间
	
	hsiz = wsiz/whratio

	dx = random.uniform(0.,dim - wsiz)
	dy = random.uniform(0.,dim - hsiz)

    #下面涉及到整个变换
    # In the first 3 lines, the original corner points are transformed into a rectangular bounding box with aspect ratio 
    # varying between 2:1 and 4:1. In other words, T matrix rectifies the LP with a random aspect ratio. Then, 
    
	pph = getRectPts(dx,dy,dx+wsiz,dy+hsiz)
	pts = pts*iwh.reshape((2,1))  #将点恢复到真实坐标值
	T = find_T_matrix(pts2ptsh(pts),pph)
    #in the next two lines, a perspective transformation with random rotation (H) is combined with T to 
    #generate the final transformation.
	H = perspective_transform((dim,dim),angles=angles)
	H = np.matmul(H,T)

	Iroi,pts = project(I,H,pts,dim)
	
	hsv_mod = np.random.rand(3).astype('float32')
	hsv_mod = (hsv_mod - .5)*.3
	hsv_mod[0] *= 360
	Iroi = hsv_transform(Iroi,hsv_mod)
	Iroi = np.clip(Iroi,0.,1.)

	pts = np.array(pts)

	if random.random() > .5:
		Iroi,pts = flip_image_and_pts(Iroi,pts)

	tl,br = pts.min(1),pts.max(1)
	llp = Label(0,tl,br)

	return Iroi,llp,pts
예제 #4
0
def augment_sample(I,pts,dim):

	maxsum,maxangle = 120,np.array([80.,80.,45.])
	angles = np.random.rand(3)*maxangle
	if angles.sum() > maxsum:
		angles = (angles/angles.sum())*(maxangle/maxangle.sum())

	# chuyển qua ma trận float32, chia cho 255
	I = im2single(I)
	# Lấy w, h dạng ma trận
	iwh = getWH(I.shape)

	whratio = random.uniform(2.,4.)
	wsiz = random.uniform(dim*.2,dim*1.)
	
	hsiz = wsiz/whratio

	dx = random.uniform(0.,dim - wsiz)
	dy = random.uniform(0.,dim - hsiz)

	pph = getRectPts(dx,dy,dx+wsiz,dy+hsiz)
	# Lấy tọa độ thật
	pts = pts*iwh.reshape((2,1))
	T = find_T_matrix(pts2ptsh(pts),pph)

	H = perspective_transform((dim,dim),angles=angles)
	H = np.matmul(H,T)

	Iroi,pts = project(I,H,pts,dim)
	
	hsv_mod = np.random.rand(3).astype('float32')
	hsv_mod = (hsv_mod - .5)*.3
	hsv_mod[0] *= 360
	Iroi = hsv_transform(Iroi,hsv_mod)
	Iroi = np.clip(Iroi,0.,1.)

	pts = np.array(pts)

	if random.random() > .5:
		Iroi,pts = flip_image_and_pts(Iroi,pts)

	# lấy giá trị tọa độ top-left, bot-right
	tl,br = pts.min(1),pts.max(1)
	llp = Label(0,tl,br)

	return Iroi,llp,pts