Beispiel #1
0
    bool SetImage()
    {
        bool    isCurrentMarker = false;
        Vector3 pos0            = arCameraNumber.WorldToScreenPoint(cropLD.transform.position);
        Vector3 pos1            = arCameraNumber.WorldToScreenPoint(cropLU.transform.position);
        Vector3 pos2            = arCameraNumber.WorldToScreenPoint(cropRD.transform.position);
        Vector3 pos3            = arCameraNumber.WorldToScreenPoint(cropRU.transform.position);

        Vector3[] posList = new Vector3[] { pos0, pos1, pos2, pos3 };

        Debug.Log("pos0 : " + pos0);
        Debug.Log("pos1 : " + pos1);
        Debug.Log("pos2 : " + pos2);
        Debug.Log("pos3 : " + pos3);
        float xMin = float.MaxValue;
        float yMin = float.MaxValue;
        float xMax = float.MinValue;
        float yMax = float.MinValue;

        foreach (Vector3 v in posList)
        {
            if (v.x < xMin)
            {
                xMin = v.x;
            }
        }
        foreach (Vector3 v in posList)
        {
            if (v.x > xMax)
            {
                xMax = v.x;
            }
        }
        foreach (Vector3 v in posList)
        {
            if (v.y < yMin)
            {
                yMin = v.y;
            }
        }
        foreach (Vector3 v in posList)
        {
            if (v.y > yMax)
            {
                yMax = v.y;
            }
        }

        //Debug.Log("xMin : " + xMin + "yMin : " + yMin + "xMax : " + xMax + "yMax : " + yMax + "pos0 : " + pos0);
        Rect croppedRect = new Rect(xMin, yMin, xMax - xMin, yMax - yMin);

        Debug.Log("cropped Rect : " + croppedRect);
        string fileName = arController.GetScreenShotPath(croppedRect, pos0, pos1, pos2, pos3);

        if (fileName != string.Empty)
        {
            AndroidJavaObject file = new AndroidJavaObject("java.io.File", Application.persistentDataPath, fileName);
            //AndroidJavaObject file = new AndroidJavaObject("java.io.File", Application.persistentDataPath, "sstest.jpg");
            //jo.Call("SetImage", Application.persistentDataPath + "/test.png");
            tesseract.Call("setImage", file);
            string result = tesseract.Call <string>("getUTF8Text");
            Debug.Log("result : " + result);
            if (CheckMarkerFromString(result))
            {
                isCurrentMarker = true;
            }
        }
        //if (!isCurrentMarker)
        //{
        //    messageText.text = "ไม่ตรงกับ ID ของคุณ";
        //    PopupMessage.SetActive(true);
        //}
        return(isCurrentMarker);
    }