Example #1
0
    public void ObjectAnalysisResult(AnalysisRootObject analysisObject)
    {
        Debug.Log("Showing result . . .");
        PrimaryText = "Showing result . . .";
        Update_DebugDisplay();

        if (analysisObject.predictions != null)
        {
            Debug.Log("Prediction is");
            PrimaryText = "Prediction is . . .";
            Update_DebugDisplay();

            // Sort the predictions to locate the highest one
            List <Prediction> sortedPredictions = new List <Prediction>();
            sortedPredictions = analysisObject.predictions.OrderBy(p => p.probability).ToList();
            Prediction bestPrediction = new Prediction();
            bestPrediction = sortedPredictions[sortedPredictions.Count - 1];

            if (bestPrediction.probability > probabilityThreshold)
            {
                //PrimaryText = bestPrediction.tagName + " : " + bestPrediction.probability.ToString();
                PrimaryText = "Take a picture to be analyzed";

                Update_DebugDisplay();

                GameObject resultPanel = Instantiate(panelReference, CameraCache.Main.transform.position, CameraCache.Main.transform.rotation);
                Vector3    toPosition  = CameraCache.Main.transform.position + CameraCache.Main.transform.forward;
                resultPanel.transform.position = toPosition;

                PredictionResultData resultData = new PredictionResultData();
                resultData.objectName      = bestPrediction.tagName;
                resultData.confidentResult = bestPrediction.probability.ToString();

                StateManagement.Instance.lastestPredictionResult = resultData;

                resultPanels.Add(resultPanel);
            }
        }
        else
        {
            Debug.Log("Object is unknown");
            PrimaryText = "Object is unknown";
            Update_DebugDisplay();
        }

        // Stop the analysis process
        ImageCapture.Instance.ResetImageCapture();
    }
    // Start is called before the first frame update
    void Start()
    {
        Text objectText = gameObject.GetComponent <Text>();

        string xboxDesc    = "Equip yourself with the Xbox Wireless Controller, featuring a sleek, streamlined design and textured grip for enhanced comfort. Enjoy custom button mapping and up to twice the wireless range. Plug in any compatible headset with the 3.5mm stereo headset jack. And with Bluetooth® technology, play your favorite games on Windows 10 PCs and tablets.*";
        string balloonDesc = "Latex balloons may be inflated with either air or helium. Because latex is a porous material, the gas (helium or air) molecules pass through the surface, eventually causing the balloon to deflate or descend. When air-inflated, latex balloons stay inflated considerably longer than those inflated with helium because air molecules are larger and slower moving than helium molecules, so air doesn't escape as quickly as helium.";

        if (StateManagement.Instance.lastestPredictionResult != null)
        {
            PredictionResultData resultData = StateManagement.Instance.lastestPredictionResult;

            if (resultData.objectName == "Balloon")
            {
                shownDesc = balloonDesc;
            }
            else if (resultData.objectName == "XboxController")
            {
                shownDesc = xboxDesc;
            }
            else
            {
                shownDesc = "None Desc";
            }

            switch (name)
            {
            case "ResultObjectName":
                objectText.text = resultData.objectName;
                break;

            case "ResultObjectDesc":
                //objectText.text = resultData.description;
                objectText.text = shownDesc;
                break;

            case "ConfidentValue":
                objectText.text = resultData.confidentResult;
                break;

            default:
                objectText.text = "Unidentified";
                break;
            }
        }
    }