Exemplo n.º 1
0
    void Update()
    {
        //取得深度資料變動區塊資訊
        Mat _DepthMat = new Mat();

        if (_drawBlock.GetBlockDepthMat() != null)
        {
            _drawBlock.GetBlockDepthMat().copyTo(_DepthMat);
            Debug.Log("Wid");
            Debug.Log(_DepthMat.width());
            Debug.Log("Hei");
            Debug.Log(_DepthMat.height());
        }
        else
        {
            //Debug.Log("Is null");
            return;
        }

        List <OpenCVForUnity.Rect> changeRectList = _matchManage._changeRectList;

        //轉換座標用
        _posTrans = new clickPositionTrans(_DepthMat.width(), _DepthMat.height(), lengthX, lengthY);
        //當發生變動更新Mesh
        if (_drawBlock._DepthImageChangeFlag)
        {
            UpdateMesh(changeRectList, _DepthMat);
            _drawBlock._DepthImageChangeFlag = false;
        }
    }
    void showData()
    {
        if (width != _DrawBlockManager.MatchWidth || height != _DrawBlockManager.MatchHeight) // 如果drawblock重新框選
        {
            width  = _DrawBlockManager.MatchWidth;
            height = _DrawBlockManager.MatchHeight;
            Debug.Log("Block Size: " + width + " x " + height);
            Debug.Log("object Size: " + _mapobject.transform.localScale.x + " x " + _mapobject.transform.localScale.y);
            _clickPositionTrans = new clickPositionTrans(width, height, _mapobject.transform.localScale.x, _mapobject.transform.localScale.y);
        }

        BaseObject[] results = _MatchManager.SensingResults.ToArray();

        outputPoint.Clear();
        for (int i = 0; i < results.Length; i++)
        {
            Point[] block   = results[i]._objectBlock;
            var     centerX = (block[0].x + block[1].x) / 2;
            var     centerY = (block[0].y + block[1].y) / 2;
            //Debug.Log("#" + i + ": " + centerX + "," + centerY);
            var transPoint = _clickPositionTrans.TransToScreen2Pos(new Point(centerX, centerY));
            //Debug.Log("object" + ": " + transPoint.x + "," + transPoint.y);

            outputPoint.Add(transPoint);
        }
    }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        //cam設定與啟用
        MatchWidth  = 0;
        MatchHeight = 0;

        //取得螢幕與輸入cam的影像大小
        _inputWidth  = ColorSourceManager.ColorWidth;
        _inputHeight = ColorSourceManager.ColorHeight;
        _depthData   = DepthSourceManager.GetData();
        //Debug.Log(_depthData.Length);

        //螢幕大小與來源比例初始化
        _currentWidth  = Screen.width;
        _currentHeight = Screen.height;
        _positionTrans = new clickPositionTrans(_currentWidth, _currentHeight, _inputWidth, _inputHeight);

        //創造mat儲存輸出影像
        _sourceMat        = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC3);
        _sourceMat_backup = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC3);
        _sourceMatDepth   = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC1);
        _blockImageBuffer = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC1);
        //創造mat儲存比對用mat(原始比對圖形為未改變比例)
        _blockImage          = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC3);
        _souceOut            = new Texture2D(_inputWidth, _inputHeight);
        _blockTexture        = new Texture2D(320, 180);
        _blockDepthTexture   = new Texture2D(320, 180);
        _blockDepthTextureBg = new Texture2D(320, 180);

        isInput = false;
        //設定同步旗標
        _SyncFlag = false;
        //thread
        _thread = new Thread(drawDepthSourceMat);
        //設定是否完成影像背景偵測
        _ScreenSettingCompletionFlag = false;
        //選擇範圍初始化
        _minX = 0; _maxX = 0; _minY = 0; _maxY = 0;
        //設定影像改變旗標
        _DepthImageChangeFlag = true;

        //try
        //{
        //    System.IO.StreamReader fileData = new System.IO.StreamReader("DrawBlockData.txt", System.Text.Encoding.Default);
        //    _pointOne.x = double.Parse(fileData.ReadLine());
        //    _pointOne.y = double.Parse(fileData.ReadLine());
        //    _pointTwo.x = double.Parse(fileData.ReadLine());
        //    _pointTwo.y = double.Parse(fileData.ReadLine());
        //    fileData.Close();
        //    //_ScreenSettingCompletionFlag = false;
        //    isInput = !isInput;
        //    pointUp();
        //}
        //catch
        //{
        //    Debug.Log("Drawblock File error");
        //}
    }
