【问题标题】:cv::Rect functionality in Python?Python 中的 cv::Rect 功能?
【发布时间】:2017-03-21 06:07:38
【问题描述】:

OpenCV 的 Python 接口似乎没有为cv::Rect 提供相应的类。它的功能是不是以python中某些函数的形式移植的?

我在 C++ 中尝试过以下代码,在 python 中也尝试过,但出现了一些错误:

border2=5 cv::Rect rectangle(border,border,image.cols-border2,image.rows-border2);

但是当我尝试如下python代码时

rect=cv2.rectangle(border,border,img.shape[1]-border2,img.shape[0]-border2);

错误rect=cv2.rectangle(border,border,img.shape[1]-border2,img.shape[0]-border2);

【问题讨论】:

  • cv2.rectangle,类似于cv::rectangle,是在mat上绘制矩形的函数。
  • 尝试cv2.rectangle(border,border,img.shape[1]-border2,img.shape[0]-border2) 而不将其分配给变量。
  • 我不认为 cv::Rect 或 cv::Rect_ 是在 Python 中实现的,因为最好使用切片。你可以试试img[ border:img.shape[1]-border2, border:img.shape[0]-border2 ]。你怎么看?

标签: python opencv computer-vision


【解决方案1】:

你应该这样做:

cv2.rectangle(img, (border, border), (img.shape[1]-border2,img.shape[0]-border2), color, thickness = 1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多