참조 : How to detect and count a spiral's turns스프링 코일 수를 계산하는 방법은 무엇입니까?
픽셀 기반 계산에서도 카운트 할 수 있습니다. 내가 어떻게이 교대로 카운트로 시작하는 이미지를 첨부 한 경우
.
나는)합니다 (FindContours을 시도; 그러나 조용히하지 못하면서 분리 된 턴을 얻지 못합니다. 또한 matchshape()에는 유사성 요소가 있지만 전체 코일에 대해 있습니다.그래서 회전 수에 대해 다음과 같이 시도 :
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;
}
어떤 도움이 도움이 될 것입니다. 다음에 서핑을하려고합니다.
============================================== ====
편집 : 추가 샘플. 당신이 그것을 좋아한다면.
================================== ================
편집 : 시도 또 다른 너 한테 :
- ROI 다음 회전 (가장 얇은 밝은 파란색 사각형)
- GetMoments()는 순간을 사용하여 ROI 높이와 위치 .Y를 축소합니다. 빈 이미지로 수축 ROI 및 ._And()을 설정합니다. (녹색 영역이있는 회색 영역)
- 이미지를 절반으로 자릅니다.
- 윤곽 및 맞춤 타원.
- 맞는 타원 수를 얻으십시오.
나중에 더 나은 알 고리와 결과를 얻을 수 있습니다. 화이트 색상의 더 큰 클러스터를 가정
일반적으로 질문을 이해하기 어렵습니다. 영어에 능숙한 사람이 명확하고 쉽게 읽을 수 있도록 질문을 교정하도록하십시오. –