using Aurora.Api.DataType; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace VisionCommon { public class ScreenShotUtil { public static (FovInfo, eFovUiPos) GetLeftTopFovInfo(List fovInfos, eDisplayType displayType) { var fovRecipe = VisionRecipeManager.GetFovRecipe(fovInfos[0]); var leftTopUiPos = VisionRecipeManager.GetFovUiPos(fovRecipe, displayType); var leftTopFovInfo = fovInfos[0]; for (int i = 1; i < fovInfos.Count; i++) { fovRecipe = VisionRecipeManager.GetFovRecipe(fovInfos[i]); var fovPos = VisionRecipeManager.GetFovUiPos(fovRecipe, displayType); if (fovPos < leftTopUiPos) { leftTopUiPos = fovPos; leftTopFovInfo = fovInfos[i]; } } return (leftTopFovInfo, leftTopUiPos); } public static bool HasRightFov(FovInfo ltFovInfo, eFovUiPos ltFovUiPos, List fovInfos, eDisplayType displayType) { var (ltFovUiPosRow, ltFovUiPosCol) = FovRecipe.GetFovUiPosRowCol(ltFovUiPos); foreach (var curfovInfo in fovInfos) { if (curfovInfo == ltFovInfo) { continue; } var fovRecipe = VisionRecipeManager.GetFovRecipe(curfovInfo); var fovUiPos = VisionRecipeManager.GetFovUiPos(fovRecipe, displayType); var (curFovUiPosRow, curFovUiPosCol) = FovRecipe.GetFovUiPosRowCol(fovUiPos); // RightTop if ((ltFovUiPosRow == curFovUiPosRow) && (ltFovUiPosCol + 1 == curFovUiPosCol)) { return true; } // RightBottom else if ((ltFovUiPosRow + 1 == curFovUiPosRow) && (ltFovUiPosCol + 1 == curFovUiPosCol)) { return true; } } return false; } public static bool HasBottomFov(FovInfo ltFovInfo, eFovUiPos ltFovUiPos, List fovInfos, eDisplayType displayType) { var (ltFovUiPosRow, ltFovUiPosCol) = FovRecipe.GetFovUiPosRowCol(ltFovUiPos); foreach (var curfovInfo in fovInfos) { if (curfovInfo == ltFovInfo) { continue; } var fovRecipe = VisionRecipeManager.GetFovRecipe(curfovInfo); var fovUiPos = VisionRecipeManager.GetFovUiPos(fovRecipe, displayType); var (curFovUiPosRow, curFovUiPosCol) = FovRecipe.GetFovUiPosRowCol(fovUiPos); // LeftBottom if ((ltFovUiPosRow + 1 == curFovUiPosRow) && (ltFovUiPosCol == curFovUiPosCol)) { return true; } // RightBottom else if ((ltFovUiPosRow + 1 == curFovUiPosRow) && (ltFovUiPosCol + 1 == curFovUiPosCol)) { return true; } } return false; } public static void MergeImages(Bitmap src, Bitmap dst, int destOffsetX, int destOffsetY) { using (Graphics g = Graphics.FromImage(dst)) { g.DrawImage(src, destOffsetX, destOffsetY); } } public static ImageSize GetScreenShotImageSize(Dictionary overlayImages, eDisplayType displayType) { if (0 < overlayImages.Count && 0 < overlayImages.Count) { var (ltFovInfo, ltFovUiPos) = GetLeftTopFovInfo(overlayImages.Keys.ToList(), displayType); if (ltFovInfo == null) { return null; } var imageSize = new ImageSize(); imageSize.Width = overlayImages[ltFovInfo].Width; imageSize.Height = overlayImages[ltFovInfo].Height; imageSize.Channel = 3; if (HasRightFov(ltFovInfo, ltFovUiPos, overlayImages.Keys.ToList(), displayType)) { imageSize.Width *= 2; } if (HasBottomFov(ltFovInfo, ltFovUiPos, overlayImages.Keys.ToList(), displayType)) { imageSize.Height *= 2; } return imageSize; } return null; } } }