python opencv旋轉(zhuǎn)圖像(保持圖像不被裁減)
本文實例為大家分享了python opencv旋轉(zhuǎ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]
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 #重點在這步,目前不懂為什么加這步
matRotation[1,2] +=(heightNew-height)/2 #重點在這步
imgRotation=cv2.warpAffine(img,matRotation,(widthNew,heightNew),borderValue=(255,255,255))
cv2.imshow("img",img)
cv2.imshow("imgRotation",imgRotation)
cv2.waitKey(0)
效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python使用循環(huán)神經(jīng)網(wǎng)絡(luò)解決文本分類問題的方法詳解
這篇文章主要介紹了Python使用循環(huán)神經(jīng)網(wǎng)絡(luò)解決文本分類問題的方法,結(jié)合實例形式詳細(xì)分析了Python神經(jīng)網(wǎng)絡(luò)相關(guān)概念、原理及解決文本分類具體操作技巧,需要的朋友可以參考下2020-01-01
Python matplotlib繪制實時數(shù)據(jù)動畫
Matplotlib作為Python的2D繪圖庫,它以各種硬拷貝格式和跨平臺的交互式環(huán)境生成出版質(zhì)量級別的圖形。本文將利用Matplotlib庫繪制實時數(shù)據(jù)動畫,感興趣的可以了解一下2022-03-03
Python開發(fā)SQLite3數(shù)據(jù)庫相關(guān)操作詳解【連接,查詢,插入,更新,刪除,關(guān)閉等】
這篇文章主要介紹了Python開發(fā)SQLite3數(shù)據(jù)庫相關(guān)操作,結(jié)合實例形式較為詳細(xì)的分析了Python操作SQLite3數(shù)據(jù)庫的連接,查詢,插入,更新,刪除,關(guān)閉等相關(guān)操作技巧,需要的朋友可以參考下2017-07-07
Python pandas.DataFrame調(diào)整列順序及修改index名的方法
這篇文章主要介紹了Python pandas.DataFrame調(diào)整列順序及修改index名的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-06-06
關(guān)于數(shù)據(jù)分析之滾動窗口pandas.DataFrame.rolling方法

