cv图片局部放大

import cv2 as cv
import sys
import numpy as np
import matplotlib.pyplot as plt

if __name__ == '__main__':
    # 读取图像并判断是否读取成功390*568
    img = cv.imread('tu.jpg')
    # 需要放大的部分
    part = img[200:300, 250:350]


    if img is None is None:
        print('Failed to read picture')
        sys.exit()

    # # 1局部图和原图拼接
    # big = np.zeros((390, 668, 3))
    # big[0:390, :568, :] = img
    # big[0:100, 568:668, :] = part
    # # 先转为int型,可以在plt显示为图片
    # big = big.astype(int)
    # # 转为uint8,否则显示为一片黑
    # big = big.astype(np.uint8)
    # # cv.rectangle(img, 左下角=(x1, y1), 右下角=(x2, y2), 框BGR=(0, 255, 0), 框粗=1)
    # cv.rectangle(big, (568, 0), (668, 100), (255, 0, 0), 2)
    # cv.rectangle(big, (250, 200), (350, 300), (255, 0, 0), 2)
    # # cv.line(img, 点=(x1, y1), 点=(x2, y2), (0, 255, 0), 2)
    # big = cv.line(big, (350, 200), (568, 0), (0, 0, 255), 2)
    # big = cv.line(big, (350, 300), (568, 100), (0, 255, 0), 2)
    # cv.imshow('big', big)
    # # 按0关闭页面
    # cv.waitKey(0)
    # cv.destroyAllWindows()

    # 2原图像局部按比例缩放
    mask = cv.resize(part, (300, 300), fx=0, fy=0, interpolation=cv.INTER_LINEAR)
    big = np.zeros((390, 868, 3))
    big[0:390, :568, :] = img
    big[0:300, 568:868, :] = mask
    # 先转为int型,可以在plt显示为图片
    big = big.astype(int)
    # 转为uint8,否则显示为一片黑
    big = big.astype(np.uint8)
    # cv.rectangle(img, 左下角=(x1, y1), 右下角=(x2, y2), 框BGR=(0, 255, 0), 框粗=1)
    cv.rectangle(big, (568, 0), (868, 300), (255, 0, 0), 2)
    cv.rectangle(big, (250, 200), (350, 300), (255, 0, 0), 2)
    # cv.line(img, 点=(x1, y1), 点=(x2, y2), (0, 255, 0), 2)
    big = cv.line(big, (350, 200), (568, 0), (0, 0, 255), 2)
    big = cv.line(big, (350, 300), (568, 300), (0, 0, 255), 2)
    cv.imshow('big', big)
    # 按0关闭页面
    cv.waitKey(0)
    cv.destroyAllWindows()

 

原图见图中ID

局部放大的图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值