Ejemplo n.º 1
0
        public static Mat Correct(Mat img, LensParams lensParams)
        {
            Mat output = img.Clone();

            Fisheye.UndistorImage(img, output, lensParams.GetMatrixK(), lensParams.GetMatrixD());
            return(output);
        }
Ejemplo n.º 2
0
        IEnumerator SetCamConfig(int iCamera, float fov, float offset_x, float offset_y, float offset_z, float rot_x,
                                 int img_w, int img_h, int img_d, string img_enc, float fish_eye_x, float fish_eye_y)
        {
            CameraSensor cam = null;

            if (iCamera == 0)
            {
                cam = camSensor;
            }
            else
            {
                cam = camSensorB;

                if (cam != null && !cam.gameObject.activeInHierarchy)
                {
                    cam.gameObject.SetActive(true);
                }
            }

            if (cam)
            {
                cam.SetConfig(fov, offset_x, offset_y, offset_z, rot_x, img_w, img_h, img_d, img_enc);

                Fisheye fe = cam.gameObject.GetComponent <Fisheye>();

                if (fe != null && (fish_eye_x != 0.0f || fish_eye_y != 0.0f))
                {
                    fe.enabled   = true;
                    fe.strengthX = fish_eye_x;
                    fe.strengthY = fish_eye_y;
                }
            }

            yield return(null);
        }
Ejemplo n.º 3
0
        private static double Validate(VectorOfVectorOfPoint3D32F processedObjectPoints, VectorOfVectorOfPointF processedImagePoints, Mat cameraMatrix, Mat distCoeffs, VectorOfPoint3D32F rvecs, VectorOfPoint3D32F tvecs, bool fisheye)
        {
            double error       = 0;
            int    totalpoints = 0;

            if (fisheye)
            {
                for (int i = 0; i < processedObjectPoints.Size; i++)
                {
                    VectorOfPoint3D32F objectFramePoints = processedObjectPoints[i];
                    VectorOfPointF     imageFramePoints  = processedImagePoints[i];
                    RotationVector3D   tvec = new RotationVector3D(new double[] { tvecs[i].X, tvecs[i].Y, tvecs[i].Z });
                    RotationVector3D   rvec = new RotationVector3D(new double[] { rvecs[i].X, rvecs[i].Y, rvecs[i].Z });

                    VectorOfPointF newImageFramePoints = new VectorOfPointF();

                    Fisheye.ProjectPoints(objectFramePoints, newImageFramePoints, rvec, tvec, cameraMatrix, distCoeffs);

                    for (int j = 0; j < newImageFramePoints.Size; j++)
                    {
                        PointF x1 = newImageFramePoints[j];
                        PointF x2 = imageFramePoints[j];
                        totalpoints++;
                        error += Math.Pow(x1.X - x2.X, 2) + Math.Pow(x1.Y - x2.Y, 2);
                    }
                }
            }
            return(Math.Sqrt(error / totalpoints));
        }
Ejemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     motionBlurFilter    = Camera.main.GetComponent <MotionBlur>();
     fisheye             = Camera.main.GetComponent <Fisheye>();
     depthOfField        = Camera.main.GetComponent <DepthOfField>();
     spaceshipController = GetComponent <SpaceshipController>();
 }
Ejemplo n.º 5
0
 void Start()
 {
     objetoSomSub = new GameObject();
     objetoSomSub.AddComponent(typeof(AudioSource));
     objetoSomSub.GetComponent <AudioSource> ().loop = true;
     objetoSomSub.transform.localPosition            = new Vector3(0, 0, 0);
     objetoSomSub.GetComponent <AudioSource> ().clip = somSubmerso;
     objetoSomSub.transform.parent = transform;
     objetoSomSub.SetActive(false);
     //
     _fisheye = GetComponent <Fisheye> ();
     _blur    = GetComponent <Blur> ();
     _edge    = GetComponent <EdgeDetection> ();
     _vortex  = GetComponent <Vortex> ();
     //
     GetComponent <SphereCollider> ().radius    = 0.005f;
     GetComponent <SphereCollider> ().isTrigger = false;
     GetComponent <Rigidbody> ().isKinematic    = true;
     GetComponent <Camera> ().nearClipPlane     = 0.01f;
     //
     _blur.iterations = 5 - DistanciaDeVisib;
     _blur.blurSpread = 1 - (Visibilidade / 10);
     //
     _vortex.radius = new Vector2(1, 1);
     _vortex.center = new Vector2(0.5f, 0.5f);
     //
     _edge.mode             = EdgeDetection.EdgeDetectMode.TriangleLuminance;
     _edge.lumThreshold     = 0;
     _edge.sampleDist       = 0;
     _edge.edgesOnly        = intensidadeCor;
     _edge.edgesOnlyBgColor = corAgua;
     //
     _blur.enabled    = false;
     _fisheye.enabled = false;
     _edge.enabled    = false;
     _vortex.enabled  = false;
     //
     planoGotas = GameObject.CreatePrimitive(PrimitiveType.Plane);
     Destroy(planoGotas.GetComponent <MeshCollider> ());
     planoGotas.transform.localScale       = new Vector3(0.02f, 0.02f, 0.02f);
     planoGotas.transform.parent           = transform;
     planoGotas.transform.localPosition    = new Vector3(0, 0, 0.05f);
     planoGotas.transform.localEulerAngles = new Vector3(90, 180, 0);
     planoGotas.GetComponent <Renderer>().material.shader = Shader.Find("FX/Glass/Stained BumpDistort");
     planoGotas.GetComponent <Renderer> ().material.SetTexture("_BumpMap", TexturaPingos);
     planoGotas.GetComponent <Renderer> ().material.SetFloat("_BumpAmt", 0);
     //
     if (GetComponent <SunShafts> () != null)
     {
         temSunShafts  = true;
         _sunShafts    = GetComponent <SunShafts> ();
         intSolInicial = _sunShafts.sunShaftIntensity;
     }
     else
     {
         temSunShafts = false;
     }
     //
     _audSourc = GetComponent <AudioSource> ();
 }
Ejemplo n.º 6
0
    void Awake()
    {
        Instance = this;

        _fisheye = playerCamera.gameObject.GetComponent<Fisheye>();
        _colorSaturation = playerCamera.gameObject.GetComponent<ColorCorrectionCurves>();
        _blur = playerCamera.gameObject.GetComponent<BlurOptimized>();
    }
Ejemplo n.º 7
0
    // Use this for initialization
    void Start()
    {
        _fisheye = this.GetComponentInChildren <Fisheye>();

        _life          = this.GetComponent <BarbieLife>();
        lastlifePoint  = _life.life;
        maxlifepoint   = _life.life;
        _cadreVieImage = GameManager.Instance.CadreVie.GetComponent <Image>();
    }
