} // Update

    void OnDestroy()
    {
        if (isInitialized)
        {
            LibOmniProCam.finalize();
            print("libOmniProCamThread: Closed.");
        }
    } // OnDestroy
    protected CameraTexture[] cameraTextureArray = new CameraTexture[2];  // 0: src image, 1: binarized image

    // Use this for initialization
    void Awake()
    {
        /* 設定ファイル読み込み */
        try {
            print("Start loading OmniProCam config parameters...");
            using (StreamReader streamReader = new StreamReader(settingFilePath)) {
                while (streamReader.EndOfStream == false)
                {
                    sdkType          = int.Parse(streamReader.ReadLine());
                    maxObjects       = int.Parse(streamReader.ReadLine());
                    roi.x            = float.Parse(streamReader.ReadLine());
                    roi.y            = float.Parse(streamReader.ReadLine());
                    roi.width        = float.Parse(streamReader.ReadLine());
                    roi.height       = float.Parse(streamReader.ReadLine());
                    maxSizeThreshold = int.Parse(streamReader.ReadLine());
                    minSizeThreshold = int.Parse(streamReader.ReadLine());
                    print("Parameters have been loaded from " + settingFilePath);
                    print(" SDK Type: " + sdkType + "  MaxObjects: " + maxObjects + ", ROI.x: " + roi.x + ", ROI.y: " + roi.y
                          + ", ROI.width: " + roi.width + ", ROI.height: " + roi.height
                          + ", MaxSizeThreshold: " + maxSizeThreshold + ", MinSizeThreshold: " + minSizeThreshold);
                } // while

                /* 初期化 */
                print("Start initializing OmniProCam devices...");
                LibOmniProCam.setCameraSDKType(sdkType);
                int returnedValue = LibOmniProCam.initialize((int)roi.x, (int)roi.y, (int)roi.width, (int)roi.height,
                                                             maxSizeThreshold, minSizeThreshold, maxObjects);
                if (returnedValue == 0)
                {
                    print("LibOmniProCam has been initialized!");
                    isInitialized = true;
                }
                else
                {
                    print("Failed to initialize LibOmniProCam: " + returnedValue.ToString());
                    isInitialized = false;
                    Destroy(gameObject);
                }
            }

            /* 結果データ初期化 */
            resultOmniProCamData = new OmniProCamData[maxObjects];

            /* カメラ画像配列の初期化 */
            cameraTextureArray[0] = new CameraTexture((int)roi.width, (int)roi.height); // src
            cameraTextureArray[1] = new CameraTexture((int)roi.width, (int)roi.height); // src

            LibOmniProCam.setShutterSpeed((int)shutterSpeedUSec);
            LibOmniProCam.setGain(gain);
            LibOmniProCam.setBinarizingThreshold(50.0f);
        } catch (Exception e) {
            print("OmniProCam config file(" + settingFilePath + ") could not be loaded(" + e.ToString() + ")");
            Destroy(gameObject);
        }
    } // Awake
