Example #1
0
        public double[] getDoubleArray()
        {
            //GET DOUBLE ARRAY
            double[] dblArray = null;
            switch (NetMain.Net.Mode)
            {
            case MODE.PIXEL: dblArray = NetDraw.BitmapToDoubleArray(LastFrameCam); break;

            case MODE.HSENSOR: dblArray = LastSensor; break;
            }
            return(dblArray);
        }
Example #2
0
        private void ModeHSensor(Bitmap xBmp, PaintEventArgs e)
        {
            //HSENSOR MODE
            Graphics g = e.Graphics;

            //GENERATE SENSOR DATA
            double max = xBmp.Width;

            double[] sensor = new double[xBmp.Height];

            for (int y = 0; y < xBmp.Height; y++)
            {
                int count = 0;
                for (int x = 0; x < xBmp.Width; x++)
                {
                    Color getColor = xBmp.GetPixel(x, y);
                    if (Mod_Check.isGray(getColor, 200))
                    {
                        count++;
                    }
                    else
                    {
                        if (Mod_Check.isEven(y))                                                          //DISPLAY EVERY SECOND SENSOR
                        {
                            g.DrawLine(Pen, new Point(0, y), new Point(count, y));                        //DRAW SENSOR TO CAMERA
                            Graphics.FromImage(xBmp).DrawLine(Pen, new Point(0, y), new Point(count, y)); //DRAW SENSOR TO SCREEN
                        }
                        sensor[y] = count / max;
                        count     = 0;
                        break;
                    }
                }
            }

            //SET BINARY IMAGE
            NetMain.PanelBinary.BackgroundImage = NetDraw.ScaleUp(new Bitmap(xBmp));
            LastSensor = sensor;

            g.Dispose();
        }
Example #3
0
 private void ModePixel(Bitmap xBmp)
 {
     //PIXEL MODE
     NetMain.PanelBinary.BackgroundImage = NetDraw.ScaleUp(new Bitmap(xBmp));
 }
Example #4
0
        private void eventPaint(object sender, PaintEventArgs e)
        {
            //TAKE LIVE IMAGE
            Bitmap screen = new Bitmap(CamWidth, CamHeight, PixelFormat.Format32bppArgb);

            Opacity = 0.0;
            Graphics.FromImage(screen).CopyFromScreen(CamLeft, CamTop, 0, 0, screen.Size, CopyPixelOperation.SourceCopy);
            Opacity = NetMain.TrackOpacity.getValue();

            //GET FRAME RATE
            NetMain.LabelFps.Text = getFrameRate().ToString();

            //INITIALIZE LAST FRAME
            if (LastFrameCam == null)
            {
                LastFrameCam = screen;
            }

            //SET TO SHOW PANEL
            NetMain.PanelShow.BackgroundImage = new Bitmap((Bitmap)NetDraw.ScaleUp(screen));
            ListFrame.Push(new Bitmap(screen));

            //DELAY
            if (ListFrame.Limit > 0)
            {
                screen = ListFrame.getLast();
            }

            //INITIALIZE VARIABLES
            bool  next = false;
            Color getColor, setColor = Color.White;

            //SCALE DOWN
            screen = (Bitmap)NetDraw.ScaleDown(screen);
            Bitmap bmp = new Bitmap(screen);

            //CONVERT GRAY SCALE
            for (int y = 0; y < bmp.Height; y++)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    getColor = bmp.GetPixel(x, y);

                    //CHECK IS ALIVE
                    if (isAlive(getColor, x, y))
                    {
                        next = true;
                    }

                    switch (NetMain.Net.Mode)
                    {
                    case MODE.PIXEL: setColor = Colors.getGray(getColor); break;                //GREY SCALE CONVERSION

                    case MODE.HSENSOR: setColor = Colors.getBlackWhite(getColor); break;        //BLACK OR WHITE CONVERSION
                    }

                    //CUSTOM CONVERSION
                    setColor = getCustomConversion(getColor, setColor);

                    //SET PIXEL COLOR
                    bmp.SetPixel(x, y, setColor);
                }
            }

            //AFTER CONVERSION
            switch (NetMain.Net.Mode)
            {
            case MODE.PIXEL: ModePixel(bmp); break;

            case MODE.HSENSOR: ModeHSensor(new Bitmap(bmp), e); break;
            }

            //SET LAST FRAME AND ALIVE
            LastFrameCam = screen;
            LastFrameNet = bmp;
            Alive        = next;

            //NET QUERY
            if (NetMain.ToggleQuery.Checked)
            {
                NetDraw.Draw(NetDraw.ScaleDown(bmp));
            }

            //NET SEND KEYS
            if (NetMain.ToggleSend.Checked)
            {
                eventGlobalSendKeys(NetMain.neuralNetworkQuery(getDoubleArray(), 0.5));
            }

            //NET LEARNING
            else
            {
                NetMain.Mario.LearningRun();
            }
        }