Skip to main content

Posts

Showing posts with the label resize image

OpenCV Resize Image With Aspect Ratio

OpenCV Resize Image With Aspect Ratio The OpenCV resize() method, as the name suggests, resizes the image.  import cv2 def resize (i , window_height = 500 ): aspect_ratio = float (i.shape[ 1 ]) / float (i.shape[ 0 ]) window_width = window_height/aspect_ratio i = cv2.resize(i , ( int (window_height) , int (window_width))) return i img = cv2.imread( 'image.jpg' ) img_resized = resize(img , window_height = 640 ) cv2.imshow( "ResizedImage" , img_resized) cv2.waitKey( 0 ) cv2.destroyAllWindows()