zhiqingstudy

Be a young person with knowledge and content

In opencv, image transformation is a tool we often use, including image scaling, image flip, image rotation, etc. How to operate it?
1. Image scaling: resize (src, dst, dsize, fx, fy, interpolation)
Src: image source (image path)
Dsize: the size of the target (how large to zoom to)
Fx: scaling factor of x-axis
Fy: scaling factor of y-axis
Dsize conflicts with fx and fy. If dsize is set, it is unnecessary to set fx and fy.
Interpolation: difference algorithm, which includes the following (specific algorithm for image scaling)
INTER_ NEAREST, proximity difference, fast speed, poor effect
INTER_ LINEAR, bilinear interpolation, default algorithm, fast speed and good effect
INTER_ CUBIC, three times difference, slightly lower speed, slightly better effect
INTER_ AREA, the best effect and the slowest speed

2. Flip of image: flip (img, flipCode) Img: specific image to flip
FlipCode:flipCode==0是上下翻转,flipCode>0是左右翻转,flipCode<0是上下加左右翻转

3. Image rotation: rotate (img, rotateCode) Img: specific image to rotate
RotateCode: the following values
ROTATE_ 90_ CLOCKWISE, 90 ° clockwise rotation
ROTATE_ 90180 ° rotation
ROTATE_ 90_ CUTERCLOCKWISE, 270 ° rotation
import cv2
from cv2 import ROTATE_90_CLOCKWISE
import numpy as np

# 导入一张图片
img=cv2.imread('20220627214919.jpg')

# 缩放图片
new_img=cv2.resize(img,dsize=None,fx=0.3,fy=0.3,interpolation=cv2.INTER_AREA)
# 翻转图片
new_img1=cv2.flip(img,-1)
# 旋转图片
new_img2=cv2.rotate(img,rotateCode=ROTATE_90_CLOCKWISE)

# 显示图片
cv2.imshow('new_img',new_img)
cv2.imshow('img',img)
cv2.imshow('new_img1',new_img1)
cv2.imshow('new_img2',new_img2)
cv2.waitKey(0)

comment
head sculpture
Code:
Related

Why you shouldn't stay at a job for more than 2 years?

3 harsh facts long-distance relationships

how to keep your girlfriend interested in a long-distance relationship




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号