python中利用opencv對圖片進行縮放


import cv2

if __name__ == '__main__':
     img = cv2.imread(r'C:\Users\Administrator\Desktop\img1791.png')
     height, width = img.shape[:2]
     #縮小圖片
     size = (int(width*0.5), int(height*0.5))
     shrink = cv2.resize(img, size, interpolation = cv2.INTER_AREA)
     cv2.imshow("縮小", shrink)
     cv2.imwrite(r'C:\Users\Administrator\Desktop\img1.png', shrink)
     #放大圖片
     fx = 1.6
     fy = 1.2
     enlarge = cv2.resize(img, (0, 0), fx = fx, fy = fy, interpolation = cv2.INTER_CUBIC)
     cv2.imshow("放大", enlarge)    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM