import cv2 import numpy as np rouge=np.array([ 0, 0, 255]) print(str(rouge)) mat= np.zeros((4, 2), dtype="float32") print(mat) imagette_couleur=np.zeros((4, 2,3), dtype="uint8") imagette_couleur[0][0]=rouge imagette_couleur[3][0]=rouge imagette_couleur[3][1]=rouge cv2.imwrite('imagette.png',imagette_couleur) src= np.zeros((4, 2), dtype="float32") dst= np.zeros((4, 2), dtype="float32") retval=cv2.getPerspectiveTransform(src,dst) #solveMethod= DECOMP_LU ''' matrice obtenue [[0. 0. 0.] [0. 0. 0.] [0. 0. 1.]] ''' xi=20 yi=30 Pi= np.zeros((3, 1), dtype="float32") Pi[0]=xi Pi[1]=yi Pi[2]=1 print(Pi) np.matmul(retval,Pi) maxWidth=2 maxHeight=2 dst = np.array([ [0, 0], [maxWidth - 1, 0], [maxWidth - 1, maxHeight - 1], [0, maxHeight - 1]], dtype="float32") src = np.array([ [0, 0], [maxWidth - 1, 0], [maxWidth - 1, maxHeight - 1], [0, maxHeight - 1]], dtype="float32") print(src) print(dst) retval=cv2.getPerspectiveTransform(src,dst) print(retval) #on obtient identité à la précision numérique près # tx=100 dst = np.array([ [0+tx, 0], [maxWidth - 1+tx, 0], [maxWidth - 1+tx, maxHeight - 1], [0+tx, maxHeight - 1]], dtype="float32") src = np.array([ [0, 0], [maxWidth - 1, 0], [maxWidth - 1, maxHeight - 1], [0, maxHeight - 1]], dtype="float32") retval=cv2.getPerspectiveTransform(src,dst) print(retval) img = cv2.imread('rubiks.jpg') [haut,larg,nbcomposantes]=img.shape print(haut) print(larg) dst=cv2.warpPerspective(img, retval, (haut,larg)) #affichage cv2.imshow('image1',dst) cv2.waitKey(0) cv2.destroyAllWindows()