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)
22网络赛第二部分任务二
最新推荐文章于 2024-10-03 09:02:12 发布