Python实现图像分屏

Python实现图像分屏

import cv2
import numpy as np

img=cv2.imread('1280_720.bmp')

print(img.shape)
print(img.shape)

h,w,c0=img.shape

h0 = int(h/2)
w0 = int(w/2)
#创建图像
img0=np.zeros((h0,w0,3),dtype=np.uint8)
img1=np.zeros((h0,w0,3),dtype=np.uint8)
img2=np.zeros((h0,w0,3),dtype=np.uint8)
img3=np.zeros((h0,w0,3),dtype=np.uint8)

#4分屏
img0 = img[0:h0, 0: w0]
img1 = img[0:h0, w0:w0*2]
img2 = img[h0:h0*2, 0:w0]
img3 = img[h0: h0*2, w0:w0*2]
#显示原始图像和处理后的图像
cv2. namedWindow("orignal",0)
cv2.resizeWindow("orignal", 600, 360)#设置窗口大小
cv2.namedWindow("img0", 0)
cv2.resizeWindow("img0", 300, 180)
#设置窗口大小
cv2.namedWindow("img1", 0)
cv2.resizeWindow("img1", 300, 180)
#设置窗口大小
cv2.namedWindow("img2", 0)
cv2.resizeWindow("img2", 300, 180)
#设置窗口大小
cv2.namedWindow("img3", 0)
cv2.resizeWindow("img3", 300,180)#设置窗口大小
cv2.imshow("orignal", img)
cv2.imshow("img0", img0)
cv2.imshow("img1", img1)
cv2.imshow("img2", img2)
cv2.imshow("img3", img3)
cv2. waitKey(0)
View Code

 

posted @ 2024-02-23 14:12  有翅膀的大象  阅读(25)  评论(0编辑  收藏  举报