数据增强时的坐标旋转计算

坐标旋转计算


主要是在做数据增强时,需要进行轮廓旋转操作,但对于多轮廓的旋转只能通过自定义函数进行计算,这里主要是平移坐标原点至中心,旋转,再将原点平移至左上角,具体代码如下:

def rotateContours(image, degree, Contours):
   center = int(image.shape[0]/2), int(image.shape[1]/2)
   hc, wc = center*2
   R = cv2.getRotationMatrix2D(center, degree, 1.0)
   image = cv2.warpAffine(image, R, (wc, hc))
   
   Contours = Contours.reshape(-1, 2)
   Contours = Contours*[1, -1] + [-center[1], center[0]]
   rotate_Contours = np.dot(Contours, np.array([R[0,0], R[0,1], -R[0,1], R[0,0]]).reshape(2,2))
   rotated_Contours = rotate_Contours*[1, -1] + [center[1], center[0]]
   return image, np.array(rotated_Contours, dtype=int32)

def drawContours(image, Contours):
   # the Contours contain multi contour
   cnts = list()
   for contour in Contours:
      contour=np.array(contour).reshape(-1, 1, 2)
      cnts.append(contour)
   cv2.drawContours(image, cnts, -1, (0, 255, 0), 2)
   return image
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值