diff --git a/AR-3/Assets/python_test.cs b/AR-3/Assets/python_test.cs index eab69e9..e96408e 100644 --- a/AR-3/Assets/python_test.cs +++ b/AR-3/Assets/python_test.cs @@ -25,6 +25,7 @@ public class python_test : MonoBehaviour int baselineWidth = 1500; int baselineHeight = 1500; Mat loadedImage; + Mat loadedImage_pls; GameObject rue; bool displayWarped = false; double rueX = 0.51; @@ -39,8 +40,12 @@ public class python_test : MonoBehaviour ProcessStartInfo start = new ProcessStartInfo(); Texture2D _TextureFromCamera; + bool displayLoaded = false; RestClient restClient; + Dictionary intToPiece = new Dictionary(); + + int viewMarked = 0; //StreamWriter sw; //StreamReader sr; @@ -50,23 +55,23 @@ public class python_test : MonoBehaviour void Start() { - //loadedImage = Imgcodecs.imread("/Users/alexandermunch-hansen/projects/chess_stuff/advancedskrald/whole_boards/boards_for_empty/board_1554285984.187497_rank_4.png"); - //camImgCopy = loadedImage.clone(); + + + + loadedImage_pls = Imgcodecs.imread("/Users/alexandermunch-hansen/projects/chess_stuff/advancedskrald/whole_boards/boards_for_empty/board_1554285984.187497_rank_4.png"); - start.FileName = "/Users/alexandermunch-hansen/.virtualenvs/cv/bin/python3"; - var cmd = "/Users/alexandermunch-hansen/projects/chess_stuff/advancedskrald/adapter.py"; - var args = ""; - start.Arguments = string.Format("\"{0}\" \"{1}\"", cmd, args); - print(start.Arguments); - start.UseShellExecute = false;// Do not use OS shell - start.CreateNoWindow = true; // We don't need new window - start.RedirectStandardInput = true; - start.RedirectStandardOutput = true;// Any output, generated by application will be redirected back - start.RedirectStandardError = true; // Any error in standard output will be redirected back (for example exceptions) + + intToPiece.Add(0, "RK"); + intToPiece.Add(1, "KNT"); + intToPiece.Add(2, "BSP"); + intToPiece.Add(6, ""); camMatFromTexture = new Mat(1080, 1920, CvType.CV_8UC3); _TextureFromCamera = new Texture2D(1920, 1080); + + + restClient = new RestClient("http://localhost:5000"); @@ -98,7 +103,7 @@ public class python_test : MonoBehaviour request.AddParameter("application/json", json, ParameterType.RequestBody); var response = restClient.Execute(request); - + print(response.Content); return response.Content; } @@ -121,6 +126,12 @@ public class python_test : MonoBehaviour // Update is called once per frame void Update() { + if (displayLoaded) + { + camMatFromTexture = loadedImage_pls.clone(); + } + + Image camImg = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888); Mat textMat = null; @@ -132,8 +143,10 @@ public class python_test : MonoBehaviour //byte[] bytes = _TextureFromCamera.EncodeToPNG(); //string filePath = "SavedScreen1.png"; //File.WriteAllBytes(filePath, bytes); - OpenCVForUnity.UnityUtils.Utils.texture2DToMat(_TextureFromCamera, camMatFromTexture); - + if (!displayLoaded) + { + OpenCVForUnity.UnityUtils.Utils.texture2DToMat(_TextureFromCamera, camMatFromTexture); + } /* @@ -147,34 +160,37 @@ public class python_test : MonoBehaviour if (Input.GetKeyDown(KeyCode.A)) { - print("fuck"); viewMarked = 0; } else if (Input.GetKeyDown(KeyCode.S)) { - print("cock"); viewMarked = 1; + } else if (Input.GetKeyDown(KeyCode.D)) + { + displayLoaded = true; + } else if (Input.GetKeyDown(KeyCode.F)) + { + displayLoaded = false; } if (Input.GetKeyDown("space")) { - //ScreenCapture.CaptureScreenshot("plspls.png"); - - loadedImage = camMatFromTexture.clone(); + //ScreenCapture.CaptureScreenshot("plspls.png"); - // TODO: We should clone camImageMat again, instead of the loadedImage I use now + // TODO: Set this back again - //loadedImage = camImageMat.clone(); - //camImgCopy = camImageMat.clone(); - - print("------------------------------------"); - - //print(loadedImage.size()); - camImageMat = loadedImage.clone(); - - print("------------------------------------"); - - + if (!displayLoaded) + { + loadedImage = camMatFromTexture.clone(); + } + else + { + loadedImage = loadedImage_pls.clone(); + } + //camMatFromTexture = loadedImage.clone(); + + + var pls = runCmd(camMatFromTexture); @@ -196,6 +212,7 @@ public class python_test : MonoBehaviour MatOfPoint2f points = new MatOfPoint2f(); points.alloc(64); + var board = homographyAndState.board; int indexer = 0; for (int y = 1; y < 9; y++) @@ -204,6 +221,7 @@ public class python_test : MonoBehaviour { var cur_pos = board[x - 1][y - 1]; + points.put(indexer, 0, (cur_pos != 6 ? 1 : -200) * y * 165, (cur_pos != 6 ? 1 : -200) * x * 165); indexer += 1; } @@ -214,11 +232,20 @@ public class python_test : MonoBehaviour Core.perspectiveTransform(points, dstPoints, homography.inv()); List transformedPoints = dstPoints.toList(); - - foreach (Point point in transformedPoints) + + indexer = 0; + for (int i = 0; i < 8; i++) { - Imgproc.circle(loadedImage, point, 10, new Scalar(255, 0, 0), -1); + for (int j = 0; j < 8; j++) { + var point = transformedPoints[indexer]; + //Imgproc.circle(loadedImage, point, 5, new Scalar(255, 255, 255), -1); + print($"({point.x}, {point.y}): {intToPiece[board[j][i]]}"); + + Imgproc.putText(loadedImage, $"{intToPiece[board[j][i]]}", new Point(point.x-30, point.y - 10), Imgproc.FONT_HERSHEY_SIMPLEX, 1, new Scalar(255, 255, 255), 3); + indexer += 1; + } } + // MatDisplay.DisplayMat(loadedImage, MatDisplaySettings.FULL_BACKGROUND); diff --git a/AR-3/packages.config b/AR-3/packages.config index 4aebb29..dda5bce 100644 --- a/AR-3/packages.config +++ b/AR-3/packages.config @@ -3,5 +3,6 @@ + \ No newline at end of file