首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cv2.边界rect rect格式文档

Cv2.边界rect rect格式文档
EN

Stack Overflow用户
提问于 2021-07-19 16:34:22
回答 1查看 682关注 0票数 1

为什么这段代码会产生(1, 1, 1, 1)结果,正如我所理解的那样,cv2.boundingRectx,y,w,h格式返回rect,但是为什么在这种情况下w,h不是零?

代码语言:javascript
复制
import cv2
import numpy as np

cv2.__version__
'4.4.0'

np.__version__
'1.19.2'

a = np.ones((8,2))
x, y, w, h = cv2.boundingRect(a.astype(np.float32))

绑定文档中没有多少信息:

代码语言:javascript
复制
def boundingRect(array): # real signature unknown; restored from __doc__
    """
    boundingRect(array) -> retval
    .   @brief Calculates the up-right bounding rectangle of a point set or non-zero pixels of gray-scale image.
    .   
    .   The function calculates and returns the minimal up-right bounding rectangle for the specified point set or
    .   non-zero pixels of gray-scale image.
    .   
    .   @param array Input gray-scale image or 2D point set, stored in std::vector or Mat.
    """
    pass

更新:

似乎在C++里,它像return Rect(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1);一样返回

EN

回答 1

Stack Overflow用户

发布于 2021-07-19 16:59:18

不是以正确的格式。一种方法是计算Python/OpenCV中的点数。

代码语言:javascript
复制
import cv2
import numpy as np

a = np.ones((8,2))
points = np.column_stack(np.where(a.transpose() > 0))

x, y, w, h = cv2.boundingRect(points)
print(x,y,w,h)

返回:

代码语言:javascript
复制
0 0 2 8
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68444062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档