22网络赛第二部分任务二

import cv2
import numpy as np
import os



list_img_path=[]
for i in range(1,5):
    x=str(i)+'.jpg'
    list_img_path.append(x)


def imgpic(path):

    image = cv2.imread(path)
    image = cv2.resize(image,(800,800))
    imgInfo = image.shape
    height = int(imgInfo[0]/2)
    width = int(imgInfo[1]/2)
    deep = imgInfo[2]
    newImgInfo = (height, width, deep)
    dst = np.zeros(newImgInfo, np.uint8)

    for i in range(0, height):
        for j in range(0, width):
            dst[i, j] = image[400+i, 400+j]

    cv2.rectangle(dst, (100, 100), (300, 300), (255, 0, 0), 2)
    font = cv2.FONT_HERSHEY_SIMPLEX
    cv2.putText(dst, 'A', (185, 200), font, 1, (0, 255, 0), 4, 8)
    savepath = './3/'+path
    cv2.imwrite(savepath,dst,[int(cv2.IMWRITE_PNG_COMPRESSION),0])
    return dst
list_count = []
height=400
width=400
for i in list_img_path:
    list_count.append(imgpic(i))
four_view = np.zeros((height * 2 + 10, width * 2 + 10, 3), np.uint8)
four_view[:, :] = 255
for i in range(len(list_count)):
    row = i // 2
    col = i % 2
    # 将小图像复制到大画布上。
    np.copyto(four_view[(height + 10) * row:height * (row + 1) + 10 * row, (width + 10) * col:width * (col + 1) + 10 * col],
              list_count[i])
cv2.imshow('result', four_view)
cv2.waitKey(0)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值