Mis a jour le 2024-03-17, 13:4

Transformations géométriques

Image de départ : newImg = img
Transformations simples :
Mise à l'échelle / changement de taille :
Exemple de changement d'échelle : newImg = cv2.resize(img, None, fx = 1, fy = 0.5, interpolation = cv2.INTER_CUBIC)
Rotation :
Exemple de rotation en diminuant la taille et avec reflexion sur les bordures pour les endroits qui sont vides après rotation : transfoMatrix = cv2.getRotationMatrix2D((img.shape[0] // 2, img.shape[1] // 2), 30, 0.8) newImg = cv2.warpAffine(img, transfoMatrix, None, flags = cv2.INTER_LINEAR, borderMode = cv2.BORDER_REFLECT)
Transformation affine :
Exemple transformation affine : import numpy transfoMatrix = cv2.getAffineTransform(numpy.array([[0, 0], [10, 0], [0, 10]], dtype = numpy.float32), numpy.array([[0, 0], [10, 0], [5, 10]], dtype = numpy.float32)) newImg = cv2.warpAffine(img, transfoMatrix, None)
On peut inverser une transformation affine : exemple : inversion de la transformation affine ci-dessus : transfoMatrix = cv2.getAffineTransform(numpy.array([[0, 0], [10, 0], [0, 10]], dtype = numpy.float32), numpy.array([[0, 0], [10, 0], [5, 10]], dtype = numpy.float32)) transfoMatrix = cv2.invertAffineTransform(transfoMatrix) newImg = cv2.warpAffine(img, transfoMatrix, None)

Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert