private Rectangle FindMarker(AtalaImage img) { int numRowsToSearch = img.Height / 8; // marker is within this area int markerSizeThreshold = img.Width / 25; // marker is at least this big // eventual marker position int top = -1; int left = -1; int right = -1; int bottom = -1; // try to find the top of the marker, by looping through each row for (int y = 0; y < numRowsToSearch; ++y) { if (FindLine(img, y, markerSizeThreshold, ref left, ref right)) { top = y; break; } } if (top == -1) { throw new Exception("Didn't find marker"); } // find marker extents int expectedBottom = top + (right - left) + 10; bottom = expectedBottom; for (int y = top + 1; y < expectedBottom; ++y) { int l=-1, r=-1; if (FindLine(img, y, markerSizeThreshold, ref l, ref r)) { if (l > right+5 || r < left-5) { throw new Exception("Marker not found"); } if (l < left) left = l; if (r > right) right = r; } else if (y - top < markerSizeThreshold) { throw new Exception("Marker not big enough"); } else { bottom = y; break; } } return new Rectangle(left, top, right - left, bottom - top); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)