In this article, we share the example of opencv to achieve the effect of image scaling specific code for your reference, the details are as follows
Image Zoom:
Image scaling i.e. resizing the image, i.e. zooming in or out
(src,dsize,fx=0,fy=0,interpolation=cv2.INTER_LINEAR)
Parameters:
Implementation Code:
import cv2 as cv import as plt # Chinese display configuration ['-serif']=['SimHei'] # Used to display Chinese labels properly ['axes.unicode_minus']=False # Used to display the negative sign normally # Load image img0 = ('img/') # Image scaling # Absolute size scaling rows, cols = [:2] res0 = (img0,(3*cols,3*rows),interpolation=cv.INTER_CUBIC) # Relative size scaling, the second parameter should be set to None if relative scaling is used. res1 = (img0, None, fx = 0.5, fy = 0.5) # View image size print() print() print() # Image display fig, axes = (nrows=1,ncols=3,figsize=(10,8),dpi=100) axes[0].imshow(res0[:,:,::-1]) axes[0].set_title("Absolute Scale Magnification") axes[1].imshow(res1[:,:,::-1]) axes[1].set_title("Relative scale reduction") axes[2].imshow(img0[:,:,::-1]) axes[2].set_title("Original image.") ()
Run results:
This is the whole content of this article.