从分辨率中获取方形 ROI 的点数

Get points of a square ROI from a resolution

我需要点数来创建一个中心平方的 ROI 如何计算?我正在使用 opencv-python.

示例: 分辨率:800x448
ROI点数:(210,34),(590,414)

居中的 ROI 必须是这样的正方形:

https://i.stack.imgur.com/Mj80K.png

我需要 1920x1080 和 1280x720 的点数

您可以计算中心裁剪(1080x1080),如下所示 Python/OpenCV。

# get the center of your current ROI 
# (half way between top-left and bottom-right points)
cx = x1 + (x2 - 1 - x1)/2
cy = y1 + (y2 - 1 - y1)/2

# get the smaller of the two current ROI dimensions
w = h = min((x2-1-x1),(y2-1-y1))

# get top left part of ROI of square region
xt = int(cx - w/2)
yt = int(cy - h/2)

# get bottom right part of ROI of square
xb = xt + w
yb = yt + h

square ROI = image[yt:yb, xt:xb]