Opencv python画图

import cv2 as cv
import numpy as np
#先画一张底图
img = np.zeros((512, 512, 3), np.uint8)
#在img底图上画一条线段,第一个其实坐标,二终点,三颜色,四线条长度
cv.line(img, (0, 0), (511, 511), (255, 0, 0), 5)
#矩形,左上角和右下角
cv.rectangle(img, (384, 0), (510, 128), (0, 255, 0), 3)
#圆,圆心坐标,半径
cv.circle(img, (447, 63), 63, (0, 0, 255), -1)
#椭圆,中心位置,轴长度(长轴,短轴),顺时针倾斜角度,顺时针开始的角度(水平右边),结束角度,颜色,粗细
cv.ellipse(img, (256, 256), (100, 50), 0, 30, 160, (0, 255, 0), -1)
#画多边形,需要知道顶点
pts=np.array([[10, 5], [20, 30], [70, 20], [50 , 10]], np.int32)
pts=pts.reshape((-1, 1, 2))
cv.polylines(img, [pts], True, (0, 255, 255))
#True 闭合多边形,False不闭合
#在图像中添加文本
font = cv.FONT_HERSHEY_SIMPLEX
#左下角坐标,字体类型,字体大小,颜色,厚度,线条
cv.putText(img, 'OpenCV', (10, 500), font, 4, (255, 255, 255), 2, cv.LINE_AA)

cv.imshow('image', img)
cv.waitKey(0)
cv.destroyAllWindows()

调色板:

import numpy as np
import cv2 as cv


def nothing(x):
    pass


img = np.zeros((300, 512, 3), np.uint8)
cv.namedWindow("image")
#创建颜色变化的轨迹栏
cv.createTrackbar('R', 'image', 0, 255, nothing)
cv.createTrackbar('G', 'image', 0, 255, nothing)
cv.createTrackbar('B', 'image', 0, 255, nothing)
switch = '0 : OFF \n1 : ON'
cv.createTrackbar(switch, 'image', 0, 1, nothing)
while True:
    cv.imshow('image', img)
    if cv.waitKey(1) == ord('q'):
        break
    r = cv.getTrackbarPos('R', 'image')
    g = cv.getTrackbarPos('G', 'image')
    b = cv.getTrackbarPos('B', 'image')
    s = cv.getTrackbarPos(switch, 'image')
    if s == 0:
        img[:] = 0
    else:
        img[:] = [b, g, r]
cv.destroyAllWindows()

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值