# @Time: 2024年10月03日 03:04
# @Author: orcakill
# @File: opencv.py
# @Description: opencv相关算法api
import cv2
import imageio
import numpy as np
[文档]
class BasicOpenCv:
[文档]
@staticmethod
def draw_rectangle(screen, x1: int, y1: int, x2: int, y2: int, img_path: str):
"""
画图,根据指定范围的坐标在原图上画框,并打印到指定地址
:param screen: 图像ndarray
:param x1: 图片左上角横坐标
:param y1: 图片左上角纵坐标
:param x2: 图片右下角横坐标
:param y2: 图片右下角纵坐标
:param img_path: 图片路径
:return: None
"""
cv2.rectangle(screen, (x1, y1), (x2, y2), (0, 0, 255), 2)
# 保存图片到本地磁盘
imageio.imsave(img_path, screen)
[文档]
@staticmethod
def draw_point(screen, pos, img_path: str):
"""
画图,根据指定范围的坐标在原图上画框,并打印到指定地址
:param screen: 图像 ndarray
:param pos: (横坐标,纵坐标)
:param img_path: 图片路径
:return: None
"""
rgb_image = cv2.cvtColor(screen, cv2.COLOR_RGB2BGR)
print(pos)
cv2.circle(rgb_image, pos, 5, (255, 0, 0), -1)
# 保存图片到本地磁盘
imageio.imsave(img_path, rgb_image)