OpenCV中minEnclosingCircle的意外结果 [英] Unexpected results of minEnclosingCircle in OpenCV
问题描述
我最近使用了OpenCV(2.4.2)的minEnclosingCircle函数,因为我需要测量一点的直径.
I have recently used the function minEnclosingCircle of OpenCV (2.4.2) because I needed to measure the diameters of a blob of points.
过了一会儿,我意识到结果不正确,所以我决定编写一个小的例程来计算一组非常小的点的直径.
After a while I realized that the results were not correct, so I decided to write a small routine that calculates the diameters of a really small set of points.
我针对以下功能测试了该功能:
I tested the function against:
- 1个单点点
- 连续2-4点
- 仅由4个角点组成的不同大小的正方形
在下表中,您可以看到我的测试结果:
In the table below you can see the results of my tests:
Note Diameter Center Points
1x1 2.000 (1.0, 1.0) [[1, 1]]
2x1 2.000 (1.0, 1.5) [[1, 1], [1, 2]]
3x1 2.060 (1.0, 2.0) [[1, 1], [1, 2], [1, 3]]
4x1 3.090 (1.0, 2.5) [[1, 1], [1, 2], [1, 3], [1, 4]]
2x2 2.000 (1.5, 1.5) [[1, 1], [1, 2], [2, 1], [2, 2]]
3x3 2.913 (2.0, 2.0) [[1, 1], [1, 3], [3, 1], [3, 3]]
4x4 4.370 (2.5, 2.5) [[1, 1], [1, 4], [4, 1], [4, 4]]
6x6 7.283 (3.5, 3.5) [[1, 1], [1, 6], [6, 1], [6, 6]]
8x8 10.196 (4.5, 4.5) [[1, 1], [1, 8], [8, 1], [8, 8]]
9x9 11.653 (5.0, 5.0) [[1, 1], [1, 9], [9, 1], [9, 9]]
16x16 21.850 (8.5, 8.5) [[1, 1], [1, 16], [16, 1], [16, 16]]
10x10 13.110 (5.5, 5.5) [[1, 1], [1, 10], [10, 1], [10, 10]]
100x100 144.207 (50.5, 50.5) [[1, 1], [1, 100], [100, 1], [100, 100]]
1000x1000 1455.183 (500.5, 500.5) [[1, 1], [1, 1000], [1000, 1], [1000, 1000]]
我已经看到该函数不会返回小于1的半径,因此我得到的最小直径为2.0.
I have already seen that the function does not return a radius smaller than 1, so the minimum diameter I get is 2.0.
除此之外,该函数总是返回比我期望的半径大的半径. 例如,10x10正方形的半径大约为12.726,而不是13.110. 误差随着正方形的大小而增加:对于1000x1000的正方形,我期望的是1412.5而不是1455.
Apart from that, the function is always returning a radius bigger than I would expect. For instance the 10x10 square would have a radius of about 12.726 instead of 13.110. The error increases with the size of the square: for a square of 1000x1000 I would expect 1412.5 instead of 1455.
实际上,我意识到相对误差始终约为3%.
Actually, I realized that the relative error is always about 3%.
我该如何解释这种奇怪的行为?
How can I explain this strange behavior?
推荐答案
I tried to solve the same problem using another library called Miniball.
用迷你球获得的结果是正确的.在这一点上,我猜想minEnclosingCircle
中使用的算法包含一些错误.
The results obtained with Miniball are correct. At this point I guess that the algorithm used in minEnclosingCircle
contains some error.
这篇关于OpenCV中minEnclosingCircle的意外结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!