如何使用opencv通过xmax xmin ymax ymin编写矩形(边界框)
how to write rectangle (bounding box) by xmax xmin ymax ymin using opencv
我发现我无法使用 opencv 使用 4 个点 (x, y, w, h) 轻松编写边界框。其中 x, y 是左上角并且 w=width, h=height.
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),15)
但是如何使用只有 xmax xmin ymax ymin 点的 opencv 编写边界框?我需要检查我的代码和 x, y, w, h 使用的边界框是否完全等于我在 xmax xmin 下的边界框ymax ymin。
我使用这些代码 x, y, w, h 转换为 xmax xmin ymax ymin
bbox_topleft_corner_x = int(prod_data[0])
bbox_topleft_corner_y = int(prod_data[1])
bbox_w = int(prod_data[2])
bbox_h = int(prod_data[3])
ymax = bbox_topleft_corner_y
ymin = bbox_topleft_corner_y - bbox_h
xmax = bbox_topleft_corner_x + bbox_w
xmin = ymin + bbox_w
但我不确定我是否按照自己的意愿做了所有事情。我想将 x, y, w, h 转换为 VOOC2007 注释 xml 格式及其边界框格式
感谢任何建议
我猜你的问题是参考系统。
在图像中,点 (0,0) 是左上角的像素。从您的 ymin 计算来看,您似乎正在考虑 y "the upper is the higher" 但原点在 top-left 点恰恰相反。
给定 x、y、宽度和高度,得到 x_max 和 y_max 应该很简单。
x_max = x + width
y_max = y + height
重要的是要记住图像的坐标系以左上角的 (0, 0)
和右下角的 (image_width, image_height)
开头。因此:
top_left = (x, y)
bottom_right = (x+w, y+h)
最后要记住的是,在某些情况下请求的参数是一个点 (x, y)
,例如 cv2.rectangle 函数中的情况。但是,像素作为底层 ndarray 结构进行访问 image[row, column]
查看 this question 了解有关 opencv 坐标系的更多信息。
我发现我无法使用 opencv 使用 4 个点 (x, y, w, h) 轻松编写边界框。其中 x, y 是左上角并且 w=width, h=height.
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),15)
但是如何使用只有 xmax xmin ymax ymin 点的 opencv 编写边界框?我需要检查我的代码和 x, y, w, h 使用的边界框是否完全等于我在 xmax xmin 下的边界框ymax ymin。
我使用这些代码 x, y, w, h 转换为 xmax xmin ymax ymin
bbox_topleft_corner_x = int(prod_data[0])
bbox_topleft_corner_y = int(prod_data[1])
bbox_w = int(prod_data[2])
bbox_h = int(prod_data[3])
ymax = bbox_topleft_corner_y
ymin = bbox_topleft_corner_y - bbox_h
xmax = bbox_topleft_corner_x + bbox_w
xmin = ymin + bbox_w
但我不确定我是否按照自己的意愿做了所有事情。我想将 x, y, w, h 转换为 VOOC2007 注释 xml 格式及其边界框格式
感谢任何建议
我猜你的问题是参考系统。
在图像中,点 (0,0) 是左上角的像素。从您的 ymin 计算来看,您似乎正在考虑 y "the upper is the higher" 但原点在 top-left 点恰恰相反。
给定 x、y、宽度和高度,得到 x_max 和 y_max 应该很简单。
x_max = x + width
y_max = y + height
重要的是要记住图像的坐标系以左上角的 (0, 0)
和右下角的 (image_width, image_height)
开头。因此:
top_left = (x, y)
bottom_right = (x+w, y+h)
最后要记住的是,在某些情况下请求的参数是一个点 (x, y)
,例如 cv2.rectangle 函数中的情况。但是,像素作为底层 ndarray 结构进行访问 image[row, column]
查看 this question 了解有关 opencv 坐标系的更多信息。