簡體   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