今天学习图像拼图,就有点像拼图游戏那样的
import cv2
import os
def cv_show_image(name, img):
cv2.imshow(name, img)
cv2.waitKey(0) # 等待时间,单位是毫秒,0代表任意键终止
cv2.destroyAllWindows()
# 将一个文件目录下的所有图像文件都列出来
filedir = "D:/estimages/image"
files = os.listdir(filedir)
print(files)
images = []
for file in files:
img = cv2.imread('{}/{}'.format(filedir, file))
images.append(img)
print(len(images))
stitcher = cv2.Stitcher.create()
status, result = stitcher.stitch(images)
if status == cv2.STITCHER_OK:
print("Success!")
cv_show_image("final", result)
cv2.imwrite("images/final.jpg", result)
else:
print("Error!")