用特征点已经生成的H矩阵,演示轮廓变化,直接上代码,
import numpy as np
import cv2
import matplotlib.pyplot as plt
import pickle
from panoramah import *
RESIZE_H=1000
RESIZE_W=750
dumpname='dump04'+'.txt' #用dump方法在之前保存的H矩阵
with open(dumpname,'rb') as f:
H=pickle.load(f)
a = np.array([[0,0], [RESIZE_W,0], [RESIZE_W,RESIZE_H], [0,RESIZE_H]])
# b = np.array([[[100,100], [200,230], [150,200], [100,220]]], dtype = np.int32)
print(a.shape)
b=np.ones((a.shape[0],1),)
tmp=np.c_[a,b].T
tmp=np.dot(H, tmp)
print(tmp)
b= tmp[2,:][np.newaxis, :].repeat(3,axis=0) #增加一维之后,复制度量一行
tmp=(tmp/b)[:2,:].T
print(tmp)
im = np.zeros((1652, 1852,3), dtype = np.uint8)
cv2.fillPoly(im, np.array([a, tmp], np.int32), (255, 255, 255)) #显示的时候需要np.int32
# cv2.fillPoly(im, [], (255, 255, 255))
# cv2.fillPoly(im, b, 255)
plt.imshow(im)
plt.show()
另外,使用opencv批量生成拼接图时,常会有超时卡死机器的现象,可以参考这个原文:https://blog.csdn.net/dcrmg/article/details/82850457
提供了装饰器和线程控制,两个方法