Wednesday, 3 March 2021

python opencv 4 draw



#main.py
import numpy as np
import cv2

cap = cv2.VideoCapture("assets/Santa Barbara.mp4")

while True:
    ret, frame = cap.read()
    width = int(cap.get(3))
    height = int(cap.get(4))

    #line (frame, start, end, color, thickness)
    img = cv2.line(frame, (0, int(height/2)), (int(width/2), height), (159, 231, 249), 5)
    img = cv2.line(frame, (int(width/2), height), (width, int(height/2)), (159, 231, 249), 5)

    #rectangle (frame, up left corner, bottom right corner, color, thickness)
    img = cv2.rectangle(img, (int(width/4), int(height/4)), (int(3*width/4), int(3*height/4)), (96, 174, 39), 5)

    #circle (frame, center, radius, color, fill | thickness)
    img = cv2.circle(img, (int(width/2), int(height/2)), int(height/8), (0, 0, 255), -1)

    #text (frame, text, center, font, font scale, color, line thickness, line type)
    font = cv2.FONT_HERSHEY_SIMPLEX
    img = cv2.putText(img, 'Bob is Great', (10, height - 10), font, 2, (255, 255, 255), 5, cv2.LINE_AA)

    cv2.imshow('frame', img)

    if cv2.waitKey(1) == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

reference:

No comments:

Post a Comment