How to count spring coil turns?

心已入冬 提交于 2019-12-24 00:55:38

问题


In reference to: How to detect and count a spiral's turns

I am not able to get count even in the pixel based calculation also.

If I have attached image how to start with the counting the turns.

I tried the FindContours(); but doesn't quite 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;
    }

I am next trying surf.

==================================================

Edit: Adding samples. If you like it do it.

==================================================

Edit: Tried another algo:

  1. ROI then Rotate ( biggest thin light blue rectangle )
  2. GetMoments() shrink ROI height and position.Y using the moment.
  3. Set the shrinked ROI and ._And() it with a blank image. ( Gray region with green rectangle )
  4. cut the image into half-half.
  5. contour and fit ellipse.
  6. get maximum number of fitted ellipses.

Later will work on better algos and results.


回答1:


Assuming the bigger cluster of white colour is the spring

--EDIT--

  1. Apply inverse threshold to the picture and fill corners with flood fill algorithm.
  2. Find the rotated bounding box of the biggest white cluster using findContours and minAreaRect
  3. Trace the box longer axis doing the following
  4. for each pixel along the axis trace axis line perpendicular going through current pixel
  5. This line will cross the spring in minimum two points.
  6. Find the point with the bigger distane from the axis
  7. This will create collection on points similar to sine function
  8. 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.



来源:https://stackoverflow.com/questions/13820556/how-to-count-spring-coil-turns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!