本文實(shí)例為大家分享了python opencv旋轉(zhuǎn)圖像的具體代碼,保持圖像不被裁減,供大家參考,具體內(nèi)容如下
創(chuàng)新互聯(lián)建站專注于樊城企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站,商城網(wǎng)站建設(shè)。樊城網(wǎng)站建設(shè)公司,為樊城等地區(qū)提供建站服務(wù)。全流程按需制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)# -*- coding:gb2312 -*- import cv2 from math import * import numpy as np img = cv2.imread("3-2.jpg") height,width=img.shape[:2] degree=45 #旋轉(zhuǎn)后的尺寸 heightNew=int(width*fabs(sin(radians(degree)))+height*fabs(cos(radians(degree)))) widthNew=int(height*fabs(sin(radians(degree)))+width*fabs(cos(radians(degree)))) matRotation=cv2.getRotationMatrix2D((width/2,height/2),degree,1) matRotation[0,2] +=(widthNew-width)/2 #重點(diǎn)在這步,目前不懂為什么加這步 matRotation[1,2] +=(heightNew-height)/2 #重點(diǎn)在這步 imgRotation=cv2.warpAffine(img,matRotation,(widthNew,heightNew),borderValue=(255,255,255)) cv2.imshow("img",img) cv2.imshow("imgRotation",imgRotation) cv2.waitKey(0)