简体   繁体   English

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

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

I have a rotated rectangular as 我有一个旋转的矩形

在此处输入图片说明

It contains the values 255 for rectangular and 0 for background. 它包含矩形值255和背景值0 I want to find a bounding box coordinate (x_min,x_max, y_min,y_max) (such as red box as bellow). 我想找到一个边界框坐标(x_min,x_max, y_min,y_max) (例如下面的红色框)。 Could you suggest to me the way to find it in python? 您能建议我在python中找到它的方法吗? Thanks 谢谢

在此处输入图片说明

This is the way how can I obtained the rotated bounding box 这是我如何获得旋转的边界框的方法

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")

This should work: 这应该工作:

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()

just need to adapt it to RGB format if you really need to... 如果确实需要,只需将其调整为RGB格式即可。

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

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