本文實(shí)例為大家分享了python opencv實(shí)現(xiàn)切變換的具體代碼,供大家參考,具體內(nèi)容如下
# -*- coding:gb2312 -*- import cv2 from math import * import numpy as np img = cv2.imread("3-2.jpg") height,width=img.shape[:2] degreeAffine=45 #切變換最后結(jié)果 heightAffine=height widthAffine=int(2*height*tan(radians(degreeAffine))+width) # 隨意兩點(diǎn)得到仿射變換矩陣 # point1=np.float32([[50,50],[200,50],[50,200]]) # point2=np.float32([[50,50],[100,50],[50,200]]) # matAffine=cv2.getAffineTransform(point1,point2) #如果結(jié)果是正的圖片 tempY=(widthAffine+1)/2-width/2 tempX=(heightAffine+1)/2-height/2 temp=np.zeros((heightAffine,widthAffine,3),np.uint8)+255 temp[tempX:(tempX+height),tempY:(tempY+width)]=img cv2.imshow("temp",temp) #仿射變換矩陣 matAffine=np.zeros([2,3]) matAffine[0,0]=1 matAffine[0,1]=tan(radians(degreeAffine)) matAffine[0,2]=(widthAffine-width)/2 matAffine[1,0]=0 matAffine[1,1]=1 matAffine[1,2]=(heightAffine-height)/2 imgAfiine=cv2.warpAffine(img,matAffine,(widthAffine,heightAffine),borderValue=(255,255,255)) cv2.imwrite("temp.jpg",temp) cv2.imwrite("imgAffine.jpg",imgAfiine) cv2.imshow("imgAffine",imgAfiine)
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。