Ejemplo n.º 8
0
 // Use this for initialization
 void Start()
 {
     p = player.GetComponent<Player>();
     fish = cam.GetComponent<Fisheye>();
     bloom = cam.GetComponent<Bloom>();
     fish.strengthX = fish.strengthY = currentFishEyeStrength = startingFishEyeStrength;
     playerLight.light.intensity = 0f;
     playerLight.light.range = 10f;
     //		player.light.intensity = 0f;
 }
        static FisheyeDef()
        {
            if (fisheyeEffect == null)
            {
                fisheyeEffect = Util.GetComponentVar <Fisheye, FisheyeDef>(fisheyeEffect);
            }

            strengthX = 0.05f;
            strengthY = 0.05f;
        }
Ejemplo n.º 10
0
        public static void Calibrate(string[] imgFiles, out LensParams lensParams)
        {
            Size patternSize = new Size(CHESS_PATTERN_WIDTH, CHESS_PATTERN_HEIGHT);

            VectorOfVectorOfPoint3D32F objPoints   = new VectorOfVectorOfPoint3D32F();
            VectorOfVectorOfPointF     imagePoints = new VectorOfVectorOfPointF();

            Size imageSize = Size.Empty;

            foreach (string file in imgFiles)
            {
                Mat img = CvInvoke.Imread(file, ImreadModes.Grayscale);
                if (imageSize == Size.Empty)
                {
                    imageSize = new Size(img.Width, img.Height);
                }
                //CvInvoke.Imshow("input", img);
                VectorOfPointF corners = new VectorOfPointF(patternSize.Width * patternSize.Height);
                bool           find    = CvInvoke.FindChessboardCorners(img, patternSize, corners);
                if (find)
                {
                    MCvPoint3D32f[] points    = new MCvPoint3D32f[patternSize.Width * patternSize.Height];
                    int             loopIndex = 0;
                    for (int i = 0; i < patternSize.Height; i++)
                    {
                        for (int j = 0; j < patternSize.Width; j++)
                        {
                            points[loopIndex++] = new MCvPoint3D32f(j, i, 0);
                        }
                    }
                    objPoints.Push(new VectorOfPoint3D32F(points));
                    imagePoints.Push(corners);
                }
            }

            Matrix <double> K           = new Matrix <double>(3, 3);
            Matrix <double> D           = new Matrix <double>(4, 1);
            Mat             rotation    = new Mat();
            Mat             translation = new Mat();

            Fisheye.Calibrate(objPoints,
                              imagePoints,
                              imageSize,
                              K,
                              D,
                              rotation,
                              translation,
                              Fisheye.CalibrationFlag.CheckCond,
                              new MCvTermCriteria(30, 0.1)
                              );
            lensParams = new LensParams(K, D);
        }
        private Task DoUndistortImage(object o)
        {
            return(Task.Factory.StartNew(async() =>
            {
                System.Windows.Forms.OpenFileDialog openFileDialog = null;
                System.Windows.Forms.SaveFileDialog saveFileDialog = null;
                bool open = false;
                bool save = false;

                CameraViewModel cvm = null;

                Parent.SyncContext.Send(c =>
                {
                    cvm = Parent.CameraViewModel;
                    openFileDialog = new System.Windows.Forms.OpenFileDialog();
                    openFileDialog.Filter = "Image (*.png) | *.png";
                    open = openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK;

                    saveFileDialog = new System.Windows.Forms.SaveFileDialog();
                    saveFileDialog.Filter = "Image (*.png) | *.png";
                    save = saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                }, null);

                if (open && save)
                {
                    MetroDialogSettings settings = new MetroDialogSettings()
                    {
                        AnimateShow = false,
                        AnimateHide = false
                    };

                    var controller = await Parent.DialogCoordinator.ShowProgressAsync(Parent, "Please wait...", "Export undistort image!", settings: Parent.MetroDialogSettings);

                    controller.SetCancelable(false);

                    Mat rawImage = CvInvoke.Imread(openFileDialog.FileName, Emgu.CV.CvEnum.ImreadModes.Grayscale);
                    Mat rawImageUndist = new Mat();

                    Mat map1 = new Mat();
                    Mat map2 = new Mat();

                    Fisheye.InitUndistorRectifyMap(cvm.OrginalCameraMatrix, cvm.DistortionCoefficients, Mat.Eye(3, 3, DepthType.Cv64F, 1), cvm.CenteredCameraMatrix, new System.Drawing.Size(512, 512), DepthType.Cv32F, map1, map2);

                    CvInvoke.Remap(rawImage, rawImageUndist, map1, map2, Inter.Linear, BorderType.Constant);

                    CvInvoke.Imwrite(saveFileDialog.FileName, rawImageUndist);

                    await controller.CloseAsync();
                }
            }));
        }
Ejemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        fpc  = GameObject.FindObjectOfType <FirstPersonController>();
        blur = GetComponentInChildren <BlurOptimized> ();
//		motionBlur = GetComponentInChildren<MotionBlur> ();
        sources = GameObject.FindGameObjectWithTag("GameController").GetComponents <AudioSource>();
        dog     = GameObject.FindGameObjectWithTag("dog");
        bark    = dog.GetComponent <AudioSource> ();
        left    = GameObject.FindGameObjectWithTag("left").GetComponent <CanvasRenderer> ();
        right   = GameObject.FindGameObjectWithTag("right").GetComponent <CanvasRenderer>();
        cam     = GetComponentInChildren <Camera> ();
        fish    = GetComponentInChildren <Fisheye> ();

        left.SetAlpha(0f);
        right.SetAlpha(0f);
    }
Ejemplo n.º 13
0
    // Use this for initialization
    void Start()
    {
        CameraEventManager.onEvent += Effect;

        CameraEventManager.ActualizeFOV += FOVEffect;

        m_Camera = GetComponent <Camera>();

        fisheye = GetComponent <Fisheye>();



        fisheye.enabled   = false;
        fisheye.strengthX = 0;
        fisheye.strengthY = 0;
    }
