五、图像绘制

一、线段绘制

import cv2
import numpy as np

newImageInfo = (500, 500, 3)
dst = np.zeros(newImageInfo, np.uint8)
# line
# 绘制线段 1 dst 2 begin 3 end 4 color
cv2.line(dst, (100, 100), (400, 400), (0, 0, 255))
# 5 line w,线条宽度
cv2.line(dst, (100, 200), (400, 200), (0, 255, 255), 20)
# 6 line type,线条类型,LINE_AA圆角更光滑
cv2.line(dst, (100, 300), (400, 300), (0, 255, 0), 20, cv2.LINE_AA)

# 绘制三角形
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(0)

在这里插入图片描述

二、矩形圆形绘制

import cv2
import numpy as np

newImageInfo = (500, 500, 3)
dst = np.zeros(newImageInfo, np.uint8)
#  1 2 左上角 3 右下角 4 参数5 fill -1代表填充, >0代表宽度 line w
cv2.rectangle(dst, (50, 100), (200, 300), (255, 0, 0), 5)  # 矩形
# 2 center 3 r
cv2.circle(dst, (250, 250), 50, (0, 255, 0), 2)  # 圆形
# 2 center 3 轴 4 angle 5 begin 6 end 7
cv2.ellipse(dst, (256, 256), (150, 100), 0, 0, 180, (255, 255, 0), -1)  # 椭圆

points = np.array([[150, 50], [140, 140], [200, 170], [250, 250], [150, 50]], np.int32)  # 任意多边形
print(points.shape)
points = points.reshape((-1, 1, 2))  # 矩阵转换
print(points.shape)
cv2.polylines(dst, [points], True, (0, 255, 255))
cv2.imshow('dst', dst)
cv2.waitKey(0)

在这里插入图片描述

三、文字图片绘制

1 - 文字绘制

import cv2

img = cv2.imread('image0.jpg', 1)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.rectangle(img, (200, 100), (500, 400), (0, 255, 0), 3)
# 1 dst,2 文字内容,3 坐标,4 字体,5 字体大小,6 color,7 粗细,8 line type
cv2.putText(img, 'this is flow', (100, 300), font, 1, (200, 100, 255), 2, cv2.LINE_AA)
cv2.imshow('src', img)
cv2.waitKey(0)

在这里插入图片描述

2 - 图片绘制

import cv2

img = cv2.imread('image0.jpg', 1)
height = int(img.shape[0] * 0.2)
width = int(img.shape[1] * 0.2)
imgResize = cv2.resize(img, (width, height))
for i in range(0, height):
    for j in range(0, width):
        img[i + 200, j + 350] = imgResize[i, j]
cv2.imshow('src', img)
cv2.waitKey(0)

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无休止符

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值