opencv图形绘制

绘制线段1

import numpy as np
import cv2
newImageInfo = (500,500,3)
dst = np.zeros(newImageInfo, np.uint8)
#line
cv2.line(dst, (100,100), (400,400), (0,0,255))
cv2.imshow("dst", dst)
cv2.waitKey()

opencv图形绘制

绘制线段2

import numpy as np
import cv2
newImageInfo = (500,500,3)
dst = np.zeros(newImageInfo, np.uint8)
#line
cv2.line(dst, (100,100), (400,400), (0,0,255))
cv2.line(dst, (100,200), (400,200), (0,255,255), 20)
cv2.imshow("dst", dst)
cv2.waitKey()

opencv图形绘制

绘制线段3 (设置线条类型,防锯齿化,使边缘更光滑)

import numpy as np
import cv2
newImageInfo = (500,500,3)
dst = np.zeros(newImageInfo, np.uint8)
#line
cv2.line(dst, (100,100), (400,400), (0,0,255))
cv2.line(dst, (100,200), (400,200), (0,255,255), 20)
cv2.line(dst, (100,300), (400,300), (0,255,255), 20, cv2.LINE_AA)
cv2.imshow("dst", dst)
cv2.waitKey()

opencv图形绘制

利用线段绘制三角形

import numpy as np
import cv2
newImageInfo = (500,500,3)
dst = np.zeros(newImageInfo, np.uint8)
cv2.line(dst, (200,150),(50,250),(25,100,255))
cv2.line(dst, (50,250),(400,380),(25,100,255))
cv2.line(dst, (400,380),(200,150),(25,100,255))
cv2.imshow("dst", dst)
cv2.waitKey()

opencv图形绘制

矩形绘制

import numpy as np
import cv2
newImageInfo = (500,500,3)
dst = np.zeros(newImageInfo, np.uint8)
#左上角和右下角的坐标, -1为矩形全部填充  若末位参数为大于0的整数则为矩形边框宽度
cv2.rectangle(dst, (50,100), (200,300), (255,0,0), -1)
cv2.imshow("dst", dst)
cv2.waitKey()

opencv图形绘制

圆形绘制

import numpy as np
import cv2
newImageInfo = (500,500,3)
dst = np.zeros(newImageInfo, np.uint8)
cv2.circle(dst, (250,250), (50), (0,255,0),2)
cv2.imshow("dst", dst)
cv2.waitKey()

opencv图形绘制

圆弧绘制

import numpy as np
import cv2
newImageInfo = (500,500,3)
dst = np.zeros(newImageInfo, np.uint8)
#2椭圆中心,3长短轴长度, 4圆弧偏转角度  5圆弧起始角度  6圆弧终止角度  8颜色  9是否填充
cv2.ellipse(dst, (256,256), (150,100), 0, 0, 180, (255,255,0), -1)
cv2.imshow("dst", dst)
cv2.waitKey()

opencv图形绘制

任意多边形绘制

import numpy as np
import cv2
newImageInfo = (500,500,3)
dst = np.zeros(newImageInfo, np.uint8)
#数组包含多边形的全部顶点,顺序
points = np.array([[150,50],[140,140],[200,170],[250,250],[150,50]],np.int32)
#参数3为是否闭合图形
cv2.polylines(dst,[points], True, (0,255,255))
cv2.imshow("dst",dst)
cv2.waitKey()

opencv图形绘制

上一篇:java面试题及答案2021,java最新面试题汇总(三十四)


下一篇:图像锐化