Ejemplo n.º 14
0
        public static double ValidateCharuco(int squaresX, int squaresY, float squareLength, float markerLength, PredefinedDictionaryName dictionary, Size imageSize, VectorOfInt charucoIds, VectorOfPointF charucoCorners, VectorOfInt markerCounterPerFrame, bool fisheye, Func <byte[], byte[]> GetRemoteChessboardCorner, Mat cameraMatrix, Mat distCoeffs)
        {
            VectorOfVectorOfPoint3D32F processedObjectPoints = new VectorOfVectorOfPoint3D32F();
            VectorOfVectorOfPointF     processedImagePoints  = new VectorOfVectorOfPointF();
            VectorOfPoint3D32F         rvecs = new VectorOfPoint3D32F();
            VectorOfPoint3D32F         tvecs = new VectorOfPoint3D32F();

            int k = 0;

            for (int i = 0; i < markerCounterPerFrame.Size; i++)
            {
                int                nMarkersInThisFrame       = markerCounterPerFrame[i];
                VectorOfPointF     currentImgPoints          = new VectorOfPointF();
                VectorOfPointF     currentImgPointsUndistort = new VectorOfPointF();
                VectorOfInt        currentIds       = new VectorOfInt();
                VectorOfPoint3D32F currentObjPoints = new VectorOfPoint3D32F();
                Mat                tvec             = new Mat();
                Mat                rvec             = new Mat();

                for (int j = 0; j < nMarkersInThisFrame; j++)
                {
                    currentImgPoints.Push(new PointF[] { charucoCorners[k] });
                    currentIds.Push(new int[] { charucoIds[k] });
                    currentObjPoints.Push(new MCvPoint3D32f[] { GetChessboardCorner(squaresX, squaresY, squareLength, markerLength, charucoIds[k], dictionary, GetRemoteChessboardCorner) });
                    k++;
                }

                Mat distCoeffsNew = new Mat(1, 4, DepthType.Cv64F, 1);
                distCoeffsNew.SetValue(0, 0, 0);
                distCoeffsNew.SetValue(0, 1, 0);
                distCoeffsNew.SetValue(0, 2, 0);
                distCoeffsNew.SetValue(0, 3, 0);

                Fisheye.UndistorPoints(currentImgPoints, currentImgPointsUndistort, cameraMatrix, distCoeffs, Mat.Eye(3, 3, DepthType.Cv64F, 1), Mat.Eye(3, 3, DepthType.Cv64F, 1));
                if (ArucoInvoke.EstimatePoseCharucoBoard(currentImgPointsUndistort, currentIds, CreateBoard(squaresX, squaresY, squareLength, markerLength, new Dictionary(dictionary)), Mat.Eye(3, 3, DepthType.Cv64F, 1), distCoeffsNew, rvec, tvec))
                {
                    rvecs.Push(new MCvPoint3D32f[] { new MCvPoint3D32f((float)rvec.GetValue(0, 0), (float)rvec.GetValue(1, 0), (float)rvec.GetValue(2, 0)) });
                    tvecs.Push(new MCvPoint3D32f[] { new MCvPoint3D32f((float)tvec.GetValue(0, 0), (float)tvec.GetValue(1, 0), (float)tvec.GetValue(2, 0)) });

                    processedImagePoints.Push(currentImgPoints);
                    processedObjectPoints.Push(currentObjPoints);
                }
            }

            return(Validate(processedObjectPoints, processedImagePoints, cameraMatrix, distCoeffs, rvecs, tvecs, fisheye));
        }
Ejemplo n.º 15
0
        public static (Mat cameraMatrix, Mat distCoeffs, double rms) CalibrateCharuco(int squaresX, int squaresY, float squareLength, float markerLength, PredefinedDictionaryName dictionary, Size imageSize, VectorOfInt charucoIds, VectorOfPointF charucoCorners, VectorOfInt markerCounterPerFrame, bool fisheye, Func <byte[], byte[]> GetRemoteChessboardCorner)
        {
            Mat    cameraMatrix = new Mat(3, 3, Emgu.CV.CvEnum.DepthType.Cv64F, 1);
            Mat    distCoeffs   = new Mat(1, 4, Emgu.CV.CvEnum.DepthType.Cv64F, 1);
            double rms          = 0.0;

            VectorOfVectorOfPoint3D32F processedObjectPoints = new VectorOfVectorOfPoint3D32F();
            VectorOfVectorOfPointF     processedImagePoints  = new VectorOfVectorOfPointF();

            int k = 0;

            for (int i = 0; i < markerCounterPerFrame.Size; i++)
            {
                int                nMarkersInThisFrame = markerCounterPerFrame[i];
                VectorOfPointF     currentImgPoints    = new VectorOfPointF();
                VectorOfPoint3D32F currentObjPoints    = new VectorOfPoint3D32F();

                for (int j = 0; j < nMarkersInThisFrame; j++)
                {
                    currentImgPoints.Push(new PointF[] { charucoCorners[k] });
                    currentObjPoints.Push(new MCvPoint3D32f[] { GetChessboardCorner(squaresX, squaresY, squareLength, markerLength, charucoIds[k], dictionary, GetRemoteChessboardCorner) });
                    k++;
                }

                processedImagePoints.Push(currentImgPoints);
                processedObjectPoints.Push(currentObjPoints);
            }

            VectorOfPoint3D32F rvecs = new VectorOfPoint3D32F();
            VectorOfPoint3D32F tvecs = new VectorOfPoint3D32F();

            if (fisheye)
            {
                Fisheye.Calibrate(processedObjectPoints, processedImagePoints, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs, Fisheye.CalibrationFlag.FixSkew | Fisheye.CalibrationFlag.RecomputeExtrinsic, new MCvTermCriteria(400, double.Epsilon));
            }
            else
            {
                CvInvoke.CalibrateCamera(processedObjectPoints, processedImagePoints, imageSize, cameraMatrix, distCoeffs, new Mat(), new Mat(), CalibType.FixK3, new MCvTermCriteria(30, 1e-4));
            }

            rms = Validate(processedObjectPoints, processedImagePoints, cameraMatrix, distCoeffs, rvecs, tvecs, fisheye);

            return(cameraMatrix, distCoeffs, rms);
        }
Ejemplo n.º 16
0
    // -------------------------------------<<<- <<<- <<<- FUNCTIONEZ EL LOCOS

    void Start()
    {
        randomRange1 = Random.Range(-5, 5);
        randomRange2 = Random.Range(0, 0.2f);
        randomRange3 = Random.Range(-0.4f, 0.4f);
        randomRange4 = Random.Range(-5, 5);
        randomRange5 = Random.Range(-0.4f, 0.4f);
        randomRange6 = Random.Range(-0.1f, 0.1f);

        vortexEffect  = GetComponent <Vortex>();
        fisheyeEffect = GetComponent <Fisheye>();
        dof           = GetComponent <DepthOfField>();

        dofFocalLenght = dof.focalLength;
        dofFocalSize   = dof.focalSize;
        dofAperture    = dof.aperture;

        bloom = GetComponent <Bloom>();
        bloom.bloomIntensity = 0.09f;;
        bloom.bloomThreshold = -0.06f;;
    }
Ejemplo n.º 17
0
        IEnumerator SetCamConfig(float fov, float offset_x, float offset_y, float offset_z, float rot_x,
                                 int img_w, int img_h, int img_d, string img_enc, float fish_eye_x, float fish_eye_y)
        {
            CameraSensor camSensor = carObj.transform.GetComponentInChildren <CameraSensor>();

            if (camSensor)
            {
                camSensor.SetConfig(fov, offset_x, offset_y, offset_z, rot_x, img_w, img_h, img_d, img_enc);

                Fisheye fe = camSensor.gameObject.GetComponent <Fisheye>();

                if (fe != null && (fish_eye_x != 0.0f || fish_eye_y != 0.0f))
                {
                    fe.enabled   = true;
                    fe.strengthX = fish_eye_x;
                    fe.strengthY = fish_eye_y;
                }
            }

            yield return(null);
        }
