private MetaRect[] ClassifyRectangles(Quadrilateral[] rects) { var metaRects = new MetaRect[rects.Length]; // Classify rectangles by its orientation and size. for (var i = 0; i < rects.Length; i++) { var subrectWidth = rects[i].Width; var subrectHeight = rects[i].Height; // Filter markers by size. if ((subrectWidth > _imageSize.Width * 0.08 && subrectHeight > _imageSize.Height * 0.08) || (subrectWidth < _imageSize.Width * 0.03 || subrectHeight < _imageSize.Height * 0.03)) { continue; } var wtoh = subrectWidth / subrectHeight; var htow = subrectHeight / subrectWidth; var metaRect = new MetaRect { Rect = rects[i], IsHorizontalLongMarker = (wtoh > 2.0f) && (wtoh < 4.5f), IsVerticalLongMarker = (htow > 2.0f) && (htow < 4.5f) }; metaRects[i] = metaRect; } return(metaRects); }
private InternalTagDetectionResult ExtraMarkerCheck(MarkersOrientation detectedMarkersOrientation, MetaRect[] metaRects, int ri1, int ri2) { var confidence = 0.5D; var r1 = metaRects[ri1]; var r2 = metaRects[ri2]; MetaRect rX = new MetaRect(); for (var ri3 = 0; ri3 < metaRects.Length; ri3++) { if (ri3 == ri1 || ri3 == ri2) { continue; } var r3 = metaRects[ri3]; if ((r3.IsHorizontalLongMarker || r3.IsVerticalLongMarker) && r3.Rect.MaxY > _imageSize.Height * 0.75) { if (r3.Rect.MinX < _imageSize.Width * 0.3 && Math.Abs(r3.Rect.MinX - r1.Rect.MinX) < _pixelToleranceWidth) { if ((detectedMarkersOrientation == MarkersOrientation.VV && r3.IsHorizontalLongMarker) || (detectedMarkersOrientation == MarkersOrientation.HH && r3.IsVerticalLongMarker) || (detectedMarkersOrientation == MarkersOrientation.VH && r3.IsVerticalLongMarker) || (detectedMarkersOrientation == MarkersOrientation.HV && r3.IsHorizontalLongMarker)) { confidence += 0.15D; if (!rX.Rect.IsEmpty && rX.Rect.MaxX > _imageSize.Width * 0.7) { if (Math.Abs(r3.Rect.MaxY - rX.Rect.MaxY) < _pixelToleranceHeight) { confidence += 0.2D; } break; } rX = r3; } } if (r3.Rect.MaxX > _imageSize.Width * 0.7 && Math.Abs(r3.Rect.MaxX - r2.Rect.MaxX) < _pixelToleranceWidth) { if ((detectedMarkersOrientation == MarkersOrientation.VV && r3.IsHorizontalLongMarker) || (detectedMarkersOrientation == MarkersOrientation.HH && r3.IsVerticalLongMarker) || (detectedMarkersOrientation == MarkersOrientation.VH && r3.IsHorizontalLongMarker) || (detectedMarkersOrientation == MarkersOrientation.HV && r3.IsVerticalLongMarker)) { confidence += 0.15D; if (!rX.Rect.IsEmpty && rX.Rect.MinX < _imageSize.Width * 0.3) { if (Math.Abs(r3.Rect.MaxY - rX.Rect.MaxY) < _pixelToleranceHeight) { confidence += 0.2D; } break; } rX = r3; } } } } return(new InternalTagDetectionResult { Orientation = detectedMarkersOrientation, Confidence = confidence }); }