Commit 9e086d51 SK

其他Blob的label导致的死循环

1 个父辈 cc99ba63
...@@ -715,6 +715,7 @@ namespace Acc.Img ...@@ -715,6 +715,7 @@ namespace Acc.Img
while (true) while (true)
{ {
bool hasFind = false; bool hasFind = false;
bool hasPixToHandle = false;
for (int x = blob.MinX; x< blob.MaxX; x++) for (int x = blob.MinX; x< blob.MaxX; x++)
{ {
for (int y = blob.MinY; y < blob.MaxY; y++) for (int y = blob.MinY; y < blob.MaxY; y++)
...@@ -729,6 +730,7 @@ namespace Acc.Img ...@@ -729,6 +730,7 @@ namespace Acc.Img
//matDistanceArr[x, y] = 0; //matDistanceArr[x, y] = 0;
continue; continue;
} }
hasPixToHandle = true;
if (!item.isEnd) if (!item.isEnd)
{ {
double distanceToCircle = item.minDistanceToCircles(x, y, reelCenter); double distanceToCircle = item.minDistanceToCircles(x, y, reelCenter);
...@@ -766,7 +768,7 @@ namespace Acc.Img ...@@ -766,7 +768,7 @@ namespace Acc.Img
{ {
item.calOneItem(oneBlobRadius); item.calOneItem(oneBlobRadius);
} }
if (item.isEnd) if (item.isEnd || hasPixToHandle)
{ {
break; break;
} }
...@@ -869,7 +871,7 @@ namespace Acc.Img ...@@ -869,7 +871,7 @@ namespace Acc.Img
} }
} }
//放大宽度,防止误判断 //放大宽度,防止误判断
maxWidth = maxWidth * 1.02; maxWidth = maxWidth * 1.1;
Console.WriteLine("Start count"); Console.WriteLine("Start count");
int totalCount = 0; int totalCount = 0;
foreach (CvBlob blob in blobs.Values) foreach (CvBlob blob in blobs.Values)
...@@ -903,10 +905,10 @@ namespace Acc.Img ...@@ -903,10 +905,10 @@ namespace Acc.Img
Circle c = groupCircle[0]; Circle c = groupCircle[0];
srcMat.Circle(c.x, c.y, (int)c.radius/2, Scalar.Yellow); srcMat.Circle(c.x, c.y, (int)c.radius/2, Scalar.Yellow);
totalCount = totalCount + 1; totalCount = totalCount + 1;
foreach (Circle cg in groupCircle) //foreach (Circle cg in groupCircle)
{ //{
srcMat.Circle(cg.x, cg.y, (int)c.radius, color); // srcMat.Circle(cg.x, cg.y, (int)c.radius, color);
} //}
} }
} }
} }
...@@ -1057,13 +1059,17 @@ namespace Acc.Img ...@@ -1057,13 +1059,17 @@ namespace Acc.Img
image = BitmapConverter.ToBitmap(dst); image = BitmapConverter.ToBitmap(dst);
CvBlobs blobs = new CvBlobs(); CvBlobs blobs = new CvBlobs();
blobs.Label(dst); blobs.Label(dst);
int blobArea = -1;
foreach(CvBlob blob in blobs.Values) { foreach(CvBlob blob in blobs.Values) {
if (blob.Rect.Contains(new OpenCvSharp.Point(markX, markY))) if (blob.Rect.Contains(new OpenCvSharp.Point(markX, markY)))
{ {
return blob.Area; if (blob.Area < blobArea || blobArea == -1)
{
blobArea = blob.Area;
}
} }
} }
return -1; return blobArea;
} }
} }
} }
...@@ -31,7 +31,7 @@ namespace AccImage ...@@ -31,7 +31,7 @@ namespace AccImage
{ {
//与平均半径差值在10%以内,认为OK //与平均半径差值在10%以内,认为OK
double diff = avgRadius - currentMaxRadius; double diff = avgRadius - currentMaxRadius;
if (diff/avgRadius <= 0.3) if (diff/avgRadius <= 0.4)
{ {
isValid = true; isValid = true;
} }
...@@ -50,13 +50,17 @@ namespace AccImage ...@@ -50,13 +50,17 @@ namespace AccImage
currentMaxRadius = 0; currentMaxRadius = 0;
centerX = 0; centerX = 0;
centerY = 0; centerY = 0;
//平均半径 ////平均半径
double total = 0; //double total = 0;
foreach (Circle c in circles) //foreach (Circle c in circles)
//{
// total = total + c.radius;
//}
//avgRadius = total / circles.Count;
if(circle.radius > avgRadius)
{ {
total = total + c.radius; avgRadius = circle.radius;
} }
avgRadius = total / circles.Count;
} }
else else
{ {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!