Ejemplo n.º 18
0
    void Start()
    {
        camera = GetComponent<Camera>();
        darkness = GetComponent<VignetteAndChromaticAberration>();
        fisheye = GetComponent<Fisheye>();
        playerCol = player.GetComponent<BoxCollider>();
        playerRig = player.GetComponent<Rigidbody>();
        initialPosition = camera.transform.position;        // Position of camera normally
        playerRigid = player.GetComponent<Rigidbody>();
        playerCollider = player.GetComponent<BoxCollider>();

        // Setting of camera
        camera.fieldOfView = glitchZoom;
        camera.transform.position = new Vector3(cameraInitPoint.position.x, cameraInitPoint.position.y, camera.transform.position.z);
        
        // Adjusting screen
        float targetaspect = 16.0f / 9.0f;
        float windowaspect = (float)Screen.width / (float)Screen.height;
        float scaleheight = windowaspect / targetaspect;
        Rect rect = camera.rect;
        
        if (scaleheight < 1.0f)
        {

            rect.width = 1.0f;
            rect.height = scaleheight;
            rect.x = 0.0f;
            rect.y = (1.0f - scaleheight)/2.0f;

            camera.rect = rect;

            // Adjusting UI
            height = Screen.currentResolution.height;
            pix = camera.pixelHeight;
            newYPosition = ((pix - height) / 2.0f);
            topLeft.anchoredPosition = new Vector2(topLeft.anchoredPosition.x, newYPosition);
            bossLives.anchoredPosition = new Vector2(bossLives.anchoredPosition.x, newYPosition);
        }
        
    }
Ejemplo n.º 19
0
        private void UpdateLastKeyFrame(KeyFrame keyFrame, Mat rawImage, double minDepth, double maxDepth)
        {
            Mat rawImageColor       = new Mat();
            Mat rawImageColorUndist = new Mat();

            CvInvoke.CvtColor(rawImage, rawImageColor, ColorConversion.Gray2Bgr);

            Mat map1 = new Mat();
            Mat map2 = new Mat();

            Fisheye.InitUndistorRectifyMap(_OrginalCameraMatrix, _DistortionCoefficients, Mat.Eye(3, 3, DepthType.Cv64F, 1), _CenteredCameraMatrix, new System.Drawing.Size(512, 512), DepthType.Cv32F, map1, map2);

            CvInvoke.Remap(rawImageColor, rawImageColorUndist, map1, map2, Inter.Linear, BorderType.Constant);

            Mat hsvImage = new Mat();

            CvInvoke.CvtColor(rawImageColorUndist, hsvImage, ColorConversion.Bgr2Hsv);

            Image <Emgu.CV.Structure.Hsv, byte> rawImageColorUndistImage = hsvImage.ToImage <Emgu.CV.Structure.Hsv, byte>();

            byte[,,] data = rawImageColorUndistImage.Data;

            foreach (Point point in keyFrame.Points)
            {
                int u = (int)Math.Round(point.U);
                int v = (int)Math.Round(point.V);

                for (int i = -2; i <= +2; i++)
                {
                    for (int j = -2; j <= +2; j++)
                    {
                        byte h = (byte)Math.Round(((1.0 / point.InverseDepth - minDepth) < 0 ? 0 : (1.0 / point.InverseDepth - minDepth)) * 180 / (maxDepth - minDepth));
                        data[v + i, u + j, 0] = h;
                        data[v + i, u + j, 1] = (byte)Math.Round(255 / 100.0 * HSV_SATURATION_PERCENT);
                        data[v + i, u + j, 2] = (byte)Math.Round(255 / 100.0 * HSV_VALUE_PERCENT);
                    }
                }
            }
            CvInvoke.CvtColor(rawImageColorUndistImage.Mat, _LastKeyFrame, ColorConversion.Hsv2Bgr);
        }
Ejemplo n.º 20
0
    // Use this for initialization
    void Start()
    {
        if (EmptyBarTexture == null)
        {
            EmptyBarTexture = new Texture2D(1, 1);
        }
        if (FullBarTexture == null)
        {
            FullBarTexture = new Texture2D(1, 1);
        }


        fadeTexture = new Texture2D(1, 1);
        rect        = new Rect(0, 0, Screen.width, Screen.height);
        //Swapping start and end values if they are plotted in incorectly
        if (BlurEffectStart < BlurEffectEnd || EyeEffectStart < EyeEffectEnd)
        {
            float temp = BlurEffectStart;
            BlurEffectStart = BlurEffectEnd;
            BlurEffectEnd   = temp;

            temp            = EyeEffectStart;
            BlurEffectStart = EyeEffectEnd;
            EyeEffectEnd    = temp;

            Debug.LogError("Effect start hunger lower than end hunger, swapping values");
        }

        //Assigning variables to scripts in the scene
        player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();
        hunger = player.hunger;
        eye    = Camera.main.GetComponent <Fisheye>();
        blur   = Camera.main.GetComponent <BlurOptimized>();

        player.hunger    = MaxHunger;
        player.MaxHunger = MaxHunger;
        //initialising values
        ResetValues();
    }
Ejemplo n.º 21
0
    void Start()
    {
        camera          = GetComponent <Camera>();
        darkness        = GetComponent <VignetteAndChromaticAberration>();
        fisheye         = GetComponent <Fisheye>();
        playerCol       = player.GetComponent <BoxCollider>();
        playerRig       = player.GetComponent <Rigidbody>();
        initialPosition = camera.transform.position;        // Position of camera normally
        playerRigid     = player.GetComponent <Rigidbody>();
        playerCollider  = player.GetComponent <BoxCollider>();

        // Setting of camera
        camera.fieldOfView        = glitchZoom;
        camera.transform.position = new Vector3(cameraInitPoint.position.x, cameraInitPoint.position.y, camera.transform.position.z);

        // Adjusting screen
        float targetaspect = 16.0f / 9.0f;
        float windowaspect = (float)Screen.width / (float)Screen.height;
        float scaleheight  = windowaspect / targetaspect;
        Rect  rect         = camera.rect;

        if (scaleheight < 1.0f)
        {
            rect.width  = 1.0f;
            rect.height = scaleheight;
            rect.x      = 0.0f;
            rect.y      = (1.0f - scaleheight) / 2.0f;

            camera.rect = rect;

            // Adjusting UI
            height                     = Screen.currentResolution.height;
            pix                        = camera.pixelHeight;
            newYPosition               = ((pix - height) / 2.0f);
            topLeft.anchoredPosition   = new Vector2(topLeft.anchoredPosition.x, newYPosition);
            bossLives.anchoredPosition = new Vector2(bossLives.anchoredPosition.x, newYPosition);
        }
    }
Ejemplo n.º 22
0
    void Start()
    {
        motionBlur = Camera.main.GetComponent<MotionBlur>();
        twirl = Camera.main.GetComponent<Twirl>();
        fisheye = Camera.main.GetComponent<Fisheye>();
        vignette = Camera.main.GetComponent<VignetteAndChromaticAberration>();
        noise = Camera.main.GetComponent<NoiseAndGrain>();

        motionBlur.enabled = false;
        twirl.enabled = false;
        fisheye.enabled = false;
        vignette.enabled = false;
        noise.enabled = false;
    }
