[PYTHON EXERCISE] HOW TO DRAW POLYGONES IN PYTHON WITH OPENCV VERSION 2.0

[PYTHON EXERCISE] HOW TO DRAW POLYGONES IN PYTHON WITH OPENCV VERSION 2.0



The full program:

# -*- coding: utf-8 -*-
"""
Created on Thu May 10 08:59:10 2018

@author: Kiet Tram
"""

# 06 - Drawing Geometric Shapes

import numpy as np
import cv2

def main():
    img = np.zeros((512, 512, 3), np.uint8)
   
    # Draw three lines as a triangle
    cv2.line(img, (0, 99), (99, 0), (0, 255, 0), 2)
    cv2.line(img, (99, 0), (99, 99), (0, 255, 0), 2)
    cv2.line(img, (99, 99), (0, 99), (0, 255, 0), 2)
   
    # Draw a rectangle
    cv2.rectangle(img, (120, 0), (199, 99), (0, 0, 255), 2)
   
    # Draw a circle
    cv2.circle(img, (200, 250), 100, (0, 255, 0), -1)
   
    # Draw an ecllipse
    cv2.ellipse(img, (299,99), (50, 20), 0, 0, 360, (120, 223, 28), -1)
   
    points = np.array([[100, 200], [200, 300], [120, 400], [50, 150], [350, 20]], np.int32)
    points = points.reshape((-1, 1, 2))
    cv2.polylines(img, [points], True, (0, 255, 255))
   
    # Draw a text
    txt = 'Tram Vu Kiet handsome'
    cv2.putText(img, txt, (50, 450), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 0))
   
    cv2.imshow("Black board", img)
    cv2.waitKey(0)
    cv2.destroyWindow()
   
if __name__ == "__main__":
    main()



Thankfully!
Kiet Tram
From Vietnam

Comments