- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在Google中搜索了arcLength
,好吧,也许我能理解它,但是它对EmguCV或OpenCV中图像的轮廓如何起作用?我试图使用MATLAB制作一些图像。该图像为9 x 9
,我在图像中画了一条线,该线为1像素。我在EmguCV中使用此代码来检测轮廓:
VectorOfVectorOfPoint cons = new VectorOfVectorOfPoint();
CvInvoke.FindContours(img_gray, cons, null, RetrType.List, ChainApproxMethod.ChainApproxNone);
for(int i=0; i<cons.Size;i++)
{
VectorOfPoint points = cons[i];
for(int x =0; x<points.Size;x++)
{
temp[points[x]] = new Gray(255);
}
double c= CvInvoke.ArcLength(cons[i], true);
textBox1.Text = c.ToString();
}
imageBox2.Image = temp;
arcLength
是:
arcLength
为0。arcLength
为2。arcLength
为4。最佳答案
arcLength
完全按照其要求进行:
Calculates a contour perimeter or a curve length.
findContours
(!)的特定问题所迷惑,即应用于1像素宽的行! (实现问题,算法问题,带有“边界跟随”的一般问题,...!?)
3 x 1
黑色图像上的白线
import cv2
import numpy as np
# Generate 5 x 5 black image
img = np.zeros((5, 5), np.uint8)
# Draw 3 x 1 white line
img = cv2.rectangle(img, (1, 1), (3, 1), 255, cv2.FILLED)
# Find contours
cnts = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[0]
# Outputs
print(img, '\n') # Image
print(np.squeeze(cnts[0]), '\n') # Contour
print('Contour points:', cnts[0].shape[0], '\n')
print('arcLength:', cv2.arcLength(cnts[0], True))
[[ 0 0 0 0 0]
[ 0 255 255 255 0]
[ 0 0 0 0 0]
[ 0 0 0 0 0]
[ 0 0 0 0 0]]
[[1 1]
[2 1]
[3 1]
[2 1]]
Contour points: 4
arcLength: 4.0
[2 1]
在轮廓中出现两次,所以我们总共有四个轮廓点,两个相邻轮廓点之间的每个“距离”为1,因此轮廓周长(=弧长)也为4。
3 x 2
黑色图像上的白色矩形
import cv2
import numpy as np
# Generate 5 x 5 black image
img = np.zeros((5, 5), np.uint8)
# Draw 3 x 2 white rectangle
img = cv2.rectangle(img, (1, 1), (3, 2), 255, cv2.FILLED)
# Find contours
cnts = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[0]
# Outputs
print(img, '\n') # Image
print(np.squeeze(cnts[0]), '\n') # Contour
print('Contour points:', cnts[0].shape[0], '\n')
print('arcLength:', cv2.arcLength(cnts[0], True))
[[ 0 0 0 0 0]
[ 0 255 255 255 0]
[ 0 255 255 255 0]
[ 0 0 0 0 0]
[ 0 0 0 0 0]]
[[1 1]
[1 2]
[2 2]
[3 2]
[3 1]
[2 1]]
Contour points: 6
arcLength: 6.0
2
的白色圆圈
import cv2
import numpy as np
# Generate 5 x 5 black image
img = np.zeros((5, 5), np.uint8)
# Draw white circle with radius 2
img = cv2.circle(img, (2, 2), 2, 255, cv2.FILLED)
# Find contours
cnts = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[0]
# Outputs
print(img, '\n') # Image
print(np.squeeze(cnts[0]), '\n') # Contour
print('Contour points:', cnts[0].shape[0], '\n')
print('arcLength:', cv2.arcLength(cnts[0], True))
[[ 0 0 255 0 0]
[ 0 255 255 255 0]
[255 255 255 255 255]
[ 0 255 255 255 0]
[ 0 0 255 0 0]]
[[2 0]
[1 1]
[0 2]
[1 3]
[2 4]
[3 3]
[4 2]
[3 1]]
Contour points: 8
arcLength: 11.313708305358887
[2 0]
到
[1 1]
的“距离”是1.414 ...(2的平方根)。每个相邻的两个轮廓点都具有该距离(请参见图片),因此我们的轮廓周长(=弧长)为8 * 1.414 ... = 11.313 ...
----------------------------------------
System information
----------------------------------------
Platform: Windows-10-10.0.16299-SP0
Python: 3.8.1
NumPy: 1.18.1
OpenCV: 4.2.0
----------------------------------------
关于c# - 轮廓的arcLength结果是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60178004/
我正在尝试在OpencCV 2.3.4 Python API中实现连接组件的噪声消除,如Learning OpenCV中从第287页开始所述 我已经计算出轮廓的长度,在此我得到了一个神秘的断言错误。
我正在尝试测量等高线的长度: 绿线是在轮廓上计算的 HoughLineP。通过计算绿线上的欧氏距离,我得到 153.88。然而,轮廓上的 arcLength() 给出了 364.71,而它应该比 Ho
这些功能是如何工作的?我正在使用 Python3.7 和 OpenCv 4.2.0。提前致谢。 approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cn
我尝试使用 arcLength 计算等高线周长。轮廓从文件中读取到 Mat 中,它只是轮廓的黑白图片。但是,当我将此 Mat 传递给函数时,它会抛出一个错误: Assertion failed (cu
我的代码有问题,找不到合适的解决方案。我正在使用 Python 2.7.10 和 OpenCV 3.0。我读了两张图片,想将其中一张图片(模板)与另一张图片的轮廓相匹配,但出现以下错误: error:
当我尝试运行以下代码时: img = cv2.imread('index4.jpg',0) ret,thresh = cv2.threshold(img,127,255,0) ret,thresh =
我是一名优秀的程序员,十分优秀!