Ejemplo n.º 23
0
        /// <summary>
        /// Se realiza:
        /// <para>1. Se posiciona la marca de agua de acuerdo a los <see cref="TissotIndicatrix"/> (Top, Bottom y del 1 - 8)</para>
        /// <para>2. Se realiza la deformación <see cref="Fisheye.Convert(FisheyeBitmap)"/></para>
        /// <para>3. Se realiza la deformación <see cref="Fisheye.ToLandscape(FisheyeBitmap)"/></para>
        /// <para>4. Se posiciona la marca de agua de acuerdo a los <see cref="TissotIndicatrix"/> de la posición del centro (9 - 12)</para>
        /// </summary>
        public void Prepare()
        {
            int            size = 0;
            AbstractBitmap img  = null;

            foreach (var indicatrix in _indicatrixes.Where(i => i.Position != Position.Center))
            {
                // Se conserva la relacion aspecto de acuerdo al ancho de la imagen

                if (_imageWatermark.Width > _imageWatermark.Height)
                {
                    size = (indicatrix.MaxWidth * _imageWatermark.Height) / _imageWatermark.Width;

                    img = Resize.Apply(_imageWatermark, indicatrix.MaxWidth, size);
                }
                else
                {
                    size = (indicatrix.MaxHeight * _imageWatermark.Width) / _imageWatermark.Height;

                    img = Resize.Apply(_imageWatermark, size, indicatrix.MaxHeight);
                }

                img = Rotate.Apply(img, indicatrix.Angle);

                var posX = indicatrix.X - (img.Width / 2);
                var posY = indicatrix.Y - (img.Height / 2);

                if (indicatrix.Position == Position.Top)
                {
                    this._topFisheye.InsertImageUnmanaged(img, posX, posY);
                }
                else
                {
                    img._image.RotateFlip(RotateFlipType.RotateNoneFlipXY);

                    this._bottomFisheye.InsertImageUnmanaged(img, posX, posY);
                }
            }

            // Se realiza la deformación fisheye

            var feTop    = Fisheye.Convert(this._topFisheye);
            var feBottom = Fisheye.Convert(this._bottomFisheye);

            // Se deforman los fisheye a landscape

            feBottom = Fisheye.ToLandscape(feBottom);

            feTop = Fisheye.ToLandscape(feTop);
            feTop._image.RotateFlip(RotateFlipType.RotateNoneFlipXY);

            // Se insertan en el bitmap "watermak"

            _waterMark.InsertImageUnmanaged(feTop, 0, 0);
            _waterMark.InsertImageUnmanaged(feBottom, 0, feBottom.Height);

            // Se insertan aquellos indicatrix que pertenezcan al centro de la imagen

            foreach (var indicatrix in _indicatrixes.Where(i => i.Position == Position.Center))
            {
                if (_imageWatermark.Width > _imageWatermark.Height)
                {
                    size = (indicatrix.MaxWidth * _imageWatermark.Height) / _imageWatermark.Width;

                    img = Resize.Apply(_imageWatermark, indicatrix.MaxWidth, size) as WatermarkBitmap;
                }
                else
                {
                    size = (indicatrix.MaxHeight * _imageWatermark.Width) / _imageWatermark.Height;

                    img = Resize.Apply(_imageWatermark, size, indicatrix.MaxHeight) as WatermarkBitmap;
                }

                _waterMark.InsertImageUnmanaged(img, indicatrix.X - img.Width / 2, indicatrix.Y - img.Height / 2);
            }

            //_waterMark.Save(@"C:\Users\Euler\Pictures\WMpreared2.png", ImageFormat.Png);
        }
 public static void InitMemberByInstance(Fisheye fish)
 {
     strengthX = fish.strengthX;
     strengthY = fish.strengthY;
 }
Ejemplo n.º 25
0
    // Use this for initialization
    void Start()
    {
        manager = GameObject.FindWithTag("GameController");
        if (numberOfCameras > 3)
        {
            cameras = GameObject.FindGameObjectsWithTag("MainCamera");
        }
        else
        {
            cameras = new GameObject[numberOfCameras];

            if (numberOfCameras == 3)
            {
                cameras[0] = startCamera;
                cameras[1] = secondCamera;
                cameras[2] = lastCamera;
            }
            else if (numberOfCameras == 1)
            {
                cameras[0] = startCamera;
            }

            Grays  = new List <Grayscale>();
            Sepias = new List <SepiaTone>();
            Blooms = new List <Bloom>();
            Fogs   = new List <GlobalFog>();
            Antis  = new List <Antialiasing>();
            DOFs   = new List <DepthOfField>();
            Fishes = new List <Fisheye>();
            Shafts = new List <SunShafts>();

            foreach (var item in cameras)
            {
                item.AddComponent <Grayscale>();

                Grayscale gs = item.GetComponent <Grayscale>();

                Grayscale mgs = manager.GetComponent <Grayscale>();

                gs.shader     = mgs.shader;
                gs.rampOffset = mgs.rampOffset;

                Grays.Add(gs);

                item.AddComponent <SepiaTone>();

                SepiaTone st = item.GetComponent <SepiaTone>();
                st.shader = manager.GetComponent <SepiaTone>().shader;

                Sepias.Add(st);

                item.AddComponent <Bloom>();

                //print(name + " " + item.name);

                Bloom bm = item.GetComponent <Bloom>();

                Bloom mbm = manager.GetComponent <Bloom>();

                bm.blurAndFlaresShader    = mbm.blurAndFlaresShader;
                bm.brightPassFilterShader = mbm.brightPassFilterShader;
                bm.lensFlareShader        = mbm.lensFlareShader;
                bm.screenBlendShader      = mbm.screenBlendShader;

                bm.bloomThreshold = mbm.bloomThreshold;
                bm.bloomIntensity = mbm.bloomIntensity;

                Blooms.Add(bm);

                item.AddComponent <GlobalFog>();

                GlobalFog gf = item.GetComponent <GlobalFog>();

                GlobalFog mgf = manager.GetComponent <GlobalFog>();

                gf.fogShader        = mgf.fogShader;
                gf.excludeFarPixels = mgf.excludeFarPixels;
                gf.height           = mgf.height;
                gf.heightDensity    = mgf.heightDensity;
                gf.startDistance    = mgf.startDistance;

                Fogs.Add(gf);

                item.AddComponent <Antialiasing>();

                Antialiasing ai = item.GetComponent <Antialiasing>();

                Antialiasing mai = manager.GetComponent <Antialiasing>();

                ai.shaderFXAAIII     = mai.shaderFXAAIII;
                ai.ssaaShader        = mai.ssaaShader;
                ai.edgeSharpness     = mai.edgeSharpness;
                ai.shaderFXAAII      = mai.shaderFXAAII;
                ai.shaderFXAAPreset2 = mai.shaderFXAAPreset2;
                ai.shaderFXAAPreset3 = mai.shaderFXAAPreset3;
                ai.dlaaShader        = mai.dlaaShader;
                ai.nfaaShader        = mai.nfaaShader;

                Antis.Add(ai);

                item.AddComponent <DepthOfField>();

                DepthOfField dof = item.GetComponent <DepthOfField>();

                DepthOfField mdof = manager.GetComponent <DepthOfField>();

                dof.dofHdrShader    = mdof.dofHdrShader;
                dof.dx11BokehShader = mdof.dx11BokehShader;

                dof.focalSize      = mdof.focalSize;
                dof.aperture       = mdof.aperture;
                dof.focalTransform = transform;

                DOFs.Add(dof);

                item.AddComponent <Fisheye>();

                Fisheye fe = item.GetComponent <Fisheye>();

                Fisheye mfe = manager.GetComponent <Fisheye>();

                fe.fishEyeShader = mfe.fishEyeShader;
                fe.strengthX     = mfe.strengthX;
                fe.strengthY     = mfe.strengthY;

                Fishes.Add(fe);

                item.AddComponent <SunShafts>();

                SunShafts ss = item.GetComponent <SunShafts>();

                SunShafts mss = manager.GetComponent <SunShafts>();

                ss.simpleClearShader = mss.simpleClearShader;
                ss.sunShaftsShader   = mss.sunShaftsShader;

                ss.sunShaftIntensity    = mss.sunShaftIntensity;
                ss.radialBlurIterations = mss.radialBlurIterations;
                ss.maxRadius            = mss.maxRadius;
                ss.radialBlurIterations = mss.radialBlurIterations;
                ss.resolution           = mss.resolution;
                ss.screenBlendMode      = mss.screenBlendMode;
                ss.sunColor             = mss.sunColor;
                ss.sunShaftBlurRadius   = mss.sunShaftBlurRadius;
                ss.sunThreshold         = mss.sunThreshold;
                ss.sunTransform         = mss.sunTransform;
                ss.useDepthTexture      = mss.useDepthTexture;

                Shafts.Add(ss);
            }

            foreach (Grayscale item in Grays)
            {
                item.enabled = false;
            }


            foreach (SepiaTone item in Sepias)
            {
                item.enabled = false;
            }

            foreach (Bloom item in Blooms)
            {
                item.enabled = false;
            }

            foreach (GlobalFog item in Fogs)
            {
                item.enabled = false;
            }

            foreach (DepthOfField item in DOFs)
            {
                item.enabled = false;
            }

            foreach (Antialiasing item in Antis)
            {
                item.enabled = false;
            }

            foreach (Fisheye item in Fishes)
            {
                item.enabled = false;
            }

            foreach (SunShafts item in Shafts)
            {
                item.enabled = false;
            }
        }

        curentKeyIndex = 0;
        if (SceneManager.GetActiveScene().buildIndex != 0)
        {
            setTop();
        }
    }
