private void BlackWhiteDone() { VideoCapture.Instance.SaveFrame = bitmap => { VideoCapture.Instance.SaveFrame = null; bitmap.Save(Path.Combine(Helpers.TempDir, "capture_white1.png"), ImageFormat.Png); bitmap.Dispose(); SaveCursorPositionIntern(); if (!Helpers.IsDevComputer) { var errorCode = NvApi.ShowImage(_projectors[0].DisplayId, _black, _projectors[0].Resolution.Width, _projectors[0].Resolution.Height); HandleNvApiError(errorCode); if (ShowImage == null) { errorCode = NvApi.ShowImage(_projectors[1].DisplayId, _projectors[1].Pattern, _projectors[1].Resolution.Width, _projectors[1].Resolution.Height); HandleNvApiError(errorCode); } else { errorCode = NvApi.ShowImage(_projectors[1].DisplayId, _white, _projectors[1].Resolution.Width, _projectors[1].Resolution.Height); HandleNvApiError(errorCode); ShowImage(Path.Combine(Helpers.TempDir, "p1full.png")); } } RestoreCursorPositionIntern(); AwaitProjectorsReady(BlackPatternDone, OnCalibrationCanceled, new[] { CalibrationSteps.Black, CalibrationSteps.Pattern }); }; }
public void Warp() { SaveCursorPositionIntern(); var data = GetWarpData(); if (!Helpers.IsDevComputer) { // TODO Marco: überarbeiten //var ee = NvApi.InitWarp(_projectors[0].DisplayId, data.Vertices0, _projectors[1].DisplayId, data.Vertices1, data.NumVertices); //HandleNvApiError(ee); //ee = NvApi.InitWarp(_projectors[1].DisplayId, data.Vertices1, _projectors[1].DisplayId, data.Vertices1, data.NumVertices); //HandleNvApiError(ee); //var errorCode = NvApi.Warp(_projectors[0].DisplayId, data.Vertices0, data.NumVertices); //HandleNvApiError(errorCode); //errorCode = NvApi.Warp(_projectors[1].DisplayId, data.Vertices1, data.NumVertices); //HandleNvApiError(errorCode); var displayIds = new[] { _projectors[0].DisplayId, _projectors[1].DisplayId }; var errorCode = NvApi.WarpMultiple(displayIds, displayIds.Length, data.Vertices0.Concat(data.Vertices1).ToArray(), data.NumVertices); HandleNvApiError(errorCode); //NvApi.InitWarp(data.Vertices0, data.Vertices1, data.NumVertices); } RestoreCursorPosition?.Invoke(); }
private void WhiteWhiteDone() { int count = 0; VideoCapture.Instance.SaveFrame = bitmap => { count++; if (count > 2) { VideoCapture.Instance.SaveFrame = null; bitmap.Save(Path.Combine(Helpers.TempDir, "capture_white.png"), ImageFormat.Png); bitmap.Dispose(); SaveCursorPositionIntern(); if (!Helpers.IsDevComputer) { var errorCode = NvApi.ShowImage(_projectors[0].DisplayId, _white, _projectors[0].Resolution.Width, _projectors[0].Resolution.Height); HandleNvApiError(errorCode); errorCode = NvApi.ShowImage(_projectors[1].DisplayId, _black, _projectors[1].Resolution.Width, _projectors[1].Resolution.Height); HandleNvApiError(errorCode); } RestoreCursorPositionIntern(); AwaitProjectorsReady(WhiteBlackDone, OnCalibrationCanceled, new[] { CalibrationSteps.White, CalibrationSteps.Black }); } }; }
public static void Initialize() { Helpers.InitTempDir(); if (!Helpers.IsDevComputer) { var errorCode = NvApi.Initialize(); HandleNvApiError(errorCode); } }
private static void HandleNvApiError(int errorCode) { if (errorCode == NvApi.NVAPI_OK) { return; } NvApi.GetError(errorCode, out var error); throw new Exception(error.Message); }
public void UnBlend() { SaveCursorPositionIntern(); if (!Helpers.IsDevComputer) { var displayIds = new[] { _projectors[0].DisplayId, _projectors[1].DisplayId }; var errorCode = NvApi.UnBlend(displayIds, displayIds.Length, _projectors[0].Resolution.Width, _projectors[0].Resolution.Height); HandleNvApiError(errorCode); } RestoreCursorPositionIntern(); }
public void Calibrate(bool initPattern) { if (initPattern) { SetPattern(_patternSize, _patternCount, _controlPointsInsideOverlap, true); } foreach (var p in _projectors) { p.GeneratePattern(); } _black = Generate(0f); _white = Generate(1f); _black.SaveAsImage(_projectorResolution, Path.Combine(Helpers.TempDir, "black.png")); _white.SaveAsImage(_projectorResolution, Path.Combine(Helpers.TempDir, "white.png")); for (var i = 0; i < _projectors.Length; i++) { _projectors[i].SavePattern(Path.Combine(Helpers.TempDir, "p" + i + ".png")); } if (ShowImage != null) { SavePatternFull(); SaveWhiteFull(); } VideoCapture.Instance.Stop(); // TODO Marco: Kamera oder File if (Helpers.CameraCalibration) { VideoCapture.Instance.Start(true); } else { VideoCapture.Instance.StartFromFile(true); } SaveCursorPositionIntern(); ShowImage?.Invoke(Path.Combine(Helpers.TempDir, "whitefull.png")); if (!Helpers.IsDevComputer) { foreach (var p in _projectors) { var errorCode = NvApi.ShowImage(p.DisplayId, _white, p.Resolution.Width, p.Resolution.Height); HandleNvApiError(errorCode); } } RestoreCursorPositionIntern(); AwaitProjectorsReady(WhiteWhiteDone, OnCalibrationCanceled, new [] { CalibrationSteps.White, CalibrationSteps.White }); }
public void Blend() { SaveCursorPositionIntern(); var data = GetBlendData(); GenerateBlendImages(data); if (!Helpers.IsDevComputer) { var errorCode = NvApi.Blend(_projectors[0].DisplayId, data.Blend0, data.Offset0, data.Width, _projectors[0].Resolution.Height); HandleNvApiError(errorCode); errorCode = NvApi.Blend(_projectors[1].DisplayId, data.Blend1, data.Offset1, data.Width, _projectors[1].Resolution.Height); HandleNvApiError(errorCode); //NvApi.Blend(data.blend0, data.blend1, data.offset0, data.offset1, data.width); } RestoreCursorPositionIntern(); }
private void BlackPatternDone() { VideoCapture.Instance.SaveFrame = bitmap => { VideoCapture.Instance.SaveFrame = null; bitmap.Save(Path.Combine(Helpers.TempDir, "capture_pattern1.png"), ImageFormat.Png); bitmap.Dispose(); SaveCursorPositionIntern(); if (!Helpers.IsDevComputer) { var displayIds = new[] { _projectors[0].DisplayId, _projectors[1].DisplayId }; var errorCode = NvApi.UnBlend(displayIds, displayIds.Length, _projectors[0].Resolution.Width, _projectors[0].Resolution.Height); HandleNvApiError(errorCode); } RestoreCursorPositionIntern(); Detect(); }; }
public void WarpBlend(bool generateBlendImages) { SaveCursorPositionIntern(); var warpData = GetWarpData(); var blendData = GetBlendData(); if (generateBlendImages) { GenerateBlendImages(blendData); } if (!Helpers.IsDevComputer) { //var errorCode = NvApi.Blend(_projectors[0].DisplayId, blendData.blend0, blendData.offset0, blendData.width, _projectors[0].Resolution.Height); //HandleNvApiError(errorCode); //errorCode = NvApi.Blend(_projectors[1].DisplayId, blendData.blend1, blendData.offset1, blendData.width, _projectors[1].Resolution.Height); //HandleNvApiError(errorCode); //errorCode = NvApi.Warp(_projectors[0].DisplayId, warpData.Vertices0, warpData.NumVertices); //HandleNvApiError(errorCode); //errorCode = NvApi.Warp(_projectors[1].DisplayId, warpData.Vertices1, warpData.NumVertices); //HandleNvApiError(errorCode); //NvApi.WarpBlend(warpData.Vertices0, warpData.NumVertices, blendData.blend, blendData.blend1, blendData.offset0, blendData.offset1, blendData.width); var displayIds = new[] { _projectors[0].DisplayId, _projectors[1].DisplayId }; var status = NvApi.UnWarp(displayIds, displayIds.Length); HandleNvApiError(status); status = NvApi.UnBlend(displayIds, displayIds.Length, blendData.Width, _projectors[0].Resolution.Height); HandleNvApiError(status); status = NvApi.WarpMultiple(displayIds, displayIds.Length, warpData.Vertices0.Concat(warpData.Vertices1).ToArray(), warpData.NumVertices); HandleNvApiError(status); status = NvApi.Blend(_projectors[0].DisplayId, blendData.Blend0, blendData.Offset0, blendData.Width, _projectors[0].Resolution.Height); HandleNvApiError(status); status = NvApi.Blend(_projectors[1].DisplayId, blendData.Blend1, blendData.Offset1, blendData.Width, _projectors[1].Resolution.Height); HandleNvApiError(status); } RestoreCursorPositionIntern(); }