Exemplo n.º 4
0
 // Update is called once per frame
 void Update()
 {
     if (_drawBlockManager.MatchHeight == 0 || _drawBlockManager.MatchWidth == 0)
     {
         _posTrans = null;//初始化
         return;
     }
     if (_kinectSettingView.active)
     {
         return;
     }
     if (_posTrans == null)
     {
         RectTransform parentRect = this.transform.parent as RectTransform;
         _posTrans = new clickPositionTrans(_drawBlockManager.MatchWidth, _drawBlockManager.MatchHeight, parentRect.rect.width, parentRect.rect.height);
     }
 }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (_currentWidth != Screen.width || _currentHeight != Screen.height)
        {
            _currentWidth  = Screen.width;
            _currentHeight = Screen.height;
            _positionTrans = new clickPositionTrans(_currentWidth, _currentHeight, _inputWidth, _inputHeight);
        }
        //讓選框狀態時暫停影像
        if (Input.GetKeyUp(KeyCode.Z))
        {
            isInput = !isInput;
        }
        if (!isInput)
        {
            ColorSourceManager.GetColorMat().copyTo(_sourceMat);
            _sourceMat.copyTo(_sourceMat_backup);
        }
        else
        {
            _sourceMat_backup.copyTo(_sourceMat);
        }
        //滑鼠點擊判斷
        if (mouseclick == 1)
        {
            pointMove();
        }
        else if (mouseclick == 2 && MatchHeight != 0 && MatchWidth != 0)
        {
            runDrawBlock();
        }
        //畫選取框框
        Imgproc.rectangle(_sourceMat, _pointOne, _pointTwo, _color, 4);

        //創造2D影像(空的)
        if (_souceOut == null)
        {
            _souceOut = new Texture2D(_inputWidth, _inputHeight);
        }
        //旋轉影像
        ReversedImage(_sourceMat).copyTo(_sourceMat);
        //將mat轉換回2D影像
        Utils.matToTexture2D(_sourceMat, _souceOut);
        //放入輸出rawImage
        _inoutImg.texture = _souceOut;
    }
Exemplo n.º 6
0
    public void CreateObject(MatchObject matchObject)
    {
        childGameObject = Instantiate(copyGameObject);                  //複製copyGameObject物件(連同該物件身上的腳本一起複製)
        childGameObject.transform.SetParent(superGameObject.transform); //放到superGameObject物件內
        RectTransform childGameObjectRect = childGameObject.GetComponent <RectTransform>();

        //座標系統統一(左下0,0)
        childGameObjectRect.anchorMin = new Vector2(0, 0);
        childGameObjectRect.anchorMax = new Vector2(0, 0);
        childGameObjectRect.pivot     = new Vector2(.5f, .5f);
        //初始化轉換座標class
        RectTransform superGameObjectRect = superGameObject.GetComponent <RectTransform>();

        _posTrans = new clickPositionTrans(_drawBlock.MatchWidth, _drawBlock.MatchHeight, superGameObjectRect.rect.width, superGameObjectRect.rect.height);
        //初始化位置
        UpdatePos(childGameObject, _speed, matchObject);
        //childGameObject.AddComponent<NullScript>();//動態增加名為"NullScript"的腳本到此物件身上
        //下面這一行的功能為將複製出來的子物件命名為CopyObject

        childGameObject.name = "CopyObject";
    }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (_bodyManager == null)
        {
            return;
        }
        bodies = _bodyManager.GetData();
        if (bodies == null)
        {
            return;
        }
        if (_drawBlockManager.MatchHeight == 0 || _drawBlockManager.MatchWidth == 0)
        {
            _posTrans = null;//初始化
            return;
        }
        if (_posTrans == null)
        {
            RectTransform parentRect = this.transform.parent as RectTransform;
            _posTrans = new clickPositionTrans(_drawBlockManager.MatchWidth, _drawBlockManager.MatchHeight, parentRect.rect.width, parentRect.rect.height);
        }
        if (_kinectSettingView.active)
        {
            return;
        }
        //遊戲狀態關閉手的圖案,保留手勢功能
        var   gameStatus = _gmaeStatusManager.CurrentStateIndex;
        Color imageColor = _handImage.GetComponent <Image>().color;

        if (gameStatus == GameState.GameRun && !_isTriggerButton)
        {
            if (imageColor.a == 1f)
            {
                _handImage.GetComponent <Image>().color = new Color(imageColor.r, imageColor.g, imageColor.b, .1f);
            }
            //if(_handImage.active)
            //    _handImage.SetActive(false);
        }
        else
        {
            if (imageColor.a == .1f)
            {
                _handImage.GetComponent <Image>().color = new Color(imageColor.r, imageColor.g, imageColor.b, 1f);
            }
            //if(!_handImage.active)
            //    _handImage.SetActive(true);
        }
        foreach (var body in bodies)
        {
            RectTransform myRect = this.transform as RectTransform;
            if (body == null)
            {
                if (_handImage.active)
                {
                    _handImage.SetActive(false);
                }
                continue;
            }
            if (body.IsTracked)
            {
                var pos = body.Joints[TrackedJoint].Position;
                //3D座標透過map轉換成2D座標
                Vector2 colorPos        = _drawBlockManager._map.CameraSpacePointToColorVector2(pos);
                Vector2 pos_inDrawBlock = GetInDrawBlockPos(colorPos);

                if (pos_inDrawBlock.x == -99 && pos_inDrawBlock.y == -99)//不在drawblock範圍內
                {
                    myRect.localPosition = new Vector3(myRect.localPosition.x, myRect.localPosition.y, 100);
                    if (_handImage.active)
                    {
                        _handImage.SetActive(false);
                    }
                }
                else
                {
                    if (!_handImage.active)
                    {
                        _handImage.SetActive(true);
                    }
                    myRect.anchoredPosition = Vector2.Lerp(myRect.anchoredPosition, _posTrans.TransToScreen2Pos(new Vector2(-pos_inDrawBlock.x, -pos_inDrawBlock.y)), _speed);
                    myRect.localPosition    = new Vector3(myRect.localPosition.x, myRect.localPosition.y, 0);
                }
            }
        }
    }