Modular stuff
This commit is contained in:
parent
cc2c0843a0
commit
87845fd1a5
|
@ -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<int, string> intToPiece = new Dictionary<int, string>();
|
||||
|
||||
|
||||
int viewMarked = 0;
|
||||
//StreamWriter sw;
|
||||
//StreamReader sr;
|
||||
|
@ -50,24 +55,24 @@ 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();
|
||||
|
||||
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)
|
||||
|
||||
|
||||
loadedImage_pls = Imgcodecs.imread("/Users/alexandermunch-hansen/projects/chess_stuff/advancedskrald/whole_boards/boards_for_empty/board_1554285984.187497_rank_4.png");
|
||||
|
||||
|
||||
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,12 +160,16 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,19 +177,18 @@ public class python_test : MonoBehaviour
|
|||
{
|
||||
//ScreenCapture.CaptureScreenshot("plspls.png");
|
||||
|
||||
loadedImage = camMatFromTexture.clone();
|
||||
// TODO: Set this back again
|
||||
|
||||
// TODO: We should clone camImageMat again, instead of the loadedImage I use now
|
||||
if (!displayLoaded)
|
||||
{
|
||||
loadedImage = camMatFromTexture.clone();
|
||||
}
|
||||
else
|
||||
{
|
||||
loadedImage = loadedImage_pls.clone();
|
||||
}
|
||||
//camMatFromTexture = loadedImage.clone();
|
||||
|
||||
//loadedImage = camImageMat.clone();
|
||||
//camImgCopy = camImageMat.clone();
|
||||
|
||||
print("------------------------------------");
|
||||
|
||||
//print(loadedImage.size());
|
||||
camImageMat = loadedImage.clone();
|
||||
|
||||
print("------------------------------------");
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -215,11 +233,20 @@ public class python_test : MonoBehaviour
|
|||
|
||||
List<Point> 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);
|
||||
|
||||
//process.Close();
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
<package id="DynamicLanguageRuntime" version="1.2.2" targetFramework="net471" />
|
||||
<package id="IronPython" version="2.7.9" targetFramework="net471" />
|
||||
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net471" />
|
||||
<package id="RestSharp" version="106.6.9" targetFramework="net471" />
|
||||
<package id="Unity.Newtonsoft.Json" version="7.0.0.0" targetFramework="net471" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user