static void Main(string[] args) { Console.WriteLine("Starting"); GameDatabase.DatabaseFolder = "C:\\SlitherShark\\database\\processed"; GameDatabase.LoadGames(); var frameProcessor = new FrameProcessor(new OutcomeProcessor(new OutcomeScoreProcessor()), new CollisionMapProcessor(new CollisionMapResolutionProcessor(new CollisionSliceProcessor(new FoodSliceProcessor(new CollisionService()), new BadCollisionSliceProcessor(new CollisionService()), new SelfSliceProcessor(new CollisionService()))), new SlitherFrameNormalizer())); var gameProcessor = new GameProcessor(frameProcessor); var sourceFolder = "C:\\SlitherShark\\database\\source"; foreach (var fileName in Directory.GetFiles(sourceFolder)) { Console.WriteLine(fileName); var jsonString = File.ReadAllText(fileName); var sourceGame = JsonConvert.DeserializeObject <Game>(jsonString, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, NullValueHandling = NullValueHandling.Ignore, }); var processedGame = gameProcessor.ProcessGame(sourceGame); GameDatabase.AddGame(processedGame); } Console.WriteLine("Done"); }
private void Window_Loaded(object sender, RoutedEventArgs e) { kinectManager = KinectManager.GetInstance; if (kinectManager.Sensor != null && kinectManager.Sensor.IsOpen == false) { kinectManager.Open(); wsClient = new WebSocketClient(); wsClient.InitializeConnection(); bodyTracker = new CVision.Tracking.BodyTracker(); frameProc = new FrameProcessor(kinectManager.Sensor); colorFrameReader = kinectManager.Sensor.ColorFrameSource.OpenReader(); colorFrameReader.FrameArrived += ColorFrameReader_FrameArrived; infraredFrameReader = kinectManager.Sensor.InfraredFrameSource.OpenReader(); infraredFrameReader.FrameArrived += InfraredFrameReader_FrameArrived; depthFrameReader = kinectManager.Sensor.DepthFrameSource.OpenReader(); depthFrameReader.FrameArrived += DepthFrameReader_FrameArrived; bodyFrameReader = kinectManager.Sensor.BodyFrameSource.OpenReader(); bodyFrameReader.FrameArrived += BodyFrameReader_FramedArrived; } }
public FrameProvider(RawFramesStore framesStore, IObserver <TValue> observer, FrameProcessor <TValue> processor) { this._cancel = new CancellationTokenSource(); this._framesStore = framesStore; this._observer = observer; this._processor = processor; // The frames generator will be run on another thread Task.Factory.StartNew(new Action(Generate)); }
public void SetVar(FrameProcessor FPU) { this.center=FPU.center.Clone() as Point[]; this.have_face=FPU.have_face; this.have_left=FPU.have_left; this.have_left_punch=FPU.have_left_punch; this.have_right=FPU.have_right; this.have_right_punch=FPU.have_right_punch; }
public Form1() { InitializeComponent(); //_haar = new HaarCascade("..\\..\\haarcascade_frontalface_alt2.xml"); FPU = new FrameProcessor(); sw = new Stopwatch(); histogramBox1.Show(); }
public WebcamDevice() { this.InitializeComponent(); //// Subcribe to dispatcher shutdown event and dispose all used resources gracefully. this.Dispatcher.ShutdownStarted += this.DispatcherShutdownStarted; this.frameProcessor = new FrameProcessor(); }
private void CompositionTarget_Rendering(object sender, EventArgs e) { TimeSpan currentRenderingTime = (e as RenderingEventArgs).RenderingTime; if (currentRenderingTime.Ticks == LastRenderingTime.Ticks) { return; } FrameProcessor.UpdateFrame((currentRenderingTime - LastRenderingTime).TotalSeconds); LastRenderingTime = currentRenderingTime; }
public static void GenerateBackground(FrameProcessor fp, Page page, ControlAttribute attribute, DescriptionAttribute description) { Image image = new Image(fp); image.Image = fp.Game.Content.Load <DiscTexture>(StartMenuInfo.BackgroundTexture); image.Width = page.Width; image.X = 0; image.Y = 0; image.Height = page.Height; image.ImageMode = FrameImageMode.Stretched; page.Add(image); }
private void GetYesCmd(bool isYkey) // auto capture { m_OkCount++; if (m_OkCount == 1) { Log.LogWrite("step 1: blink function test!"); } else if (m_OkCount == 2) { Log.LogWrite("step 2: capture function test!"); } if (isYkey) { Log.LogWrite("get Yes[Y] CMD to auto capture!"); } if (_frameProcessor == null) { Log.LogWrite("get CMD to new _frameProcessor"); _frameProcessor = new FrameProcessor(Frame1, Frame2); } dispatcher = Dispatcher.CurrentDispatcher; timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0) }; timer.Tick += timer_Tick; timer.Start(); string ReferenceImagePath = "CapturePic.bmp"; System.Drawing.Image Image = System.Drawing.Image.FromFile(ReferenceImagePath); GuidImage.Image = Image; GuidImage.Height = Image.Height; GuidImage.Width = Image.Width; this.RetryBtn.Text = "Retry"; this.RetryBtn.Visible = true; this.PassBtn.Text = "Ok"; this.PassBtn.Visible = true; this.FailBtn.Text = "NG"; this.FailBtn.Visible = true; RegisterHotKey(this.Handle, 79, 0, (UInt32)Keys.O); //注册çƒé”® Ok RegisterHotKey(this.Handle, 78, 0, (UInt32)Keys.N); //注册çƒé”® NG RegisterHotKey(this.Handle, 82, 0, (UInt32)Keys.R); //注册çƒé”® Retry }
public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy(AllowSpecificOrigins, builder => builder.WithOrigins("http://slither.io").AllowAnyHeader().AllowAnyMethod()); }); var frameProcessor = new FrameProcessor(new OutcomeProcessor(new OutcomeScoreProcessor()), new CollisionMapProcessor(new CollisionMapResolutionProcessor(new CollisionSliceProcessor(new FoodSliceProcessor(new CollisionService()), new BadCollisionSliceProcessor(new CollisionService()), new SelfSliceProcessor(new CollisionService()))), new SlitherFrameNormalizer())); var gameManager = new GameManager(new GameProcessor(frameProcessor), sourceDatabaseFolder); var slitherPlayer = new SlitherPlayer(frameProcessor, new ProcessedFrameMatchAnalyzer(new CollisionMapMatchAnalyzer(new SliceMatchAnalyzer(new CollisionListMatchAnalyzer()))), new SlitherFrameNormalizer()); services.AddSingleton(gameManager); services.AddSingleton(slitherPlayer); services.AddControllers(); }
public static void GenerateLogo(FrameProcessor fp, Page page, ControlAttribute attribute, DescriptionAttribute description) { Image image = new Image(fp); image.Image = fp.Game.Content.Load <DiscTexture>(StartMenuInfo.LogoTexture); image.ImageMode = FrameImageMode.Stretched; int width = ParseBounds(StartMenuInfo.LogoWidth, page.Width); image.Width = width; image.Height = (int)((float)image.Width / (float)image.Image.Width * image.Image.Height); Size2 pos = GetLocation(StartMenuInfo.LogoPosition, page.Width, image.Width, page.Height, image.Height); image.X = pos.Width; image.Y = pos.Height; page.Add(image); }
private void CompositionTarget_Rendering(object sender, EventArgs e) { TimeSpan currentRenderingTime = (e as RenderingEventArgs).RenderingTime; if (currentRenderingTime.Ticks == LastRenderingTime.Ticks) { return; } try { FrameProcessor.UpdateFrame((currentRenderingTime - LastRenderingTime).TotalSeconds); } catch (Exception ex) { MessageBox.Show($"{ex.StackTrace}", $"{ex.Message}"); } LastRenderingTime = currentRenderingTime; }
public SlitherPlayerTests() { GameDatabase.DatabaseFolder = "C:\\SlitherShark\\test\\processed"; GameDatabase.LoadGames(); var jsonString = File.ReadAllText("C:\\SlitherShark\\test\\source\\test.json"); SourceGame = JsonConvert.DeserializeObject <Game>(jsonString, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, NullValueHandling = NullValueHandling.Ignore, }); SlitherPlayer = new SlitherPlayer(new FrameProcessor(new OutcomeProcessor(new OutcomeScoreProcessor()), new CollisionMapProcessor(new CollisionMapResolutionProcessor(new CollisionSliceProcessor(new FoodSliceProcessor(new CollisionService()), new BadCollisionSliceProcessor(new CollisionService()), new SelfSliceProcessor(new CollisionService()))), new SlitherFrameNormalizer())), new ProcessedFrameMatchAnalyzer(new CollisionMapMatchAnalyzer(new SliceMatchAnalyzer(new CollisionListMatchAnalyzer()))), new SlitherFrameNormalizer()); var frameProcessor = new FrameProcessor(new OutcomeProcessor(new OutcomeScoreProcessor()), new CollisionMapProcessor(new CollisionMapResolutionProcessor(new CollisionSliceProcessor(new FoodSliceProcessor(new CollisionService()), new BadCollisionSliceProcessor(new CollisionService()), new SelfSliceProcessor(new CollisionService()))), new SlitherFrameNormalizer())); var gameProcessor = new GameProcessor(frameProcessor); var processedGame = gameProcessor.ProcessGame(SourceGame); GameDatabase.AddGame(processedGame); }
private void MainForm_Load(object sender, EventArgs e) { this.FormBorderStyle = FormBorderStyle.None; //Full screen and no title RegisterHotKey(this.Handle, 89, 0, (UInt32)Keys.Y); //注册çƒé”® Yes 0x59 try { if (_frameProcessor == null) { Log.LogWrite("start new _frameProcessor........."); _frameProcessor = new FrameProcessor(Frame1, Frame2); } Log.LogWrite("start Search IRcameral is Open........."); UInt32 m_SearchCount = 0; while (true) { System.Threading.Thread.Sleep(10); m_SearchCount++; if (_frameProcessor.isIRcameralOpen) { ShowGuidStep("Press Yes[Y] to start capture..."); Log.LogWrite("IR Camera open..........."); break; } if (m_SearchCount > 100) { Log.LogWrite("Search out time no IR Camera device open.. exit"); QuiteApp(false); break; } } } catch (Exception ex) { Log.LogWrite("no IR Camera device available, exit"); Shutdown(); QuiteApp(false); } }
private void QuiteApp(bool bPass) { DisableInfraredSourceChangedEvents(); if (_frameProcessor != null) { _frameProcessor.Dispose(); _frameProcessor.Shutdown(); _frameProcessor.StopIRDevice(); _frameProcessor = null; } if (bPass) { Log.LogPass(); Log.WriteLogResult(STATE_PASS); Xml.XmlPass(); Xml.WriteXmlResult(STATE_PASS); Program.ExitApplication(0); } else { Log.LogFail(); Log.WriteLogResult(STATE_FAIL); Xml.XmlFail(); Xml.WriteXmlResult(STATE_FAIL); try { Program.ExitApplication(255); } catch (Exception ex) { throw(ex); Program.ExitApplication(255); System.Environment.Exit(255); } } }
/// <summary> /// Provides streamable sequence of frames processed by the application of the given <paramref name="processor"/>. /// </summary> /// <typeparam name="TValue"></typeparam> /// <param name="processor"></param> /// <returns></returns> public IStreamable <Microsoft.StreamProcessing.Empty, TValue> GetStreamable <TValue>(FrameProcessor <TValue> processor) { var observable = Observable.Create(GetSubscriber(new TickFrameProcessor <TValue>(processor).Invoke)).Select(x => new StreamEvent <TValue>(x.Ticks, x.Ticks + 1, x.Value)); return(Streamable.ToStreamable(observable)); }
public TickFrameProcessor(FrameProcessor <TValue> processor) { this.processor = processor; }
/// <summary> /// Provides observable sequence of frames processed by the application of the given <paramref name="processor"/>. /// </summary> /// <typeparam name="TValue"></typeparam> /// <param name="processor"></param> /// <returns></returns> public IObservable <TValue> GetObservable <TValue>(FrameProcessor <TValue> processor) { return(Observable.Create(GetSubscriber(processor))); }
/// <summary> /// Enables to subscribe to the stream of frames produced by the current table. /// <para/> /// It is possible to create an observable as follows: /// <code> /// FasterFrameTable table; /// var observable = Observable.Create(table.GetSubscriber(processor)); /// </code> /// </summary> /// <typeparam name="TValue"></typeparam> /// <param name="observer"></param> /// <param name="processor"></param> /// <returns></returns> public Func <IObserver <TValue>, IDisposable> GetSubscriber <TValue>(FrameProcessor <TValue> processor) { return(observer => new FrameProvider <TValue>(_framesStore, observer, processor)); }
public Image(FrameProcessor fp, Texture image, int posX, int posY, int width, int height) : base(fp, posX, posY, width, height, "", new Color(0, 0, 0, 0)) { this.Image = image; }
public static void ReadVideo(Config config, FFProbeStream streamInfo, string filePath, string outPath) { var p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = "ffmpeg.exe"; p.StartInfo.Arguments = $"-i \"{filePath}\" -f rawvideo -c:v rawvideo -pix_fmt bgra -s {streamInfo.Width}x{streamInfo.Height} pipe:1"; var f = 0; var frameLength = streamInfo.Width * streamInfo.Height * 4; var buffer = new byte[config.Model.BufferSize]; p.Start(); var stream = p.StandardOutput.BaseStream; using var frame = new MemoryStream(frameLength); var frameTasks = new List <Task>(); var frameBytesRead = 0; var bytesRead = 0; do { while (frameTasks.Count >= config.Model.FrameConcurrency) { var removeTasks = new List <Task>(); foreach (var task in frameTasks) { if (task.IsCompleted) { removeTasks.Add(task); } } foreach (var r in removeTasks) { frameTasks.Remove(r); } } if (frameBytesRead + config.Model.BufferSize > frameLength) { bytesRead = stream.Read(buffer, 0, frameLength - frameBytesRead); frame.Write(buffer); var frameProcessStream = new MemoryStream(frameLength); frame.Seek(0, SeekOrigin.Begin); frame.CopyTo(frameProcessStream); frameTasks.Add(FrameProcessor.ProcessFrame(config, frameProcessStream, f++, streamInfo.Width, streamInfo.Height, outPath)); frame.Seek(0, SeekOrigin.Begin); frameBytesRead = 0; } else { bytesRead = stream.Read(buffer, 0, buffer.Length); if (bytesRead != 0) { frameBytesRead += bytesRead; frame.Write(buffer); } } } while (!p.HasExited); p.WaitForExit(); }
public SlitherPlayer(FrameProcessor frameProcessor, ProcessedFrameMatchAnalyzer processedFrameMatchAnalyzer, SlitherFrameNormalizer slitherFrameNormalizer) { FrameProcessor = frameProcessor; ProcessedFrameMatchAnalyzer = processedFrameMatchAnalyzer; SlitherFrameNormalizer = slitherFrameNormalizer; }
public Label(FrameProcessor fp) : base(fp) { }
public static void GenerateLabel(FrameProcessor fp, Page page, ControlAttribute attribute, DescriptionAttribute description) { }
// Glorious FrameArrived Handler private void FrameArrived(MediaFrameReader sender, MediaFrameArrivedEventArgs args) { var mfRef = sender.TryAcquireLatestFrame(); var softwareBitmap = mfRef?.VideoMediaFrame?.SoftwareBitmap; if (mfRef == null || softwareBitmap == null) { mfRef?.Dispose(); return; } // Get Transform matrices var tup = FrameProcessor.GetTransforms(mfRef, unityWorldCoordinateSystem); if (tup == null) { return; } var frameToOrigin = tup.Item1; var intrinsics = tup.Item2; var extrinsics = tup.Item3; // Get System Ticks as a time value var systemTicks = mfRef.SystemRelativeTime.Value.Duration().Ticks; var w = softwareBitmap.PixelWidth; var h = softwareBitmap.PixelHeight; byte[] data; switch (softwareBitmap.BitmapPixelFormat) { case BitmapPixelFormat.Bgra8: // Color if (frameWriter != null) // debug { frameWriter.writeColorPNG(softwareBitmap, systemTicks); } // Bgra8 has 4 bytes per pixel, apparently data = new byte[4 * w * h]; softwareBitmap.CopyToBuffer(data.AsBuffer()); var buf = new byte[3 * w * h]; var c = 0; // get rid of useless byte for (var i = 0; i < w * h; i++) { for (var j = 0; j < 3; j++) { buf[c] = data[i * 4 + 2 - j]; c++; } } conn.SendColorFrame(new MessageComposer.Payload { FrameId = systemTicks, Width = softwareBitmap.PixelWidth, Height = softwareBitmap.PixelHeight, BytesPerPoint = 1, PointsPerPixel = 3, FrameToOrigin = frameToOrigin, Intrinsics = intrinsics, Extrinsics = extrinsics, Data = buf }); break; case BitmapPixelFormat.Gray16: // Depth if (frameWriter != null) // debug { frameWriter.writeDepthPGM(softwareBitmap, systemTicks); } data = new byte[2 * w * h]; softwareBitmap.CopyToBuffer(data.AsBuffer()); conn.SendDepthFrame(new MessageComposer.Payload { FrameId = systemTicks, Width = softwareBitmap.PixelWidth, Height = softwareBitmap.PixelHeight, BytesPerPoint = 2, PointsPerPixel = 1, FrameToOrigin = frameToOrigin, Intrinsics = intrinsics, Extrinsics = extrinsics, Data = data }); break; default: Debug.LogError("Invalid Frame"); break; } mfRef.Dispose(); }
public Image(FrameProcessor fp) : base(fp) { }
public Logo(FrameProcessor fp) : base(fp) { }
/// <summary> /// Initializes a new instance of this class, which provides /// basic graphics device initialization, game logic, rendering code, and a game loop. /// </summary> public Game(string gameId, IGameFactory gameFactory) { this.gameId = gameId; Enabled = true; this.GameFactory = gameFactory; AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += currentDomain_UnhandledException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; //ForceAssemblies(); Debug.Assert(Instance == null); Instance = this; Log.Message(GetReleaseInfo()); Log.Message("Startup directory : {0}", AppDomain.CurrentDomain.BaseDirectory); Log.Message("Current directory : {0}", Directory.GetCurrentDirectory()); // For animation rendering applications : // http://msdn.microsoft.com/en-us/library/bb384202.aspx GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency; config = new ConfigManager(this); inputDevice = new InputDevice(this); graphicsDevice = new GraphicsDevice(this); renderSystem = new RenderSystem(this); soundSystem = new SoundSystem(this); network = new Network(this); content = new ContentManager(this); gameTimeInternal = new GameTime(); invoker = new Invoker(this); console = new GameConsole(this); keyboard = new Keyboard(this); mouse = new Mouse(this); touch = new Touch(this); gamepads = new GamepadCollection(this); frames = new FrameProcessor(this); userStorage = new UserStorage(this); // create SV, CL and UI instances : sv = new GameServer(this); cl = new GameClient(this); ui = new UserInterface(this); ed = new GameEditor(this); config.ExposeConfig(SoundSystem, "SoundSystem", "snd"); config.ExposeConfig(RenderSystem, "RenderSystem", "rs"); config.ExposeConfig(Frames, "Frames", "frames"); config.ExposeConfig(Console, "Console", "con"); config.ExposeConfig(Network, "Network", "net"); config.ExposeConfig(Keyboard, "Keyboard", "kb"); config.ExposeConfig(Touch, "Touch", "touch"); config.ExposeConfig(Mouse, "Mouse", "mouse"); config.ExposeConfig(sv, "GameServer", "sv"); config.ExposeConfig(cl, "GameClient", "cl"); config.ExposeConfig(ui, "UserInterface", "ui"); config.ExposeConfig(ed, "GameEditor", "ed"); }
public FrameProcessorTests() { _outcomeProcessor = new Mock <IOutcomeProcessor>(); _collisionMapProcessor = new Mock <ICollisionMapProcessor>(); _frameProcessor = new FrameProcessor(_outcomeProcessor.Object, _collisionMapProcessor.Object); }
public Background(FrameProcessor fp) : base(fp) { }
public Form1() { InitializeComponent(); SetAnimation(); //ConnectToServer(); //gamestate = GameState.GAME; myTimer.Tick += new EventHandler(GameDraw); myTimer.Interval = 25; myTimer.Start(); controlTimer.Tick += new EventHandler(GameControlReset); controlTimer.Interval = 500; myplayerTimer.Tick += new EventHandler(PlayerStateReset); myplayerTimer.Interval = 5000; FPU = new FrameProcessor(); FPU.Reset(); IFormatter formatter = new BinaryFormatter(); FileStream fs = new FileStream("../../hist.dat", FileMode.Open); HistSerial hs = (HistSerial)formatter.Deserialize(fs); hist = hs.hist; FPU.SetHist(hist); }
public Label(FrameProcessor fp, int posX, int posY, int width, int height, string text, SpriteFont font, Color backColor) : base(fp, posX, posY, width, height, text, font, backColor) { }
/// <summary> /// Ctor /// </summary> /// <param name="engine"></param> public CustomGameInterface(Game game) : base(game) { console = new GameConsole(game, "conchars"); userInterface = new FrameProcessor(game, @"Fonts\textFont"); }