opencv如何实现图片缩放与镜像
更新:HHH   时间:2023-1-7


这篇文章主要介绍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)


程序运行后效果如下图:

以上是“opencv如何实现图片缩放与镜像”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注天达云行业资讯频道!

返回互联网科技教程...