Ejemplo n.º 26
0
        public void Fired(IOProxy proxy, List <AbstractProxyEventData> eventData)
        {
            CameraEventData cameraEventData = (CameraEventData)eventData.FirstOrDefault(c => c is CameraEventData);

            if (cameraEventData != null)
            {
                Task.Factory.StartNew(() =>
                {
                    Mat mat = cameraEventData.Image;

                    bool undistort = false;

                    Parent.SyncContext.Send(o =>
                    {
                        undistort = Undistort;

                        if (GammaCorretion)
                        {
                            Mat result = new Mat(ImageWidth, ImageHeight, DepthType.Cv32F, 1);
                            int i      = 0;
                            Mat lut    = new Mat(1, 256, DepthType.Cv32F, 1);
                            foreach (double val in Parent.SettingContainer.Settings.CalibrationSettings.PhotometricCalibrationSettings.ResponseValues)
                            {
                                lut.SetValue(0, i++, (byte)val);
                            }
                            CvInvoke.LUT(mat, lut, result);
                            result.ConvertTo(mat, DepthType.Cv8U);
                        }

                        if (VignetteCorretion)
                        {
                            Mat invVignette = new Mat(ImageWidth, ImageHeight, DepthType.Cv32F, 1);
                            Mat result      = new Mat(ImageWidth, ImageHeight, DepthType.Cv32F, 1);
                            CvInvoke.Divide(Mat.Ones(ImageWidth, ImageHeight, DepthType.Cv32F, 1), Parent.CalibrationViewModel.PhotometricCalibrationViewModel.Vignette.CvImage, invVignette, 255, DepthType.Cv32F);
                            CvInvoke.Multiply(mat, invVignette, result, 1, DepthType.Cv32F);
                            result.ConvertTo(mat, DepthType.Cv8U);
                        }
                    }
                                            , null);

                    if (undistort)
                    {
                        Mat matUndist = new Mat(ImageWidth, ImageHeight, DepthType.Cv8U, 1);

                        if (FishEyeCalibration)
                        {
                            Mat map1 = new Mat();
                            Mat map2 = new Mat();
                            Fisheye.InitUndistorRectifyMap(OrginalCameraMatrix, DistortionCoefficients, Mat.Eye(3, 3, DepthType.Cv64F, 1), CenteredCameraMatrix, new System.Drawing.Size(ImageWidth, ImageHeight), DepthType.Cv32F, map1, map2);
                            CvInvoke.Remap(mat, matUndist, map1, map2, Inter.Linear, BorderType.Constant);
                        }
                        else
                        {
                            CvInvoke.Undistort(mat, matUndist, CenteredCameraMatrix, DistortionCoefficients);
                        }
                        mat = matUndist;
                    }

                    _FPSCounter.CountFrame();
                    Parent.SyncContext.Post(o =>
                    {
                        ExposureTime = (eventData[0] as CameraEventData).ExposureTime;
                        Image        = new CvImageContainer();

                        Image.CvImage = mat;
                    }
                                            , null);
                });
            }
        }
        internal override void SettingsUpdated()
        {
            base.SettingsUpdated();

            bool changed = false;

            changed |= Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Fx != Fx;
            changed |= Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Fy != Fy;
            changed |= Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Cx != Cx;
            changed |= Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Cy != Cy;
            changed |= Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Alpha != Alpha;

            var firstNotSecond = _DistCoeffs.Except(Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.DistCoeffs).ToList();
            var secondNotFirst = Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.DistCoeffs.Except(_DistCoeffs).ToList();

            changed |= firstNotSecond.Any() || secondNotFirst.Any();

            if (changed)
            {
                Fx    = Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Fx;
                Fy    = Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Fy;
                Cx    = Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Cx;
                Cy    = Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Cy;
                Alpha = Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.Alpha;

                _DistCoeffs = Parent.SettingContainer.Settings.CalibrationSettings.IntrinsicCalibrationSettings.DistCoeffs.ToList();

                if (_DistCoeffs.Count == 4)
                {
                    K1 = _DistCoeffs[0];
                    K2 = _DistCoeffs[1];
                    K3 = _DistCoeffs[2];
                    K4 = _DistCoeffs[3];
                }

                Mat board     = ChArUcoCalibration.DrawBoard(5, 5, 0.04f, 0.02f, new System.Drawing.Size(Parent.CameraViewModel.ImageWidth, Parent.CameraViewModel.ImageHeight), 10, PredefinedDictionaryName.Dict6X6_250);
                Mat boardDist = board.Clone();

                Mat cameraMatrix = new Mat(3, 3, Emgu.CV.CvEnum.DepthType.Cv64F, 1);
                Mat distCoeffs   = new Mat(1, Parent.CameraViewModel.FishEyeCalibration ? 4 : _DistCoeffs.Count, Emgu.CV.CvEnum.DepthType.Cv64F, 1);

                cameraMatrix.SetValue(0, 0, Fx);
                cameraMatrix.SetValue(1, 1, Fy);
                cameraMatrix.SetValue(0, 1, Fx * Alpha);
                cameraMatrix.SetValue(0, 2, Cx);
                cameraMatrix.SetValue(1, 2, Cy);
                cameraMatrix.SetValue(2, 2, 1.0f);

                Mat newK = new Mat(3, 3, Emgu.CV.CvEnum.DepthType.Cv64F, 1);

                for (int i = 0; i < distCoeffs.Cols && (Parent.CameraViewModel.FishEyeCalibration ? i < 4 : true); i++)
                {
                    distCoeffs.SetValue(0, i, _DistCoeffs[i]);
                }

                if (Parent.CameraViewModel.FishEyeCalibration)
                {
                    Fisheye.EstimateNewCameraMatrixForUndistorRectify(cameraMatrix, distCoeffs, new System.Drawing.Size(Parent.CameraViewModel.ImageWidth, Parent.CameraViewModel.ImageHeight), Mat.Eye(3, 3, Emgu.CV.CvEnum.DepthType.Cv64F, 1), newK, 0, new System.Drawing.Size(Parent.CameraViewModel.ImageWidth, Parent.CameraViewModel.ImageHeight), 0.3);
                    Mat map1 = new Mat();
                    Mat map2 = new Mat();
                    Fisheye.InitUndistorRectifyMap(cameraMatrix, distCoeffs, Mat.Eye(3, 3, Emgu.CV.CvEnum.DepthType.Cv64F, 1), newK, new System.Drawing.Size(Parent.CameraViewModel.ImageWidth, Parent.CameraViewModel.ImageHeight), Emgu.CV.CvEnum.DepthType.Cv32F, map1, map2);
                    CvInvoke.Remap(board, boardDist, map1, map2, Emgu.CV.CvEnum.Inter.Linear, Emgu.CV.CvEnum.BorderType.Constant);
                }
                else
                {
                    CvInvoke.Undistort(board, boardDist, cameraMatrix, distCoeffs);
                }
                Parent.SyncContext.Post(c =>
                {
                    ChAruCoBoard         = new CvImageContainer();
                    ChAruCoBoard.CvImage = boardDist;
                }, null);
            }
        }
