python
复制代码
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@author: LIFEI
@time: 2023/8/27 10:21
@file: im_rd.py
@project: main.py
@describe: TODO
"""
import cv2
import numpy as np
def mask(img_img):
# 创建一个点标记,cv2.drawMarker(img,点坐标,颜色,样式,线宽)
draw_marker = cv2.drawMarker(img_img, (256, 256), (255, 0, 0), cv2.MARKER_CROSS, thickness=8)
# 在点标记的基础上创建一个红色线条赋值给draw_line,cv2.line(draw_marker(img,起始点坐标,终止点坐标,颜色,线宽)
draw_line = cv2.line(draw_marker, (50, 50), (450, 450), (0, 0, 255), thickness=2)
# 在上述基础上画一个圆赋值给circle,cv2.circle(img,原点坐标,半径,颜色,线宽)
circle = cv2.circle(draw_line, (447, 100), 63, (0, 255, 0), 1)
# 在上述基础上画一个矩形赋值给rect,cv2.rectangle(img,左上角坐标,右下角坐标,颜色,线宽)
rect = cv2.rectangle(circle, (300, 300), (400, 400), (255, 0, 0), 3)
# 在上述基础上画一个椭圆ellipse,cv2.ellipse(img,原点,坐标轴,角度,起始角度,终止角度,颜色,线宽,线型,shift)
ellipse = cv2.ellipse(rect, (120, 120), (100, 50), 0, 0, 360, 255, 1)
# 在上述基础上绘制文字标记赋值给text
text = cv2.putText(ellipse, 'Open_cv', (400, 500), cv2.FONT_HERSHEY_SIMPLEX, 4, [255, 30, 56], 2)
# 返回上述结果
return text
if __name__ == '__main__':
img = cv2.imread(r"D:\data\img.png")
# 创建一个黑色背景图像赋值给img
# img = np.zeros((512, 512, 3), np.uint8)
# 显示上述标记
result = mask(img)
cv2.imshow("img", result)
# 等待
cv2.waitKey(0)
# 窗口
cv2.destroyAllWindows()