python-opencv有效随机角度旋转

imgb=cv2.imread(r"F:\Data_library\steel\Treadimage2\big.png")
imgs=cv2.imread(r"F:\Data_library\steel\Treadimage2\samll.png")
tmp_rot=np.zeros_like(imgs)
#固定角度旋转
tmp_rot=cv2.rotate(imgs,cv2.ROTATE_90_CLOCKWISE,tmp_rot)
#翻转0,1,-1
cv2.flip(imgs,-1,tmp_rot)
#自由旋转角度设置
angle=60
new_h=int(abs(imgs.shape[0]*np.cos(angle/180.*np.pi))+abs(imgs.shape[1]*np.sin(angle/180.*np.pi)))
new_w=int(abs(imgs.shape[0]*np.sin(angle/180.*np.pi))+abs(imgs.shape[1]*np.cos(angle/180.*np.pi)))
M1 = cv2.getRotationMatrix2D((int((imgs.shape[1])/2.),int((imgs.shape[0])/2.)),angle,1)
//#np.random.randint(0,360) (int(imgs.shape[1]/2.),int(imgs.shape[0]/2.)
M2 =np.float32([[0,0,(new_w-imgs.shape[1])/2.],[0,0,(new_h-imgs.shape[0])/2.]])
//# M2 =np.float32([[1,0,new_w-imgs.shape[1]],[0,1,new_h-imgs.shape[0]]])
//# M=np.matmul(M1,M2.T)
M=M1+M2
dst = cv2.warpAffine(imgs, M, (new_w,new_h))
cv2.namedWindow(“randb”)
cv2.imshow(“randb”,dst)
cv2.waitKey()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值