话不多说,先上图:
img = cv2.imread('yz.jpeg',cv2.IMREAD_COLOR)
imgRGB = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
dst = cv2.resize(imgRGB, (400, 400))
Image.fromarray(circle2rectangle(dst,(200,200),200,100))
方法代码:
def circle2rectangle(img,circle_center,R,W):
C=int(2*R*np.pi)
rectangle = np.zeros((W,C,3),dtype='uint8')
x=np.arange(C).reshape(-1,1)
y=np.arange(W).reshape(1,-1)
x,y=np.broadcast_arrays(x,y)
theta = np.pi*2/C*(x+1)
r= R-y-1
p_x = (circle_center[0] - r*np.sin(theta)+0.5).astype(int)-1
p_y = (circle_center[1] + r*np.cos(theta)+0.5).astype(int)-1
rectangle[y,x,:] = img[p_y,p_x,:]
return rectangle