• 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)

    三张图片效果如下:

  • 相关阅读:
    IO模型
    协程
    线程
    进程
    网络编程
    模块二
    面向对象(二)
    面向对象(一)
    优化异常报错
    python 模块
  • 原文地址:https://www.cnblogs.com/fensnote/p/13436494.html
Copyright © 2020-2023  润新知