Ejemplo n.º 28
0
 //GameObject game
 //   public GameObject;
 void Start()
 {
     fEye         = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Fisheye>();
     fEye.enabled = false;
 }
Ejemplo n.º 29
0
    // Use this for initialization
    void Start()
    {
        CameraEventManager.onEvent += Effect;

        CameraEventManager.ActualizeFOV += FOVEffect;

        m_Camera = GetComponent<Camera>();

        fisheye = GetComponent<Fisheye>();

        fisheye.enabled = false;
        fisheye.strengthX = 0;
        fisheye.strengthY = 0;
    }
Ejemplo n.º 30
0
	// Use this for initialization
	void Start () {
        fish = GetComponent<Fisheye>();
	}
Ejemplo n.º 31
0
 // Use this for initialization
 void Start()
 {
     fisheye = GetComponent <Fisheye>();
 }
Ejemplo n.º 32
0
 private void Awake()
 {
     GetComponent <Animator>();
     m_fisheye = Camera.main.GetComponent <Fisheye>();
 }
Ejemplo n.º 33
0
        public void SuperR()
        {
            SRC_Img       = new Image <Gray, byte>(@"C:\Users\Админ\Downloads\image63341262,2002.png");
            Corrected_Img = SRC_Img.Clone();

            PointF[] corners = new PointF[] { new PointF(100, 196), new PointF(261, 190), new PointF(417, 192), new PointF(584, 201),
                                              new PointF(111, 277), new PointF(284, 287), new PointF(458, 291), new PointF(580, 284),
                                              new PointF(130, 368), new PointF(276, 395), new PointF(429, 391), new PointF(563, 365) };

            /*MCvPoint3D32f[] objCorners = new MCvPoint3D32f[] { new MCvPoint3D32f( 0, 0, 0.0f),    new MCvPoint3D32f(SRC_Img.Width / 3 - 1, 0, 0.0f),       new MCvPoint3D32f( 2 * SRC_Img.Width / 3 - 1, 0, 0.0f),    new MCvPoint3D32f( SRC_Img.Width - 1, 0, 0.0f),
             *                                  new MCvPoint3D32f( 0, SRC_Img.Height / 2 - 1, 0.0f),  new MCvPoint3D32f(SRC_Img.Width / 3 - 1, SRC_Img.Height / 2 - 1, 0.0f),     new MCvPoint3D32f( 2 * SRC_Img.Width / 3 - 1, SRC_Img.Height / 2 - 1, 0.0f),  new MCvPoint3D32f( SRC_Img.Width - 1, SRC_Img.Height / 2 - 1, 0.0f),
             *                                  new MCvPoint3D32f( 0, SRC_Img.Height - 1, 0.0f),  new MCvPoint3D32f( SRC_Img.Width / 3 - 1, SRC_Img.Height - 1, 0.0f),    new MCvPoint3D32f( 2 * SRC_Img.Width / 3 - 1, SRC_Img.Height - 1, 0.0f),  new MCvPoint3D32f( SRC_Img.Width - 1, SRC_Img.Height - 1, 0.0f)
             *                            };
             */
            // X: 0 - 480 / 3 ||0 159 329 479
            // Y: 0 - 210 / 2 || 0 104 209

            MCvPoint3D32f[] objCorners = new MCvPoint3D32f[] { new MCvPoint3D32f(0, 0, 0.0f), new MCvPoint3D32f(159, 0, 0.0f), new MCvPoint3D32f(329, 0, 0.0f), new MCvPoint3D32f(479, 0, 0.0f),
                                                               new MCvPoint3D32f(0, 104, 0.0f), new MCvPoint3D32f(159, 104, 0.0f), new MCvPoint3D32f(329, 104, 0.0f), new MCvPoint3D32f(479, 104, 0.0f),
                                                               new MCvPoint3D32f(0, 209, 0.0f), new MCvPoint3D32f(159, 209, 0.0f), new MCvPoint3D32f(329, 209, 0.0f), new MCvPoint3D32f(479, 209, 0.0f) };

            VectorOfPointF veccorners = new VectorOfPointF();

            veccorners.Push(corners);
            VectorOfPoint3D32F vecobjcorners = new VectorOfPoint3D32F();

            vecobjcorners.Push(objCorners);

            MCvTermCriteria TermCriteria = new MCvTermCriteria(30, 0.1);

            CvInvoke.CornerSubPix(SRC_Img, veccorners, new Size(2, 2), new Size(-1, -1), TermCriteria);

            IntrinsicCameraParameters intrisic = new IntrinsicCameraParameters();

            ExtrinsicCameraParameters[] extrinsic;
            intrisic.IntrinsicMatrix = new Matrix <double>(new double[, ] {
                { 1, 0, 349.417 }, { 0, 1, 286.417 }, { 0, 0, 1 }
            });
            try
            {
                Matrix <float> distortCoeffs   = new Matrix <float>(1, 4);
                Mat            rotationVectors = new Mat();
                //rotationVectors[0] = new Mat(3,1, DepthType.Cv32F, 1);
                Mat translationVectors = new Mat();
                //translationVectors[0] = new Mat(1, 3, DepthType.Cv32F, 1);

                /*
                 * double error = CvInvoke.CalibrateCamera(new MCvPoint3D32f[][] { objCorners }, new PointF[][] { veccorners.ToArray() },
                 *   SRC_Img.Size, intrisic.IntrinsicMatrix, distortCoeffs, CalibType.UserIntrinsicGuess, new MCvTermCriteria(30, 0.01), out rotationVectors, out translationVectors);
                 */
                /*
                 *
                 * Fisheye.Calibrate(vecobjcorners, veccorners, SRC_Img.Size, intrisic.IntrinsicMatrix, distortCoeffs, rotationVectors, translationVectors,
                 * Fisheye.CalibrationFlag.UseIntrinsicGuess, TermCriteria);
                 * */

                Matrix <float> matrix = new Matrix <float>(new float[, ] {
                    { 1, 0, 349 }, { 0, 1, 286 }, { 0, 0, 1 }
                });
                Fisheye.UndistorImage(SRC_Img, Corrected_Img, matrix, new VectorOfFloat(new float[] { 3500, 3500, 0, 0 }));
                Image <Gray, Byte> Res_Img = new Image <Gray, byte>(2 * SRC_Img.Width, SRC_Img.Height);
                CvInvoke.HConcat(SRC_Img, Corrected_Img, Res_Img);
                int error = 0;
                error++;
                //error += 0;
                //Array aa = rotationVectors[0].Data;
                //error += 0;
                //float q = rotationVectors.ElementAt<float>(0);
            }
            catch (Exception) { }
        }
