两种方法拼接
#img = np.vstack((img, img2)) # vstack按垂直方向,hstack按水平方向 img = np.concatenate((img, img2), axis=0) # axis=0 按垂直方向,axis=1 按水平方向
统一图片大小,保证数组维度一致避免拼接失败。 把图片全部调整成第一张图的宽高
def img_size(image_names,width, height): for i in image_names: img = cv2.imread(os.path.join(img_path, i)) img_resize = cv2.resize(img, (width, height), interpolation=cv2.INTER_CUBIC) cv2.imwrite(os.path.join(img_path, i), img_resize) print(os.path.join(img_path, i))
完整案例,拼接文件夹中的所有图片
import cv2 import os import numpy as np def img_size(image_names,width, height): for i in image_names: img = cv2.imread(os.path.join(img_path, i)) img_resize = cv2.resize(img, (width, height), interpolation=cv2.INTER_CUBIC) cv2.imwrite(os.path.join(img_path, i), img_resize) print(os.path.join(img_path, i)) if __name__ == '__main__': img_path = r'F:\studytest' image_names = [name for name in os.listdir(img_path) if os.path.splitext(name)[1] == ".jpg"] img1 = cv2.imread(os.path.join(img_path, image_names[0])) width, height = img1.shape[:2][::-1] img_size(image_names,width, height) img = img1 for i in range(1,len(image_names)): img_page = image_names[i] img2 = cv2.imread(os.path.join(img_path, img_page)) #img = np.vstack((img, img2)) # vstack按垂直方向,hstack按水平方向 img = np.concatenate((img, img2), axis=0) # axis=0 按垂直方向,axis=1 按水平方向 cv2.imwrite(os.path.join(img_path,"res.jpg"), img) # cv2.imshow("img",img) # cv2.waitKey() ``
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 范文芳.1996-FNNTASY【HYPE】【WAV+CUE】
- 纯音入心系列纯音乐《韵味古筝曲》1CD[MP3][146.2MB]
- 纯音入心系列纯音乐《古筝系列-传统乐曲》1CD[MP3][974.7MB]
- 纯音入心系列纯音乐《古筝系列-弦凝指咽声停处》1CD[MP3][656.5MB]
- 群星.1994-大烂片2辑【派森】【WAV+CUE】
- 吴倩莲.1997-望爱【EMI百代】【WAV+CUE】
- 杨千嬅.2002-万紫千红演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郭采洁.2015-Begin.Again爱造飞鸡【华纳】【FLAC分轨】
- 许志安.2011-ON.AND.ON【东亚】【WAV+CUE】
- 潘秀琼.1994-木兰从军【名将】【WAV+CUE】
- 纯音入心系列纯音乐《古筝系列-当流行乐遇到古筝》1CD[MP3][1.9GB]
- 纯音入心系列纯音乐《精选古筝名曲100首》1CD[MP3][388.7MB]
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]