最近忙着写论文,众所周知,论文偷图截图往上贴是不行的,凭老师阅篇无数的眼睛,论文那个地方不是22磅都能给你找出来,所以网上的感人画质图片是不可能用上的。
但是又想展现自己的实验数据(其实就是水页数的),把实验用到的图片数据集整个九宫格还是不错的。(水的美滋滋)
课题是VO,多多少少还是会接触Python,目前大概看Python也就5天吧。
于是想用Python写个九宫格拼图,
参考了一下网上代码,但自己运行老报错,(pip有问题)。于是自己手撸了,
老实人写法,一个一个图拼接的,对大部分人这代码应该是没什么参考价值了,哈哈哈(和我一样的小白可以参考一下,救急专用)。代码如下,硬核手撸,主要不太熟悉Python只能写成这样了
程序缩小了图片尺寸,程序内容大家应该一眼都能看懂
`#!/usr/bin/python
import cv2 as cv
import numpy as np
img1 = cv.imread(’./left-0009.png’,1)
img2 = cv.imread(’./left-0010.png’,1)
img3 = cv.imread(’./left-0011.png’,1)
img4 = cv.imread(’./left-0012.png’,1)
img5 = cv.imread(’./left-0013.png’,1)
img6 = cv.imread(’./left-0014.png’,1)
img7 = cv.imread(’./left-0015.png’,1)
img8 = cv.imread(’./left-0016.png’,1)
img9 = cv.imread(’./left-0017.png’,1)
imgif = img1.shape
h = imgif[0]
w = imgif[1]
new_h = int(h0.5)
new_w = int(w0.5)
img1_new = cv.resize(img1, (new_w,new_h))
img2_new = cv.resize(img2, (new_w,new_h))
img3_new = cv.resize(img3, (new_w,new_h))
img4_new = cv.resize(img4, (new_w,new_h))
img5_new = cv.resize(img5, (new_w,new_h))
img6_new = cv.resize(img6, (new_w,new_h))
img7_new = cv.resize(img7, (new_w,new_h))
img8_new = cv.resize(img8, (new_w,new_h))
img9_new = cv.resize(img9, (new_w,new_h))
img12 = np.hstack((img1_new,img2_new))
img123 = np.hstack((img12,img3_new))
img45 = np.hstack((img4_new,img5_new))
img456 = np.hstack((img45,img6_new))
img78 = np.hstack((img7_new,img8_new))
img789 = np.hstack((img78,img9_new))
Vimg1_6 = np.vstack((img123,img456))
Vimg1_9 = np.vstack((Vimg1_6,img789))
cv.imshow(’’,Vimg1_9)
cv.imwrite(’./img1_9.png’,Vimg1_9)
cv.waitKey()`