예제 #3
0
  // Use this for initialization
  void Start () {

    /* マルチディスプレイ有効化 */
    if (Display.displays.Length > 1) {
      Display.displays[1].Activate();
    }

    if (Display.displays.Length > 2) {
      Display.displays[2].Activate();
    }

    omniProCamDeviceManagerPtr = GameObject.Find("OmniProCam/LibOmniProCamManager").GetComponent<OmniProCamDeviceManager>();
    meshRenderer = GetComponent<MeshRenderer>();

    /* 初期値 */
    loadAdjustmentValuesToFile();

    LibOmniProCam.setBinarizingThreshold(binarizingThreshold);
  }
    } // Awake

    // Update is called once per frame
    void Update()
    {
        /* Process */
        //int counter = LibOmniProCam.process();
        LibOmniProCam.process();
        //print(counter);

        /* 結果取得 */
        LibOmniProCam.getObjectData(resultOmniProCamData);

        /* カメラ画像の取得 */
        if (cameraTextureType == CameraTextureType.CAMERA_TEXTURE_TYPE_SRC)
        {
            LibOmniProCam.getSrcImageRGBAForUnity(cameraTextureArray[0].pixelsIntPtr, (int)roi.width, (int)roi.height);
            cameraTextureArray[0].texture.SetPixels32(cameraTextureArray[0].pixels);
            cameraTextureArray[0].texture.Apply();
        }
        else if (cameraTextureType == CameraTextureType.CAMERA_TEXTURE_TYPE_BINARIZED)
        {
            LibOmniProCam.getBinarizedImageRGBAForUnity(cameraTextureArray[1].pixelsIntPtr, (int)roi.width, (int)roi.height);
            cameraTextureArray[1].texture.SetPixels32(cameraTextureArray[1].pixels);
            cameraTextureArray[1].texture.Apply();
        }
    } // Update
    // Update is called once per frame
    void Update()
    {
        /* スケールの微調整 */
        if (!Input.GetKey(KeyCode.O))
        {
            /* 縦スケールの微調整 */
            if (Input.GetKey(KeyCode.E))
            {
                scale.y += 0.1f * Time.deltaTime;
                transform.localScale = scale;
            }
            else if (Input.GetKey(KeyCode.D))
            {
                scale.y -= 0.1f * Time.deltaTime;
                transform.localScale = scale;
            }
            /* 縦スケールの微調整 */
            if (Input.GetKey(KeyCode.F))
            {
                scale.x += 0.1f * Time.deltaTime;
                transform.localScale = scale;
            }
            else if (Input.GetKey(KeyCode.A))
            {
                scale.x -= 0.1f * Time.deltaTime;
                transform.localScale = scale;
            }

            /* オフセットの設定 */
        }
        else
        {
            /* 縦オフセットの微調整 */
            if (Input.GetKey(KeyCode.E))
            {
                offset.y          += 0.05f * Time.deltaTime;
                transform.position = new Vector3(offset.x, 0.0f, offset.y);
            }
            else if (Input.GetKey(KeyCode.D))
            {
                offset.y          -= 0.05f * Time.deltaTime;
                transform.position = new Vector3(offset.x, 0.0f, offset.y);
            }

            /* 横オフセットの微調整 */
            if (Input.GetKey(KeyCode.F))
            {
                offset.x          += 0.05f * Time.deltaTime;
                transform.position = new Vector3(offset.x, 0.0f, offset.y);
            }
            else if (Input.GetKey(KeyCode.A))
            {
                offset.x          -= 0.05f * Time.deltaTime;
                transform.position = new Vector3(offset.x, 0.0f, offset.y);
            }
        }

        /* 縦オフセットの微調整 */
        if (Input.GetKey(KeyCode.E))
        {
            offset.y          += 0.05f * Time.deltaTime;
            transform.position = new Vector3(offset.x, 0.0f, offset.y);
        }

        /* 2値化閾値 */
        if (Input.GetKey(KeyCode.UpArrow))
        {
            binarizingThreshold += 1.0f;
            if (binarizingThreshold >= 255.0f)
            {
                binarizingThreshold = 255;
            }
            LibOmniProCam.setBinarizingThreshold(binarizingThreshold);
            print("BinarizingThreshold: " + binarizingThreshold);
        }
        else if (Input.GetKey(KeyCode.DownArrow))
        {
            binarizingThreshold -= 1.0f;
            if (binarizingThreshold <= 0.0f)
            {
                binarizingThreshold = 0;
            }
            LibOmniProCam.setBinarizingThreshold(binarizingThreshold);
            print("BinarizingThreshold: " + binarizingThreshold);
        }

        ///* 高さ */
        //if (Input.GetKey(KeyCode.PageUp)) {
        //  transform.Translate(0.0f, 0.1f * Time.deltaTime, 0.0f);
        //} else if (Input.GetKey(KeyCode.PageDown)) {
        //  transform.Translate(0.0f, -0.1f * Time.deltaTime, 0.0f);
        //}

        /* 書き出し */
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            if (omniProCamDeviceManagerPtr.getCameraTextureType() == CameraTextureType.CAMERA_TEXTURE_TYPE_BINARIZED)
            {
                omniProCamDeviceManagerPtr.setCameraTextureType(CameraTextureType.CAMERA_TEXTURE_TYPE_SRC);
                print("CameraTextureType: Src");
            }
            else
            {
                omniProCamDeviceManagerPtr.setCameraTextureType(CameraTextureType.CAMERA_TEXTURE_TYPE_BINARIZED);
                print("CameraTextureType: Binarized");
            }
        }

        OmniProCamData[] ptr = omniProCamDeviceManagerPtr.getOmniProCamDataArrayPtr();
        foreach (OmniProCamData i in ptr)
        {
            if (i.id != 0)
            {
            }
        }

        /* 投影 */
        if (omniProCamDeviceManagerPtr.getCameraTextureType() == CameraTextureType.CAMERA_TEXTURE_TYPE_BINARIZED)
        {
            meshRenderer.material.SetTexture("_AlphaTex0", omniProCamDeviceManagerPtr.getBinarizedCameraImageTexturePtr().texture);
        }
        else
        {
            meshRenderer.material.SetTexture("_AlphaTex0", omniProCamDeviceManagerPtr.getSrcCameraImageTexturePtr().texture);
        }
    }
