1 Star 0 Fork 0

MiraBit/mmrotate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
testhall.py 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
MiraBit 提交于 2023-08-18 22:18 . f
import numpy as np
import cv2
import matplotlib.pyplot as plt
def draw_rect(rect):
# 在im画布上画矩形rect
im = np.zeros([240, 320], dtype = np.uint8)
cv2.polylines(im, [rect], 1, 255)
plt.imshow(im)
plt.show()
def rotate_rect(rect, angle):
# 输出rect旋转后的矩形四个点的坐标,angle为正及顺时针旋转,为负及逆时针旋转
(x,y),(w,h),a = cv2.minAreaRect(rect)
rect_r = ((x,y), (w,h), a+angle)
return cv2.boxPoints(rect_r).astype(np.int32)
# rect = np.array([[100, 50], [150, 50], [150, 150], [100, 150]], dtype=np.int32)
def rect2point9(rect):
point9 = []
rect_x = np.mean(rect[:, 0])
rect_y = np.mean(rect[:, 1])
point9.append([rect_x, rect_y])
for p in range(len(rect)):
point9.append(rect[p])
point9.append((rect[p,:]+rect[(p+1)%len(rect),:])/2)
return np.array(point9)
# 旋转矩形框 x y w h a
rect_a = ((100,100), (50,100), 45)
draw_rect(cv2.boxPoints(rect_a).astype(np.int32))
# 4个点 x y
rect_xy = cv2.boxPoints(rect_a).astype(np.float32)
print(rect_xy)
# 9个点 x y
point9 = rect2point9(rect_xy)
print(point9)
#旋转矩形框 x y w h a
rect_a = cv2.minAreaRect(point9)
print(rect_a)
#draw_rect(cv2.boxPoints(rect_a).astype(np.int32))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/luchaoshi/mmrotate.git
git@gitee.com:luchaoshi/mmrotate.git
luchaoshi
mmrotate
mmrotate
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385