예제 #1
0
    // Use this for initialization
    void Start()
    {
        holds = GameObject.FindGameObjectsWithTag("Hold");

        loopManager = gameObject.GetComponent <LoopManager>();

        loopManager.Setup(soundItems);

        // If starting directly into music scene, holds will be empty
        if (DEBUG)
        {
            holds = ClimbARHandhold.InstantiateHandholds(prefabHold, GetComponent <Camera>(), new float[] { 1f, 1f, 0.2f, 0.2f, 2f, 2f, 0.2f, 0.2f, 1f, 1f, 0.1f, 0.1f, 0.4f, 0.4f, 0.3f, 0.2f });
            holds[0].transform.localPosition = new Vector2(-1, -1);
            holds[1].transform.localPosition = new Vector2(1, 1);
            holds[2].transform.localPosition = new Vector2(-1, 1);
            holds[3].transform.localPosition = new Vector2(1, -1);
        }
        // If not debugging and no holds, just return
        else if (holds.Length <= 0)
        {
            return;
        }

        // Otherwise we actually have holds, assign it to hold
        HashSet <int> usedHoldIndexes  = new HashSet <int>();
        HashSet <int> usedSoundIndexes = new HashSet <int>();

        if (holds.Length < soundItems.Length)
        {
            Debug.Log("Not enough handholds for the number of sound items");
        }

        for (int i = 0; i < Mathf.Min(holds.Length, soundItems.Length); i++)
        {
            GameObject soundHold = holds[i];
            if (soundHold == null)
            {
                Debug.Log("no valid hold found");
            }
            else
            {
                ClimbARHandhold.HoldLineRendererActive(soundHold, true);
                ClimbingHold holdScript = soundHold.GetComponent <ClimbingHold>();
                Destroy(holdScript);

                SoundHold soundHoldScript = soundHold.AddComponent <SoundHold>();

                soundHoldScript.Setup(soundItems[i], i, loopManager);

                loopManager.RegisterHold(soundHoldScript.holdIndex, i);

                soundHoldScript.GetComponent <LineRenderer>()
                .startColor = UnityEngine.Color.cyan;
                soundHoldScript.GetComponent <LineRenderer>()
                .endColor = UnityEngine.Color.cyan;

                GameObject holdText       = new GameObject();
                HoldText   holdTextScript = holdText.AddComponent <HoldText>();
                holdTextScript.addText("   " + soundItems[i], holdText, soundHold);
            }
        }
    }
예제 #2
0
    // coroutine for overlaying bounding boxes on color image
    IEnumerator GrabFrameAndClassify(float delay)
    {
        classifyRunning = true;
        Debug.Log("starting classification coroutine");

        GameObject     bodyView = GameObject.Find("KinectBodyView");
        BodySourceView view     = bodyView.GetComponent <BodySourceView>();

        view.isClassifying = true;

        yield return(new WaitForSeconds(delay));

        if (_Reader == null)
        {
            Debug.Log("Using hardcoded bounding boxes or image");
            view.isClassifying = false;
            yield return(null);
        }
        ColorFrame frame = _Reader.AcquireLatestFrame();

        if (frame != null)
        {
            int     numHolds;
            float[] holdsBoundingBoxes;
            int     imageWidth;
            int     imageHeight;

            if (DEBUG)
            {
                Debug.Log("In debug mode; using hardcoded bounding boxes");
                //holdsBoundingBoxes = new int[] { 500, 500, 100, 100, 700, 700, 150, 150 };
                holdsBoundingBoxes = new float[] { 500, 500, 100, 100, 500, 100, 200, 200 };
                numHolds           = holdsBoundingBoxes.Length / 4;

                imageWidth  = 1000;
                imageHeight = 1000;
            }
            else
            {
                // don't apply texture, just load it for classification
                frame.CopyConvertedFrameDataToArray(
                    _Data,
                    ColorImageFormat.Bgra);
                _Texture.LoadRawTextureData(_Data);

                // classify image using OpenCV classifier

                FrameDescription frameDesc = _Sensor
                                             .ColorFrameSource
                                             .CreateFrameDescription(ColorImageFormat.Bgra);
                imageWidth         = frameDesc.Width;
                imageHeight        = frameDesc.Height;
                holdsBoundingBoxes = classifyWithOpenCV(imageWidth, imageHeight);
                if (holdsBoundingBoxes[0] < 0)
                {
                    if (!DEBUG)
                    {
                        frame.Dispose();
                        frame = null;
                    }
                    Debug.LogError("Error with classifying. Exiting coroutine");
                    classifyRunning = false;
                    yield break;
                }
                numHolds = holdsBoundingBoxes.Length / 4;
            }

            float[] projectorBounds = StateManager.instance.getProjectorBounds();
            float[] holdsProjectorTransformed;

            if (!StateManager.instance.debugView)
            {
                holdsProjectorTransformed =
                    ClimbARTransformation.transformOpenCvToUnitySpace(
                        projectorBounds,
                        holdsBoundingBoxes);
            }
            else
            {
                holdsProjectorTransformed = new float[holdsBoundingBoxes.Length];
                for (int i = 0; i < holdsBoundingBoxes.Length; i++)
                {
                    holdsProjectorTransformed[i] = (float)holdsBoundingBoxes[i];
                }
            }

            Debug.Log("instantiating " + numHolds + " holds");

            cleanHandHolds(ref this.handholds);
            this.handholds = ClimbARHandhold.InstantiateHandholds(
                this.Handhold,
                this.mainCam,
                holdsProjectorTransformed);

            // persist holds
            for (int i = 0; i < this.handholds.Length; i++)
            {
                DontDestroyOnLoad(this.handholds[i]);
            }

            if (!DEBUG)
            {
                frame.Dispose();
                frame = null;
            }
        }
        else
        {
            Debug.LogError("Frame was null");
        }

        // release locks for this file and the body source view text
        classifyRunning    = false;
        view.isClassifying = false;
    }