opencv图片缩放与镜像

一个练习的代码,先对图片进行缩放,然后再做镜像:

import cv2
import numpy as np

img = cv2.imread("src.jpg", 1)
cv2.imshow("src",img)

imgInfo = img.shape
height = imgInfo[0]
width  = imgInfo[1]
deep   =  imgInfo[2]

#图片大,镜像后太高屏幕显示不全,这里先缩放
matScale = np.float32([[0.8,0,0], [0,0.8,0]])
scale = cv2.warpAffine(img, matScale, (int(width*0.8), int(height*0.8)))  

cv2.imshow("scale", scale)

#重新获取缩放后的图片高与宽
imgInfo = scale.shape
height  = imgInfo[0]
width   = imgInfo[1]

#镜像的图片信息
newImgInfo = (height * 2, width, deep)
dest = np.zeros(newImgInfo, np.uint8)

#镜像
for i in range(0, height):
    for j in range(0, width):
        dest[i,j] = scale[i,j]
        dest[height*2 - i -1, j] = scale[i, j]

#画一个镜像与原图分割线        
for i in range(0, width):
    dest[height, i] = (0,0,255)

cv2.imshow("dst", dest)
cv2.waitKey(0)

三张图片效果如下:

发布了36 篇原创文章 · 获赞 39 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/wuquan_1230/article/details/87965940