python - OpenCV: Merging fitted shapes
问题描述
If I'm using OpenCV (Python) and fit two shapes, like so:
a = cv2.fitEllipse(contours)
b = cv2.minAreaRect(contours)
Both a
and b
are represented as Box2D
objects, which look something like:
center: (x, y)
size: (width, height)
rotation: angle
a
and b
are often going to be fairly similar, but not exact due to different fit methods. How can I find the shape (ellipse) that is the "average" of a
and b
? That is, the ellipse that is the best fit between a
and b
?
解决方案
“平均”的定义可能不明确,并为您提供不同的解决方案。如果这对您来说并不重要,因为您只想以任何方式平均形状,下面是如何平均两个矩形的简单解决方案:
表示两个矩形(a1, a2, a3, a4)
和(b1, b2, b3, b4)
。假设我们要找到矩形(x1, x2, x3, x4)
最小化
一个矩形被参数化为
其中R
是 2D 旋转矩阵,是q_i
矩形大小未知的矩阵之一。是未知的矩形中心。w
h
p
整个公式形成一个二次规划问题,具有未知数w, h, R, p
和二次约束R
的是一个旋转矩阵。
推荐阅读
- c++ - 如何在不知道他拥有哪些构造函数的情况下初始化属性?
- eclipse - Eclipse subversion checkout SSL 和 SSH 的区别
- python - 遍历目录中的文件会创建一个额外的 nan 数组
- android - 打开 CV 项目未构建
- javascript - X-Frame-Options:DENY 不适用于 Spring Boot REST API
- c# - 如何使用 C# 在页面对象模型中实现“findelements”
- python - 有没有更快的方法来删除熊猫中数据框的所有空白/标签?
- c - 如何在链表的末尾添加一个节点?
- python - 使用 FiPy 对一维化学工程扩散问题进行建模
- javascript - bootstrap 4 - 导航栏品牌标志在向下滚动时不会改变