예제 #6
0
    void Update()
    {
        /* スケールの微調整 */
        //if (!Input.GetKey(KeyCode.O)) {

        //  /* 縦スケールの微調整 */
        //  if (Input.GetKey(KeyCode.E)) {
        //    scale.y += 0.1f * Time.deltaTime;
        //    transform.localScale = scale;
        //  } else if (Input.GetKey(KeyCode.D)) {
        //    scale.y -= 0.1f * Time.deltaTime;
        //    transform.localScale = scale;
        //  }
        //  /* 縦スケールの微調整 */
        //  if (Input.GetKey(KeyCode.F)) {
        //    scale.x += 0.1f * Time.deltaTime;
        //    transform.localScale = scale;
        //  } else if (Input.GetKey(KeyCode.A)) {
        //    scale.x -= 0.1f * Time.deltaTime;
        //    transform.localScale = scale;
        //  }

        //  /* オフセットの設定 */
        //} else {

        //  /* 縦オフセットの微調整 */
        //  if (Input.GetKey(KeyCode.E)) {
        //    offset.y += 0.05f * Time.deltaTime;
        //    transform.position = new Vector3(offset.x, 0.0f, offset.y);
        //  } else if (Input.GetKey(KeyCode.D)) {
        //    offset.y -= 0.05f * Time.deltaTime;
        //    transform.position = new Vector3(offset.x, 0.0f, offset.y);
        //  }

        //  /* 横オフセットの微調整 */
        //  if (Input.GetKey(KeyCode.F)) {
        //    offset.x += 0.05f * Time.deltaTime;
        //    transform.position = new Vector3(offset.x, 0.0f, offset.y);
        //  } else if (Input.GetKey(KeyCode.A)) {
        //    offset.x -= 0.05f * Time.deltaTime;
        //    transform.position = new Vector3(offset.x, 0.0f, offset.y);
        //  }
        //}



        ///* 2値化閾値 */
        //if (Input.GetKey(KeyCode.UpArrow)) {
        //  binarizingThreshold += 1.0f;
        //  if (binarizingThreshold >= 255.0f) {
        //    binarizingThreshold = 255;
        //  }
        //  LibOmniProCam.setBinarizingThreshold(binarizingThreshold);
        //  print("BinarizingThreshold: " + binarizingThreshold);
        //} else if (Input.GetKey(KeyCode.DownArrow)) {
        //  binarizingThreshold -= 1.0f;
        //  if (binarizingThreshold <= 0.0f) {
        //    binarizingThreshold = 0;
        //  }
        //  LibOmniProCam.setBinarizingThreshold(binarizingThreshold);
        //  print("BinarizingThreshold: " + binarizingThreshold);
        //}



        /* 書き出し */
        //Use "0" Can change the image between src &binarized
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            if (omniProCamDeviceManagerPtr.getCameraTextureType() == CameraTextureType.CAMERA_TEXTURE_TYPE_BINARIZED)
            {
                omniProCamDeviceManagerPtr.setCameraTextureType(CameraTextureType.CAMERA_TEXTURE_TYPE_SRC);
                print("CameraTextureType: Src");
            }
            else
            {
                omniProCamDeviceManagerPtr.setCameraTextureType(CameraTextureType.CAMERA_TEXTURE_TYPE_BINARIZED);
                print("CameraTextureType: Binarized");
            }
        }



        // Using binary image for shade and threshold
        if (isFaceThreshold)
        {
            omniProCamDeviceManagerPtr.setCameraTextureType(CameraTextureType.CAMERA_TEXTURE_TYPE_BINARIZED);
            binarizingThreshold = faceThresholdValue;
            LibOmniProCam.setBinarizingThreshold(binarizingThreshold);
        }


        ///* MlioLight Application */
        //if (omniProCamDeviceManagerPtr.getCameraTextureType() == CameraTextureType.CAMERA_TEXTURE_TYPE_BINARIZED) {
        //  meshRenderer.material.SetTexture("_AlphaTex0", omniProCamDeviceManagerPtr.getBinarizedCameraImageTexturePtr().texture);
        //} else {
        //  meshRenderer.material.SetTexture("_AlphaTex0", omniProCamDeviceManagerPtr.getSrcCameraImageTexturePtr().texture);
        //}


        /*Image Proseeing Part*/

        /* if use the IR camera with FlyCapture SDk */
        if (UseIRCamera)
        {
            //convert from tex to tex2d
            if (omniProCamDeviceManagerPtr.getCameraTextureType() == CameraTextureType.CAMERA_TEXTURE_TYPE_BINARIZED)
            {
                TexToProcess = omniProCamDeviceManagerPtr.getBinarizedCameraImageTexturePtr().texture;
            }
            else if (omniProCamDeviceManagerPtr.getCameraTextureType() == CameraTextureType.CAMERA_TEXTURE_TYPE_SRC)
            {
                TexToProcess = omniProCamDeviceManagerPtr.getSrcCameraImageTexturePtr().texture;
            }


            Texture2D Tex2dImg = new Texture2D(TexToProcess.width, TexToProcess.height);
            Utils.textureToTexture2D(TexToProcess, Tex2dImg);

            //convert the tex2d to mat
            MatToProcess = new Mat(TexToProcess.height, TexToProcess.width, CvType.CV_8UC4, new Scalar(0, 0, 0, 255));
            Utils.texture2DToMat(Tex2dImg, MatToProcess);


            //flip the image for projection
            // -1 means both x and y
            //Core.flip(MatToProcess, MatToProcess, -1);

            //to gary image
            Imgproc.cvtColor(MatToProcess, MatToProcess, 6);
            Mat resultMat = new Mat();
            MatToProcess.copyTo(resultMat);

            //Process for marker detection
            if (isMarkerDetection)
            {
                resultMat = markerDetection.MarkerProcessing(MatToProcess);
            }

            if (isHandInteraction && !isMarkerDetection)
            {
                resultMat = handDetection.HandProcessing(MatToProcess, false);
            }
            else if (isMarkerDetection && isHandInteraction)
            {
                resultMat = handDetection.HandProcessing(MatToProcess, true, markerDetection.arGameObject);
            }
            //Process for  face detction (can't work in IR camera now)
            else if (isFaceDetection)
            {
                faceDetection.Run(MatToProcess);
            }
            else if (isFaceThreshold)
            {
                resultMat = faceThreshold.Processing(MatToProcess);
            }
            else if (isShade)
            {
                //press Q to catch the background frame
                resultMat = new Mat(resultMat.rows(), resultMat.cols(), CvType.CV_8UC1, new Scalar(0, 0, 0));
                if (Input.GetKey(KeyCode.Q))
                {
                    pre_Mat       = MatToProcess;
                    StartTouching = true;
                }
                if (StartTouching)
                {
                    resultMat = shadeTouch.TouchProcessing(MatToProcess, pre_Mat);
                }
            }

            // convert to texture and show
            Texture2D ResultTex = new Texture2D(resultMat.cols(), resultMat.rows(), TextureFormat.RGB24, false);
            Utils.matToTexture2D(resultMat, ResultTex);

            //show the image
            gameObject.GetComponent <Renderer>().material.mainTexture = ResultTex;
        }



        /*if use the noremal web camera*/
        else if (!UseIRCamera && isPlay)
        {
            MatToProcess = new Mat(webTex.height, webTex.width, CvType.CV_8UC4, new Scalar(0, 0, 0, 255));
            Utils.webCamTextureToMat(webTex, MatToProcess);

            if (isFaceDetection)
            {
                faceDetection.Run(MatToProcess);
            }

            Texture2D ResultTex = new Texture2D(MatToProcess.cols(), MatToProcess.rows(), TextureFormat.RGB24, false);
            Utils.matToTexture2D(MatToProcess, ResultTex);

            gameObject.GetComponent <Renderer>().material.mainTexture = ResultTex;
        }
    }