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

Dessin de formes

On peut dessiner sous OpenCV. Mais, attention :
Traçage d'une ligne :
Traçage d'un rectangle :
Traçage d'un cercle :
Traçage d'une ellipse (qui peut être partielle) :
Traçage d'un polyône :
Exemple de traçage de formes : import numpy newImg = 255 * numpy.ones((274, 365, 3), numpy.uint8) cv2.rectangle(newImg, (10, 100), (100, 150), (0, 255, 255), -1) cv2.rectangle(newImg, (110, 200), (200, 250), (255, 0, 0), 1) cv2.circle(newImg, (180, 130), 20, (0, 255, 0), -1) cv2.ellipse(newImg, (250, 180), (30, 10), 30, 90, 360, (255, 0, 255), -1) cv2.line(newImg, (0, 0), (264, 100), (0, 0, 255), 4) points = numpy.array([[200, 25], [240, 50], [270, 90], [270, 50]], numpy.int32) points = points.reshape((-1, 1, 2)) cv2.polylines(newImg, [points, points + 80], True, (100, 100, 100), 2) cv2.putText(newImg, 'texte', (10, 200), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 125, 0), 1)
Traçage de texte :
Exemple montrant les possibilités de polices : import numpy newImg = 255 * numpy.ones((274, 365, 3), numpy.uint8) cv2.putText(newImg, 'Font_Hershey_Plain', (10, 20), cv2.FONT_HERSHEY_PLAIN, 1, (0, 125, 0), 1) cv2.putText(newImg, 'Font_Hershey_Complex', (10, 40), cv2.FONT_HERSHEY_COMPLEX, 0.5, (0, 125, 0), 1) cv2.putText(newImg, 'Font_Hershey_Complex_Small', (10, 60), cv2.FONT_HERSHEY_COMPLEX_SMALL, 0.8, (0, 125, 0), 1) cv2.putText(newImg, 'Font_Hershey_Duplex', (10, 80), cv2.FONT_HERSHEY_DUPLEX, 0.5, (0, 125, 0), 1) cv2.putText(newImg, 'Font_Hershey_Plain', (10, 100), cv2.FONT_HERSHEY_PLAIN, 1, (0, 125, 0), 1) cv2.putText(newImg, 'Font_Hershey_Script_Complex', (10, 120), cv2.FONT_HERSHEY_SCRIPT_COMPLEX, 0.5, (0, 125, 0), 1) cv2.putText(newImg, 'Font_Hershey_Script_Simplex', (10, 140), cv2.FONT_HERSHEY_SCRIPT_SIMPLEX, 0.5, (0, 125, 0), 1) cv2.putText(newImg, 'Font_Hershey_Simplex', (10, 160), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 125, 0), 1) cv2.putText(newImg, 'Font_Hershey_Triplex', (10, 180), cv2.FONT_HERSHEY_TRIPLEX, 0.5, (0, 125, 0), 1)

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