繁体   English   中英

如何在Python中找到旋转边界框的坐标?

[英]How to find coordinate of a rotated bounding box in Python?

我有一个旋转的矩形

在此处输入图片说明

它包含矩形值255和背景值0 我想找到一个边界框坐标(x_min,x_max, y_min,y_max) (例如下面的红色框)。 您能建议我在python中找到它的方法吗? 谢谢

在此处输入图片说明

这是我如何获得旋转的边界框的方法

import numpy as np
import skimage.transform
import Image
img = np.zeros([2088,1773], dtype=np.uint8)
img[386:575, 816:1000] = 255
img =skimage.transform.rotate(img, -20, mode='edge')
img=img*255
img = Image.fromarray(img)
if img.mode != 'RGB':
    img = img.convert('RGB')
img.save("rotated_bb.jpg")

这应该工作:

import numpy as np
import skimage.transform
img = np.zeros([2088,1773], dtype=np.uint8)
img[386:575, 816:1000] = 255
img = skimage.transform.rotate(img, -20, mode='edge')

rect = np.where(img==1)
xmin, xmax = rect[1].min(), rect[1].max()
ymin, ymax = rect[0].min(), rect[0].max()

如果确实需要,只需将其调整为RGB格式即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM