Image zoom

In OpenCV, the function that implements image scaling is: cv2.resize(InputArray src, OutputArray dst, Size, fx, fy, interpolation)

After entering the Raspberry Pi 5 desktop, open a terminal and run the following command to start the container corresponding to Dofbot:

Access Jupyter Lab within Docker:

Code path:/root/Dofbot/4.opencv/2.Transform/01_zoom_pic.ipynb

Parameter explanation:

InputArray srcInput image
OutputArray dstOutput picture
SizeOutput image size
fx, fyScaling factors along the x-axis, y-axis
interpolationinsertion method

Interpolation method used by options:

INTER_NEARESTNearest neighbor interpolation
INTER_LINEARBilinear interpolation (default setting)
INTER_AREAResampling using pixel area relationships.
INTER_CUBICBicubic interpolation of 4x4 pixel neighborhoods
INTER_LANCZOS4Lanczos interpolation of 8x8 pixel neighborhoods

Notice:

  1. The output size format is (width, height)

  2. The default interpolation method is: bilinear interpolation

The main code is as follows:

After execution, you can see that the image is 800*800

After the execution is completed, you can see that the image is 400*400, scaled by half.

After execution, you can see that the image is 200*200, scaled by a quarter.

Next let’s talk about matplotlib: Python’s 2D drawing library.

Reference tutorial: https://www.runoob.com/numpy/numpy-matplotlib.html