Je suis assez sûr que mes images sont en niveaux de gris qui devrait être monocanal mais je reçois cette erreur et je ne sais pas comment travailler avec ça. Ci-dessous est mon code: Je travaille pour accélérer mon code en créant une pyramide d'images pour chaque image. La mise à l'échelle des images au plus petit format permet d'obtenir une estimation approximative et de l'agrandir.erreur: (-210) warpMatrix doit être matrice à virgule flottante monocanal dans la fonction cv :: findTransformECC
import cv2
import numpy as np
path = "R:\\ProcessedPhoto_in_PNG\\"
path1 = "R:\\AlignedPhoto_in_PNG_EUCLIDEAN\\"
nol = 3
warp_mode = cv2.MOTION_EUCLIDEAN
if warp_mode == cv2.MOTION_HOMOGRAPHY :
warp = np.eye(3, 3, dtype=np.float32)
else :
warp = np.eye(2, 3, dtype=np.float32)
warp = np.dot(warp, np.array([[1, 1, 2], [1, 1, 2], [1/2, 1/2, 1]])**(1-nol))
# Specify the number of iterations.
number_of_iterations = 5000;
# Specify the threshold of the increment
# in the correlation coefficient between two iterations
termination_eps = 1e-10;
# Define termination criteria
criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, number_of_iterations, termination_eps)
def alignment(criteria, warp_mode, warp, nol):
for i in range(1770,1869):
for level in range(nol):
im = cv2.imread(path + 'IMG_1770.png')
im1 = cv2.imread(path + 'IMG_%d.png'%(i))
sz = im1.shape
scale = 1/2**(nol-1-level)
im_1 = cv2.resize(im, None, fx= scale, fy = scale, interpolation=cv2.INTER_AREA)
im_2 = cv2.resize(im1, None, fx= scale, fy= scale, interpolation=cv2.INTER_AREA)
im_gray = cv2.cvtColor(im_1, cv2.COLOR_BGR2GRAY)
im1_gray = cv2.cvtColor(im_2, cv2.COLOR_BGR2GRAY)
# Run the ECC algorithm. The results are stored in warp_matrix.
warp = cv2.findTransformECC(im_gray, im1_gray, warp, warp_mode, criteria)
if level != nol-1:
# might want some error catching here to reset initial guess
# if your algorithm fails at some level of the pyramid
# scale up for the next pyramid level
warp = warp * np.array([[1, 1, 2], [1, 1, 2], [1/2, 1/2, 1]])
if warp_mode == cv2.MOTION_HOMOGRAPHY :
# Use warpPerspective for Homography
im1_aligned = cv2.warpPerspective (im1, warp, (sz[1],sz[0]), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP)
else :
# Use warpAffine for Translation, Euclidean and Affine
im1_aligned = cv2.warpAffine(im1, warp, (sz[1],sz[0]), flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP);
print(i)
cv2.imwrite(path1 + "AlignedEU_IMG_%d.png"%i , im1_aligned)
alignment(criteria, warp_mode, warp, nol)
convertir la variable 'warp' taper 'np.float32', puis continuez –