void DoProcess()
        {
            if (!(imgMat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("imgMat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_imgMat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat> (imgMat);

            if (!(color.Value is OpenCVForUnityPlayMakerActions.Scalar))
            {
                LogError("color is not initialized. Add Action \"newScalar\".");
                return;
            }
            OpenCVForUnity.CoreModule.Scalar wrapped_color = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Scalar, OpenCVForUnity.CoreModule.Scalar> (color);

            List <UnityEngine.Vector2> wrapped_points = new List <UnityEngine.Vector2> (points.Length);

            for (int i = 0; i < points.Length; i++)
            {
                wrapped_points.Add((Vector2)points.Get(i));
            }


            OpenCVForUnityUtils.DrawFaceLandmark(wrapped_imgMat, wrapped_points, wrapped_color, thickness.Value);
        }
        void DoProcess()
        {
            if (!(mat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("mat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_mat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat>(mat);

            Utils.webCamTextureToMat(webCamTexture.Value as WebCamTexture, wrapped_mat, flip.Value, flipCode.Value);
        }
        void DoProcess()
        {
            if (!(mat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("mat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_mat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat>(mat);

            MatUtils.copyToMat <int>(array.intValues, wrapped_mat);
        }
        void DoProcess()
        {
            if (!(mat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("mat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_mat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat>(mat);

            Utils.matToTexture2D(wrapped_mat, texture2D.Value as Texture2D, flip.Value, flipCode.Value, flipAfter.Value, updateMipmaps.Value, makeNoLongerReadable.Value);
        }
        void DoProcess()
        {
            if (!(mat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("mat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_mat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat>(mat);

            Utils.texture2DToMat(texture2D.Value as Texture2D, wrapped_mat);
        }
Example #6
0
        void DoProcess()
        {
            System.Int64[] wrapped_array = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.LongArray, System.Int64[]>(array);

            if (!(mat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("mat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_mat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat>(mat);

            MatUtils.copyToMat <long>(wrapped_array, wrapped_mat);
        }
Example #7
0
        void DoProcess()
        {
            if (!(imgMat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("imgMat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_imgMat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat> (imgMat);



            OpenCVForUnityUtils.DrawFaceRect(wrapped_imgMat, rect.Value, new OpenCVForUnity.CoreModule.Scalar((double)color_v0.Value, (double)color_v1.Value, (double)color_v2.Value, (double)color_v3.Value), thickness.Value);
        }
        void DoProcess()
        {
            if (!(mat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("mat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_mat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat>(mat);

            System.Double[] wrapped_array = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.DoubleArray, System.Double[]>(array);

            MatUtils.copyFromMat <double>(wrapped_mat, wrapped_array);
        }
    //turn an array of 3d vectors to a list of Mat
    public List <OpenCVForUnity.CoreModule.Mat> Arrayof3DVectorstoListofMat(Vector3[] arrayOf3DVectors)
    {
        List <OpenCVForUnity.CoreModule.Mat> matList = new List <OpenCVForUnity.CoreModule.Mat>();

        foreach (Vector3 _vec in arrayOf3DVectors)
        {
            float[] _screenPosArray = { _vec.x, _vec.y, _vec.z };
            OpenCVForUnity.CoreModule.Mat _screenMat = new OpenCVForUnity.CoreModule.Mat(1, 3, OpenCVForUnity.CoreModule.CvType.CV_64F);
            _screenMat.put(1, 3, _screenPosArray);

            matList.Add(_screenMat);
        }

        return(matList);
    }
        void DoProcess()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (!UpdateCache(go))
            {
                return;
            }

            OpenCVForUnity.CoreModule.Mat wrapped_originalMat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat>(originalMat);

            if (!(storeResult.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                storeResult.Value = new OpenCVForUnityPlayMakerActions.Mat();
            }
            ((OpenCVForUnityPlayMakerActions.Mat)storeResult.Value).wrappedObject = imageOptimizationHelper.GetDownScaleMat(wrapped_originalMat);
        }
Example #11
0
    public OpenCVForUnity.CoreModule.Mat GetMat(int x, int y, int width, int height)
    {
        if (mat == null || mat.getNativeObjAddr() == System.IntPtr.Zero)
        {
            return(null);
        }

        // Crop the image by using opencv
        var rect = new OpenCVForUnity.CoreModule.Rect(x, y, width, height);
        var dst  = new OpenCVForUnity.CoreModule.Mat(mat, rect);

        // Validate the mat object
        if (dst == null || dst.getNativeObjAddr() == System.IntPtr.Zero)
        {
            return(null);
        }

        return(dst);
    }
Example #12
0
        void DoProcess()
        {
            if (!(mat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("mat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_mat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat>(mat);

            int[] tmpArray = new int[array.Length];

            MatUtils.copyFromMat <int>(wrapped_mat, tmpArray);

            for (int i = 0; i < tmpArray.Length; i++)
            {
                array.Set(i, (float)tmpArray[i]);
            }
            array.SaveChanges();
        }
Example #13
0
        void DoProcess()
        {
            if (!(faceLandmarkDetector.Value is DlibFaceLandmarkDetectorPlayMakerActions.FaceLandmarkDetector))
            {
                LogError("faceLandmarkDetector is not initialized. Add Action \"newFaceLandmarkDetector\".");
                return;
            }
            DlibFaceLandmarkDetector.FaceLandmarkDetector wrapped_faceLandmarkDetector = DlibFaceLandmarkDetectorPlayMakerActionsUtils.GetWrappedObject <DlibFaceLandmarkDetectorPlayMakerActions.FaceLandmarkDetector, DlibFaceLandmarkDetector.FaceLandmarkDetector> (faceLandmarkDetector);

            if (!(imgMat.Value is OpenCVForUnityPlayMakerActions.Mat))
            {
                LogError("imgMat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_imgMat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject <OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat> (imgMat);


            OpenCVForUnityUtils.SetImage(wrapped_faceLandmarkDetector, wrapped_imgMat);
        }
Example #14
0
    /// <summary>
    /// Raises the webcam texture initialized event.
    /// </summary>
    private void OnInited()
    {
        if (colors == null || colors.Length != webCamTexture.width * webCamTexture.height)
        {
            colors = new Color32[webCamTexture.width * webCamTexture.height];
        }

        texture = new Texture2D(webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false);
        mat     = new OpenCVForUnity.CoreModule.Mat(webCamTexture.height, webCamTexture.width, OpenCVForUnity.CoreModule.CvType.CV_8UC3);
        //rawImage.texture = texture;

        gameObject.transform.localScale = new Vector3(texture.width, texture.height, 1);
        Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);

        float width  = texture.width;
        float height = texture.height;

        float widthScale  = (float)Screen.width / width;
        float heightScale = (float)Screen.height / height;
    }
        void DoProcess ()
        {


            if (!(imgMat.Value is OpenCVForUnityPlayMakerActions.Mat)) {
                LogError ("imgMat is not initialized. Add Action \"newMat\".");
                return;
            }
            OpenCVForUnity.CoreModule.Mat wrapped_imgMat = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject<OpenCVForUnityPlayMakerActions.Mat, OpenCVForUnity.CoreModule.Mat> (imgMat);

            if (!(color.Value is OpenCVForUnityPlayMakerActions.Scalar)) {
                LogError ("color is not initialized. Add Action \"newScalar\".");
                return;
            }
            OpenCVForUnity.CoreModule.Scalar wrapped_color = OpenCVForUnityPlayMakerActionsUtils.GetWrappedObject<OpenCVForUnityPlayMakerActions.Scalar, OpenCVForUnity.CoreModule.Scalar> (color);


            OpenCVForUnityUtils.DrawFaceRect (wrapped_imgMat, rect.Value, wrapped_color, thickness.Value);

        }
Example #16
0
    public OpenCVForUnity.CoreModule.Mat GetMat()
    {
        // Get the full image
        var colors  = GetColors();
        var texture = new Texture2D(webCamTexture.width, webCamTexture.height);

        texture.SetPixels32(colors);

        // Convert the texture2d to mat format
        var dst = new OpenCVForUnity.CoreModule.Mat(webCamTexture.height, webCamTexture.width, OpenCVForUnity.CoreModule.CvType.CV_8UC3);

        OpenCVForUnity.UnityUtils.Utils.texture2DToMat(texture, dst);

        // Validate the mat object
        if (dst == null || dst.getNativeObjAddr() == System.IntPtr.Zero)
        {
            return(null);
        }

        return(dst);
    }
    // Start is called before the first frame update
    void Start()
    {
        //List< Mat >   objectPoints
        List <OpenCVForUnity.CoreModule.Mat> screenMatList = Arrayof3DVectorstoListofMat(screenPositions);

        //List<Mat> imagePoints
        List <OpenCVForUnity.CoreModule.Mat> handMatList = Arrayof3DVectorstoListofMat(handPositions);

        //TODO: Size imageSize
        OpenCVForUnity.CoreModule.Size imageSize = new OpenCVForUnity.CoreModule.Size(Screen.width, Screen.height);

        //TODO: Mat cameraMatrix
        OpenCVForUnity.CoreModule.Mat cameraMatrix = new OpenCVForUnity.CoreModule.Mat(3, 3, OpenCVForUnity.CoreModule.CvType.CV_64F);

        //TODO: Mat distCoeffs

        //TODO: List<Mat> rvecs

        //TODO: int flags

        //if look at docs (url above class decleration) the calibrateCamera function needs all the arguments specified above.
        OpenCVForUnity.Calib3dModule.Calib3d.calibrateCamera();
    }