Exemplo n.º 1
0
        private void test()
        {
            //for test // id=0,title=keyboard,confidence=0.64,location.(x:434.00, y:11.58, width:204.65, height:199.89), width=640, height=480
            List <Recognition> testlist    = new List <Recognition>();
            Recognition        recognition = new Recognition();

            recognition.id          = "0";
            recognition.title       = "keyboard";
            recognition.confidence  = 0.94f;
            recognition.frameWidth  = 640;
            recognition.frameHeight = 480;
            recognition.location    = new Rect(434, 11.58f, 204.63f, 199.89f);
            testlist.Add(recognition);
            OnRecognizeSuccess(testlist);
            // for test
        }
Exemplo n.º 2
0
        void OnRecognizeSuccess(List <Recognition> dataList)
        {
            ClearRecognitionFrame();

            if (!isRecognizing)
            {
                return;
            }

            for (int i = 0, size = dataList.Count; i < size; i++)
            {
                Recognition recog   = dataList[i];
                float       offsetX = recog.location.x / recog.frameWidth;
                float       offsetY = recog.location.y / recog.frameHeight;
                float       scaleX  = recog.location.width / recog.frameWidth;
                float       scaleY  = recog.location.height / recog.frameHeight;

                float newScaleX  = scaleX * previewPanelSize.x;
                float newScaleY  = scaleY * previewPanelSize.y;
                float newCenterX = previewPanelTL.x + offsetX * previewPanelSize.x + newScaleX / 2;
                float newCenterY = previewPanelTL.y - offsetY * previewPanelSize.y - newScaleY / 2;
                //Debug.Log("Recognition==>" + recog.location.width + "/" + recog.frameWidth + "," +
                //    +previewPanelSize.x + "," + newCenterX + ","
                //   + offsetX + "," + newScaleX + "," + previewPanelTL.x);
                //recog.PrintInfo();
                if (cacheTransform == null)
                {
                    return;
                }
                GameObject frameGo = Instantiate(Resources.Load("Prefabs/RecognitionFrame")) as GameObject;
                frameGo.transform.SetParent(cacheTransform);
                frameGo.transform.localPosition            = new Vector3(newCenterX, newCenterY, cameraPreviewPanelTransform.localPosition.z - 0.05f * i);
                frameGo.transform.localRotation            = Quaternion.identity;
                frameGo.transform.Find("Frame").localScale = new Vector3(newScaleX, newScaleY, 1);

                Transform descTransform = frameGo.transform.Find("Desc");
                descTransform.localPosition = new Vector3(0.2f - newScaleX / 2, newScaleY / 2 - 0.2f, 0);
                TextMesh descTextMesh = descTransform.GetComponent <TextMesh>();
                descTextMesh.text = recog.title + "(" + recog.confidence + ")";

                frameGoList.Add(frameGo);
            }
        }
Exemplo n.º 3
0
            //List<Classifier.Recognition> mappedRecognitions
            public void onRecoginizeSuccess(AndroidJavaObject list)
            {
                if (!_RecognizeApi.IsRunning())
                {
                    return;
                }

                int size = list.Call <int>("size");
                List <Recognition> dataList = new List <Recognition>(size);

                for (int i = 0; i < size; i++)
                {
                    Recognition       rec  = new Recognition();
                    AndroidJavaObject item = list.Call <AndroidJavaObject>("get", i);
                    rec.id    = item.Call <string>("getId");
                    rec.title = item.Call <string>("getTitle");
                    AndroidJavaObject confidenceObject = item.Call <AndroidJavaObject>("getConfidence");
                    rec.confidence = ((int)(confidenceObject.Call <float>("floatValue") * 100)) / 100.00f;
                    AndroidJavaObject locationObject = item.Call <AndroidJavaObject>("getLocation");
                    float             cx             = locationObject.Call <float>("centerX");
                    float             cy             = locationObject.Call <float>("centerY");
                    float             width          = locationObject.Call <float>("width");
                    float             height         = locationObject.Call <float>("height");
                    rec.frameWidth  = item.Call <int>("getPreviewWidth");
                    rec.frameHeight = item.Call <int>("getPreviewHeight");
                    Rect rect = new Rect(cx - width / 2, cy - height / 2, width, height);
                    rec.location = rect;

                    // LOG
                    // rec.PrintInfo();

                    dataList.Add(rec);

                    Loom.QueueOnMainThread((param) =>
                    {
                        if (_OnRecognizeSuccess != null)
                        {
                            _OnRecognizeSuccess((List <Recognition>)param);
                        }
                    }, dataList);
                }
            }