如何计算弹簧圈转数? [英] How to count spring coil turns?
问题描述
我MOT能够得到即使在基于像素的计算也算
I am mot able to get count even in the pixel based calculation also.
如果我重视形象如何启动与计数匝数
If I have attached image how to start with the counting the turns.
我试过FindContours()。但不安静得到隔离圈,它不能。 。另外,matchshape()我有相似性因素,但对于整个线圈
I tried the FindContours(); but doesn't quiet get the turns segregated which it can't. Also the matchshape() I have the similarity factor but for whole coil.
所以,我想如下轮到计数:
So I tried as follows for turn count :
public static int GetSpringTurnCount()
{
if (null == m_imageROIed)
return -1;
int imageWidth = m_imageROIed.Width;
int imageHeight = m_imageROIed.Height;
if ((imageWidth <= 0) || (imageHeight <= 0))
return 0;
int turnCount = 0;
Image<Gray, float> imgGrayF = new Image<Gray, float>(imageWidth, imageHeight);
CvInvoke.cvConvert(m_imageROIed, imgGrayF);
imgGrayF = imgGrayF.Laplace(1); // For saving integer overflow.
Image<Gray, byte> imgGray = new Image<Gray, byte>(imageWidth, imageHeight);
Image<Gray, byte> cannyEdges = new Image<Gray, byte>(imageWidth, imageHeight);
CvInvoke.cvConvert(imgGrayF, imgGray);
cannyEdges = imgGray.Copy();
//cannyEdges = cannyEdges.ThresholdBinary(new Gray(1), new Gray(255));// = cannyEdges > 0 ? 1 : 0;
cannyEdges = cannyEdges.Max(0);
cannyEdges /= 255;
Double[] sumRow = new Double[cannyEdges.Cols];
//int sumRowIndex = 0;
int Rows = cannyEdges.Rows;
int Cols = cannyEdges.Cols;
for (int X = 0; X < cannyEdges.Cols; X++)
{
Double sumB = 0;
for (int Y = 0; Y < cannyEdges.Rows; Y ++)
{
//LineSegment2D lines1 = new LineSegment2D(new System.Drawing.Point(X, 0), new System.Drawing.Point(X, Y));
Double pixels = cannyEdges[Y, X].Intensity;
sumB += pixels;
}
sumRow[X] = sumB;
}
Double avg = sumRow.Average();
List<int> turnCountList = new List<int>();
int cnt = 0;
foreach(int i in sumRow)
{
sumRow[cnt] /= avg;
if(sumRow[cnt]>3.0)
turnCountList.Add((int)sumRow[cnt]);
cnt++;
}
turnCount = turnCountList.Count();
cntSmooth = cntSmooth * 0.9f + (turnCount) * 0.1f;
return (int)cntSmooth;
}
任何帮助将是有益的。我接下来想冲浪。
Any help will be helpful. I am next trying surf.
============================= =====================
==================================================
编辑:添加样品。如果妳喜欢这样做。
Adding samples. If u like it do it.
=============================== ===================
==================================================
编辑:尝试另一种算法中:
Tried another algo:
- 投资回报率,然后旋转(最大的稀淡蓝色矩形)
- GetMoments()缩小ROI的高度和position.Y使用的那一刻。
- 将萎缩的投资回报率和._And()它与一个空白图像。 (带有绿色矩形灰色区域)
- 切开图像成半的一半。
- 轮廓和合适的椭圆。
- 得到拟合椭圆的最大数量。
- ROI then Rotate ( biggest thin light blue rectangle )
- GetMoments() shrink ROI height and position.Y using the moment.
- Set the shrinked ROI and ._And() it with a blank image. ( Gray region with green rectangle )
- cut the image into half-half.
- contour and fit ellipse.
- get maximum number of fitted ellipses.
后来将工作更好的交易算法和结果。
Later will work on better algos and results.
推荐答案
假设白色的大集群是春天
Assuming the bigger cluster of white colour is the spring
- EDIT--
--EDIT--
- 应用反阈值的图片,并填写洪水填充算法的角落。
- 找到旋转边界最大的白色集群中使用findContours和minAreaRect
- 的箱式跟踪框长轴做以下
- 沿轴心轨迹轴心线的每个像素垂直通过当前像素
- 这条线将穿越弹簧至少两个百分点。
- 找到从轴与大distane点LI>
- 这将类似于正弦函数点创建集合
- 计数这个集合的峰值或群集,这将得到循环数的两倍。
要去
- Apply inverse threshold to the picture and fill corners with flood fill algorithm.
- Find the rotated bounding box of the biggest white cluster using findContours and minAreaRect
- Trace the box longer axis doing the following
- for each pixel along the axis trace axis line perpendicular going through current pixel
- This line will cross the spring in minimum two points.
- Find the point with the bigger distane from the axis
- This will create collection on points similar to sine function
- Count the peaks or clusters of this collection this will get twice the number of loops.
这一切假设你没有在图片中高噪声。
All this assuming you don't have high noise in the picture.
这篇关于如何计算弹簧圈转数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!