Today let’s learn how to scale an image using OpencV.
cv2.resize()
Opencv provides the cv2.resize() function to scale the image.Copy the code
Here I’m going to go directly to baidu’s graph, which is pretty good,
def suofang_demo(image)Scale the image res to the specified width and height= cv.resize(image, (65.75))
cv.imshow("res"Res2 = cv.resize(image, None, fx=2, fy=2, interpolation=cv.INTER_LINEAR)
cv.imshow('res2', res2)
Copy the code
(I won’t finish here)
PyrDown ()
OpenCV provides a function cv2.PyrDown () to implement downsampling in an image Gaussian pyramid operation with the syntax: DST = cv2.pyrDown(SRC [, dstsize[, borderType]]) DST for the target image. ● SRC is the original image. ● DSTsize is the size of the target image. ● borderType is the boundary type. The default value is BORDER_DEFAULTCopy the code
Code:
def suofang_demo2(image): # Shrink pyrDown () r1= cv.pyrDown(image)
r2 = cv.pyrDown(r1)
r3 = cv.pyrDown(r2)
cv.imshow("r1", r1)
cv.imshow("r2", r2)
cv.imshow("r3", r3)
Copy the code
It can be seen from the above results that after downward sampling, the number of rows and columns of the image will be half of the original, and the overall size of the image will be 1/4 of the original.Copy the code
CV. PyrUp ()
Similar to pyrDown, zoom inCopy the code
def suofang_demo3(image): # put pyUp () r1= cv.pyrUp(image)
r2 = cv.pyrUp(r1)
cv.imshow("r1", r1)
cv.imshow("r2", r2)
Copy the code
It can be seen from the above results that the number of rows and columns of the image will be doubled and the overall size of the image will be quadrupled after upward sampling.Copy the code