import cv2
import numpy as np
img = cv2.imread("3.1.jpeg")
flower = cv2.resize(img,(200,200))
suiji = np.random.randint(256,size=(200,200,3),dtype = np.uint8) #此时设置了维度为3,否则默认维度为2,图片不能拼接size=(200,200,3),
img1 = np.zeros((200,200,3),np.uint8)
black = img1.copy()
black[:,:] = 0
green = img1.copy()
green[:,:,1] = 255
red = img1.copy()
red[:,:,2] = 255
black_white = black.copy()
for i in range(0,20):
for j in range(0,200):
black_white[i,j] = [255,255,255]
for i in range(40,60):
for j in range(0,200):
black_white[i,j] = [255,255,255]
for i in range(80,100):
for j in range(0,200):
black_white[i,j] = [255,255,255]
for i in range(120,140):
for j in range(0,200):
black_white[i,j] = [255,255,255]
white = img1.copy()
white[::] = 255
for i in range(150,200):
for j in range(150,200):
white[i,j] = [0,0,255]
#cv2.imshow("dst3",suiji)
#cv2.imshow("dst4",flower)
#cv2.imshow("dst5",black)
#cv2.imshow("dst6",green)
#cv2.imshow("dst7",red)
#cv2.imshow("dst8",black_white)
#cv2.imshow("dst9",white)
#img_h = np.hstack((dst1,dst1)) #水平拼接
#img_v = np.vstack((dst2,dst2)) #竖直拼接
a0 = np.hstack((flower,flower,suiji))
a1 = np.hstack((suiji,red,green))
a3 = np.hstack((black,black_white,white))
a4 = np.vstack((a0,a1,a3))
cv2.imshow("20040420",a4)
#a1 = np.hstack((suiji,red))
#ab2 = np.hstack((a1,green))
#a3 = np.hstack((black,black_white))
#ab3 = np.hstack((a3,white))
cv2.waitKey()
cv2.destroyAllWindows()
实验,将前面所学结合(各种类图片的创建及拼接)
最新推荐文章于 2024-08-30 12:42:13 发布