opencv常用的畫圖介面示例
阿新 • • 發佈:2021-02-06
技術標籤:OpenCV
1. 畫圖結果
2. 程式碼
# -*- coding: utf-8 -*- # @Time : 2021/1/31 下午4:36 # @Author : zxq # @File : func.py # @Software: PyCharm import numpy as np import cv2 as cv # Create a black image img = np.zeros((512, 512, 3), np.uint8) # line # Draw a diagonal blue line with thickness of 5 px cv.line(img, (0, 0), (511, 511), (255, 0, 0), 5) # rectangle cv.rectangle(img, pt1=(384, 0), pt2=(510, 128), color=(0, 255, 0), thickness=3) # circle cv.circle(img, (447, 63), radius=63, color=(0, 0, 255), thickness=-1) # ellipse # angle: rotation angle, cv.ellipse(img, center=(256, 256), axes=(100, 50), angle=90, startAngle=90, endAngle=180, color=255, thickness=-1) # Polygon pts = np.array([[10, 5], [20, 30], [70, 20], [50, 10]], np.int32) pts = pts.reshape((-1, 1, 2)) # (4, 2)->(4, 1, 2) cv.polylines(img, pts=[pts, pts+40], isClosed=True, color=(0, 255, 255)) cv.namedWindow('img', 0), cv.imshow('img', img), cv.waitKey()