Ejemplo n.º 34
0
    int width, height;    //resolução da janela

    void Start()
    {
        //o objeto, assim que é criado, assume papel como singleton
        if (me != null)
        {
            Destroy(gameObject);
            return;
        }
        me = this;
        Content.Start();
        loading = true;
        credits = false;

        //marcar as referências
        tr    = transform;
        camTr = tr.Find("cam");
        cam   = camTr.GetComponent <Camera>();

        background = camTr.Find("bg").GetComponent <Animator>();
        fisheye    = camTr.GetComponent <Fisheye>();
        blur       = camTr.GetComponent <MotionBlur>();
        fade       = camTr.Find("fade").GetComponent <SpriteRenderer>();
        blank      = camTr.Find("blank").GetComponent <SpriteRenderer>();
        fading     = camTr.Find("fading").GetComponent <Animator>();

        creditsTr     = camTr.Find("credits");
        creditsScroll = creditsTr.Find("scroll");

        meterTr     = camTr.Find("meter");
        meterHeight = meterTr.Find("height");

        sheepTr   = tr.Find("sheep");
        sheep     = sheepTr.GetComponent <Sheep>();
        badTripTr = tr.Find("badtrip");

        audioBg  = camTr.GetComponent <AudioSource>();
        audioBad = badTripTr.GetComponent <AudioSource>();

        //carregar cenas
        //na vdd isso depende. se o cara tá no _main, ele carrega o jogo normal.
        //senão, ele carrega só as coisas atuais, para testar essa fase específica.
                #if UNITY_EDITOR
        if (Application.loadedLevelName == "_main")
        {
                #endif
        //carregar todas as cenas
        levelCount = sceneNames.Length;
        levels     = new Level[levelCount];
        StartCoroutine(LoadLevels());
                #if UNITY_EDITOR
    }

    else
    {
        //carreegar só a cena atual.
        //isso só funciona no editor pq né
        levels = new Level[] { (Level)GameObject.FindObjectsOfType(typeof(Level))[0] }
        ;
        levels[0].index = 0;
        levels[0].start = 0;
        levels[0].end   = levels[0].width;
        totalWidth      = levels[0].width;
        levelCount      = 1;
        loading         = false;

        //iniciar nível
        levelIndex = 0;
        UpdateLevel();
        UpdateCameraLimits();
        camX = minX;
        camTr.localPosition = new Vector3(camX, camTr.localPosition.y, camTr.localPosition.z);
    }
                #endif

        fisheye.strengthX = fisheye.strengthY = 0;
                #if UNITY_EDITOR
        if (Application.loadedLevelName == "_main" || Application.loadedLevelName == "map1")
        {
            meterTr.localPosition = new Vector3(meterTr.localPosition.x, meterTr.localPosition.y, 500);
        }
        else
        {
            meterTr.localPosition = new Vector3(meterTr.localPosition.x, meterTr.localPosition.y, 0);
            sheep.AddHighness();
        }
                #else
        meterTr.localPosition = new Vector3(meterTr.localPosition.x, meterTr.localPosition.y, 500);
                #endif

        badTripPos = -10;
        badTripTr.localPosition = new Vector3(-10, badTripTr.localPosition.y, badTripTr.localPosition.z);
        fade.color = Color.black;
        creditsTr.localPosition = new Vector3(0, 0, -500);
        blank.color             = new Color(1, 1, 1, 0);

        //verifica se mostra o tempo ou não --- JU
        if (Content.firstRun)
        {
            tr.Find("tutorial").localPosition = Vector3.zero;
            tr.Find("status").localPosition   = new Vector3(0, 0, 500);
        }
        else
        {
            tr.Find("status").localPosition   = Vector3.zero;
            tr.Find("tutorial").localPosition = new Vector3(0, 0, 500);
            float  timeFinal = Content.timeEnd - Content.timeStart;
            string prefix;
            if (Content.gotThrough)
            {
                prefix = "completed in ";
            }
            else
            {
                prefix = "lived for ";
            }
            tr.Find("status/text").GetComponent <TextMesh>().text = prefix + ((int)(timeFinal / 60)).ToString("D2") + ":" + (timeFinal % 60).ToString("00.000") + "\n" + Content.collectablesLast + "/8 flowers colected";
        }

        //atualizar resolução do jogo
        SetCamera();
    }