python中如何确定一个区间,利用interval中的Intervl,可以得到一个区间,左闭右开;
open-CV强大的图片处理工具,但是bug也不少,安装模块不顺利,pip与conda安装都不顺利,可能还得自己去官网下载包,然后导入site-package里面就好。最近需要实现旋转,但是会发生裁剪,于是网上百度了大佬的,特此记录:(cv2打开图片的路径与一般的不一样,为"/",否则会报错)
import cv2
import math
def solu_image(path,name):
image=cv2.imread(path+"//"+name)
h,w=image.shape[:2]
deg=np.arange(45,405,45)#随机旋转一定的角度45的整数倍
degree=random.choice(deg)
heightNew=int(wabs(math.sin(math.radians(degree)))+habs(math.cos(math.radians(degree))))
widthNew=int(habs(math.sin(math.radians(degree)))+wabs(math.cos(math.radians(degree))))
matRotation=cv2.getRotationMatrix2D((w/2,h/2),degree,1)
matRotation[0,2] +=(widthNew-w)/2 #重新调整新图片的(x,y)
matRotation[1,2] +=(heightNew-h)/2
imgRotation=cv2.warpAffine(image,matRotation,(widthNew,heightNew),borderValue=(255,255,255))
path1=path+"//"+“crop.jpg”
cv2.imwrite(path1,imgRotation)