예제 #1
0
        private async void OnTrainButtonClicked(object sender, RoutedEventArgs e)
        {
            trainProgressRing.Visibility = Visibility.Visible;

            if (symbol1Images != null)
            {
                int count = symbol1Images.Count;
                for (int i = 0; i < count; i++)
                {
                    DecorateResultPickerTextBlockOnFileProcess(symbol1ResultPickerTextBlock, i, count);
                    var imageStream = await imageProcessor.Process(symbol1Images[i]);

                    await perceptron.Calculate(imageStream, trainSetConfig.Train1);
                }
            }

            if (symbol2Images != null)
            {
                int count = symbol2Images.Count;
                for (int i = 0; i < count; i++)
                {
                    DecorateResultPickerTextBlockOnFileProcess(symbol2ResultPickerTextBlock, i, count);
                    var imageStream = await imageProcessor.Process(symbol2Images[i]);

                    await perceptron.Calculate(imageStream, trainSetConfig.Train2);
                }
            }

            trainProgressRing.Visibility = Visibility.Collapsed;
        }
        private async void OnRecognizedButtonClicked(object sender, RoutedEventArgs e)
        {
            progressRing.Visibility = Visibility.Visible;

            InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();

            var file = await SaveDrawing();

            var imageStream = await imageProcessor.Process(file);

            TrainConfig result = await perceptron.Activation(imageStream);

            progressRing.Visibility = Visibility.Collapsed;

            var recognitionResult = await RecognizeDialog.ShowDialogAsync(result.Symbol);

            progressRing.Visibility = Visibility.Visible;

            if (recognitionResult == RecognitionResult.Right)
            {
                await perceptron.Calculate(imageStream.CloneStream(), result);
            }
            else
            {
                var rightConfig = await TrainSetConfigHelper.GetOppositTrainConfig(result);

                await perceptron.Calculate(imageStream.CloneStream(), rightConfig);
            }

            progressRing.Visibility = Visibility.Collapsed;

            ClearCanvas();
        }
예제 #3
0
    void Update()
    {
        directionFront = transform.up;
        directionLeft  = transform.up - transform.right;
        directionRight = transform.up + transform.right;
        directionL     = -transform.right;
        directionR     = transform.right;

        hitFront = Physics2D.Raycast(gameObject.transform.position, directionFront, 10, whatToHit);
        hitLeft  = Physics2D.Raycast(gameObject.transform.position, directionLeft, 10, whatToHit);
        hitRight = Physics2D.Raycast(gameObject.transform.position, directionRight, 10, whatToHit);

        hitL = Physics2D.Raycast(gameObject.transform.position, directionL, 10, whatToHit);
        hitR = Physics2D.Raycast(gameObject.transform.position, directionR, 10, whatToHit);

        inputs = new float[] { hitFront.distance, hitLeft.distance, hitRight.distance, hitR.distance, hitL.distance, gameObject.GetComponent <Rigidbody2D>().velocity.sqrMagnitude };
        p.UpdateInputs(inputs);

        for (int i = 0; i < inputs.Length; i++)
        {
            if (inputs[i] == 0)
            {
                inputs[i] = 10;
            }
        }

        float[] outputs = p.Calculate();

        float vel = Mathf.Clamp((outputs[0] * 2 - 1) * 10, -20, 20);
        float rot = Mathf.Clamp((outputs[1] * 2 - 1) * 10, -10, 10);


        gameObject.GetComponent <Rigidbody2D>().velocity = transform.up * vel;

        gameObject.GetComponent <Rigidbody2D>().rotation = gameObject.GetComponent <Rigidbody2D>().rotation + rot;

        //Debug.Log(string.Format("VEL:{0},ROT:{1}||{2},{3}||{4}", vel,rot, hitFront.distance, hitLeft.distance, Random.seed));

        if (Input.GetMouseButtonDown(0))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }
    void Update()
    {
        directionLeft  = left.up - left.right / 8;
        directionRight = right.up + right.right / 8;

        hitLeft  = Physics2D.Raycast(left.position, directionLeft, 10, whatToHit);
        hitRight = Physics2D.Raycast(right.transform.position, directionRight, 10, whatToHit);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            gameObject.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            gameObject.GetComponent <Rigidbody2D>().inertia  = 0;
            if (control)
            {
                control = false;
            }
            else
            {
                control = true;
            }
        }
        if (control)
        {
            gameObject.GetComponent <Rigidbody2D>().inertia = 0;
            if (Input.GetKey(KeyCode.W))
            {
                velC = transform.up * 6;
                back = false;
            }
            else

            if (Input.GetKey(KeyCode.S))
            {
                velC = transform.up * -6;
                back = true;
            }
            else
            {
                velC = Vector2.zero;
            }

            /////////////////

            if (Input.GetKey(KeyCode.A))
            {
                rotC = back ? -1.5f : 1.5f;
            }
            else
            if (Input.GetKey(KeyCode.D))
            {
                rotC = back ? 1.5f : -1.5f;
            }
            else
            {
                rotC = 0;
            }

            gameObject.GetComponent <Rigidbody2D>().velocity = velC;
            if (velC != Vector2.zero)
            {
                gameObject.GetComponent <Rigidbody2D>().rotation = gameObject.GetComponent <Rigidbody2D>().rotation + rotC;
            }
        }
        else
        {
            velC   = Vector2.zero;
            rotC   = 0;
            inputs = new float[] { hitLeft.distance, hitRight.distance };
            p.UpdateInputs(inputs);

            for (int i = 0; i < inputs.Length; i++)
            {
                if (inputs[i] == 0)
                {
                    inputs[i] = 10;
                }
            }

            float[] outputs = p.Calculate();

            float vel = Mathf.Clamp((outputs[0] * 2 - 1) * 10, -20, 20);
            float rot = Mathf.Clamp((outputs[1] * 2 - 1) * 10, -10, 10);


            gameObject.GetComponent <Rigidbody2D>().velocity = transform.up * vel;

            gameObject.GetComponent <Rigidbody2D>().rotation = gameObject.GetComponent <Rigidbody2D>().rotation + rot;

            //Debug.Log(string.Format("VEL:{0},ROT:{1}||{2},{3}||{4}", vel,rot, hitFront.distance, hitLeft.distance, Random.seed));
        }
        if (Input.GetMouseButtonDown(0))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }