public VideoConvert(string[] split, IWebSocketConnection socket) { VideoCapture capture = new VideoCapture("./vidoe.mp4"); int width = 64; int height = 64; ComputerCraftStuff CCS = new ComputerCraftStuff(); Dictionary <Color, char> colors = CCS.colors; int i = 0; using (Mat image = new Mat("./test.png")) { while (true) { if (!socket.IsAvailable) { break; } capture.Read(image); if (image.Empty()) { socket.Close(); break; } Console.WriteLine((i + 1) + " / " + capture.FrameCount); var arr = new List <byte>(); var indexer = new Mat <Vec3b>(image.Resize(new OpenCvSharp.Size(width, height), 0, 0, InterpolationFlags.Nearest)).GetIndexer(); for (byte x = 0; x < height; x += 1) { for (byte y = 0; y < width; y += 1) { Vec3b color = indexer[x, y]; // BGR arr.Add(Convert.ToByte(colors[CCS.GetClosestColor(colors.Keys.ToArray(), Color.FromArgb(color.Item2, color.Item1, color.Item0))])); } } byte[] compressed = CCS.compress(arr.ToArray()); Console.WriteLine(arr.Count + " -> " + compressed.Length); socket.Send(compressed); i++; } } }
public void OldScreenshotConvert(string[] split, IWebSocketConnection socket) { int width = int.Parse(split[1]); int height = int.Parse(split[2]); ComputerCraftStuff CCS = new ComputerCraftStuff(); Dictionary <Color, char> colors = CCS.colors; int i = 0; while (i < 4000) { if (!socket.IsAvailable) { break; } i++; Mat image = BitmapConverter.ToMat(makeScreenshot()); var arr = new List <byte>(); var resized = image.Resize(new OpenCvSharp.Size(width, height), 0, 0, InterpolationFlags.Nearest); var indexer = new Mat <Vec3b>(resized).GetIndexer(); for (int x = 0; x < height; x += 1) { for (int y = 0; y < width; y += 1) { Vec3b color = indexer[x, y]; // BGR arr.Add(Convert.ToByte(colors[CCS.GetClosestColor(colors.Keys.ToArray(), Color.FromArgb(color.Item2, color.Item1, color.Item0))])); } } byte[] compressed = CCS.compress(arr.ToArray()); Console.WriteLine(arr.Count + " -> " + compressed.Length); socket.Send(compressed); Cv2.WaitKey(1); } }