Example #1
0
        private void Vision_OnObjectClassified(object sender, ClassificationResultArgs e)
        {
            // Display the top guess for the dominant object on the image
            _text.text = e.observations.First().identifier;

            // Release the native object
            _cvPixelBuffer.Dispose();
        }
 private void Vision_OnObjectClassified(object sender, ClassificationResultArgs e)
 {
     // Display the top guess for the dominant object on the image
     _text.text = e.observations.First().identifier;
 }
Example #3
0
        private void Vision_OnObjectClassified(object sender, ClassificationResultArgs e)
        {
            // Display the top guess for the dominant object on the image

            bool[] foundArray = new bool[objCount];
            for (int i = 0; i < objCount; i++)
            {
                foundArray [i] = false;
            }

            int index = -1;

            foreach (VisionClassification obs in e.observations)
            {
                // Ignore detections with low confidence

                if (obs.confidence < 0.65)
                {
                    continue;
                }

                index++;
                string name = obs.identifier.Split(',')[0];

                // create the Detection GameObject if necessary

                if (_markerArray [index] == null)
                {
                    _markerArray [index] = GameObject.Instantiate <GameObject>(_detectionPrimitive);
                }

                // Need to convert the box factors to be centered around 0
                // The DetectionRectangle is going to be 1m from the camera so in fact
                // these percentages become coordinates.

                float xMin = (obs.xMin - 0.5f);
                float yMin = (obs.yMin - 0.5f);
                float xMax = (obs.xMax - 0.5f);
                float yMax = (obs.yMax - 0.5f);

                // The center of the box is needed for the GameObject local position

                float xCenter = (xMax - xMin) / 2 + xMin;
                float yCenter = -((yMax - yMin) / 2 + yMin);

                // The primitive plane GameObject is 10 x 10 so the width (which will be used as the
                // local scale for the plane) has to be divided by 10

                float width  = (xMax - xMin) / 10.0f;
                float height = (yMax - yMin) / 10.0f;

                Debug.Log("Got: " + index + ", " + name + " " + obs.confidence + " " + obs.xMin + " " + obs.yMin + " " + obs.xMax + " " + obs.yMax +
                          "/n" + "Center: " + xCenter + ", " + yCenter + " size: " + width + ", " + height);

                Vector3 pos = new Vector3(xCenter, yCenter, 0);



                // Set the correct data in the child GameObjects

                _markerArray [index].GetComponentInChildren <DetectionRectangle> ().SetData(pos, width, height);
                _markerArray [index].GetComponentInChildren <DetectionName> ().SetData(pos, name);

                foundArray[index] = true;
            }


            for (int i = 0; i < objCount; i++)
            {
                if (_markerArray[i] != null)
                {
                    // Hide the marker if the index is unused or show if it is used
                    _markerArray[i].gameObject.SetActive(foundArray[i]);
                }
            }

            //ARKit placement

            if (e.observations.FirstOrDefault().identifier != cachedName && e.observations.FirstOrDefault().identifier != null)
            {
                float   xC     = Mathf.Lerp(e.observations.FirstOrDefault().xMin, e.observations.FirstOrDefault().xMax, 0.5f);
                float   yC     = Mathf.Lerp(e.observations.FirstOrDefault().yMin, e.observations.FirstOrDefault().yMax, 0.5f);
                Vector2 hitPos = new Vector2(xC, yC);
                //Vector2 screenPos = new Vector2(xCenter, yCenter);
                m_UnityARHitTestExample.PerformPlaceMentFromVision(hitPos, e.observations.FirstOrDefault().identifier);
                Debug.Log("m_UnityARHitTestExample.PerformPlaceMentFromVision called");

                cachedName = e.observations.FirstOrDefault().identifier;
            }
        }