Beispiel #1
0
    public void RestoreFromUndoState()
    {
        Alert.Singleton.ShowAlert(Alert.Message.BETTER_EXPERIENCE);



        if (Undo != null)
        {
            int last = Undo.Count - 1;

            if (last >= 0)
            {
                Undo[last].CopyTo(WallMask);

                if (OutputMaskTexture)
                {
                    WallMask.ApplyToTexture2D(OutputMaskTexture);
                }

                else
                {
                    Debug.LogError("Kauel: Error OutputMaskTexture == null");
                }

                Undo[last].Dispose();

                Undo.RemoveAt(last);
            }
            else
            {
                //Reset Position and Rotation

                var panZoom = RawImageEdit.GetComponent <KPanZoomRotation>();

                if (panZoom)
                {
                    panZoom.ResetPositionAndSize();
                }
            }
        }
    }
Beispiel #2
0
    void Update()
    {
        if (testing)
        {
            DetectEdges();

            Mat temp = new Mat();

            CvInvoke.CvtColor(EdgeMap, temp, ColorConversion.Gray2Bgr);

            temp.ApplyToTexture2D(OutputTexture);

            temp.Dispose();

            return;
        }
    }
Beispiel #3
0
    //Esta función genera un JPG con la comparación de un antes y un después y agrega una barra que muestra los colores usados y el logo de Ceresita

    public void PreprocessTextureFromRawImage()
    {
        bool color1used = false;

        bool color2used = false;



        Debug.Log("Kauel: PreprocessTextureFromRawImage()");



        Debug.Log("WallMask = " + WallMask.str());



        Mat Channel0 = new Mat();

        Mat Channel1 = new Mat();

        CvInvoke.ExtractChannel(WallMask, Channel0, 0);

        CvInvoke.ExtractChannel(WallMask, Channel1, 1);

        Debug.Log("Channel0 = " + Channel0.str());

        Debug.Log("Channel1 = " + Channel1.str());



        color1used = CvInvoke.CountNonZero(Channel0) > 10;

        color2used = CvInvoke.CountNonZero(Channel1) > 10;

        Debug.Log("color1used = " + color1used);

        Debug.Log("color2used = " + color2used);

        Channel0.Dispose();

        Channel1.Dispose();



        EncodedImageAsPNG = null;



        if ((OutputTexture == null) || (TargetMaterial == null))
        {
            Debug.Log("Kauel: OutputTextures == null");

            return;
        }



        Texture2D tex = OutputTexture;

        Texture2D result = new Texture2D(tex.width, tex.height, tex.format, false);



        RenderTexture temp = RenderTexture.GetTemporary(tex.width, tex.height); //Textura temporal para aplicar el material

        //Siguiente linea comentada por Actualizacion de Plugin
        //Graphics.Blit(tex, temp, TargetMaterial); //Aplica el material



        //Copia la textura temporal

        RenderTexture.active = temp;

        result.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);

        RenderTexture.active = null;

        RenderTexture.ReleaseTemporary(temp); //Libera memoria



        Mat before = CameraMat24.Clone();

        CvInvoke.Flip(before, before, FlipType.Vertical);

        CvInvoke.CvtColor(before, before, ColorConversion.Bgr2Rgb);

        Mat after = result.GetNewMat();

        Debug.Log("Kauel: Before =" + before.str());

        Debug.Log("Kauel: After =" + after.str());



        //Junta las 2 imagenes de forma horizontal

        Mat beforeafter = new Mat();

        CvInvoke.HConcat(before, after, beforeafter);



        //Logo de Ceresita

        Mat corner = Corner.GetNewMat(); //Logo de Ceresita



        //Ancho de cada barra

        int w1 = (beforeafter.Width - corner.Width) / 2;

        int w2 = beforeafter.Width - corner.Width - w1;



        //Uso de dos colores

        if (color1used && color2used)
        {
            //Uso de uno o ningun color
        }
        else
        {
            w1 = beforeafter.Width - corner.Width;

            w2 = w1;
        }



        Mat bar1 = new Mat(corner.Height, w1, DepthType.Cv8U, 3);



        Kolores k = SelectedColors[0].SelectedKolor;

        float r = k.RGBA.r * 255;

        float g = k.RGBA.g * 255;

        float b = k.RGBA.b * 255;

        float l = k.HSL.z;

        bar1.SetTo(new MCvScalar(b, g, r)); //Pinta la Barra del primer color



        MCvScalar textcolor = White;

        if (l > 0.5f)
        {
            textcolor = Black;
        }

        CvInvoke.PutText(bar1, k.Name, new Point(40, 50), FontFace.HersheyDuplex, 1.0, textcolor, 2);

        CvInvoke.PutText(bar1, k.Code, new Point(40, 100), FontFace.HersheyDuplex, 1.0, textcolor, 2);



        //Aplica la segunda barra de color

        Mat bar2 = new Mat(corner.Height, w2, DepthType.Cv8U, 3);

        k = SelectedColors[1].SelectedKolor;

        r = k.RGBA.r * 255;

        g = k.RGBA.g * 255;

        b = k.RGBA.b * 255;

        l = k.HSL.z;

        bar2.SetTo(new MCvScalar(b, g, r)); //Pinta la Barra del segundo color



        textcolor = White;

        if (l > 0.5f)
        {
            textcolor = Black;
        }

        CvInvoke.PutText(bar2, k.Name, new Point(40, 50), FontFace.HersheyDuplex, 1.0, textcolor, 2);

        CvInvoke.PutText(bar2, k.Code, new Point(40, 100), FontFace.HersheyDuplex, 1.0, textcolor, 2);



        //Uso de dos colores

        if (color1used && color2used)
        {
            CvInvoke.HConcat(bar1, bar2, bar2);

            CvInvoke.HConcat(bar2, corner, bar2);
        }
        else
        {
            //Solo color 2

            if (color2used)
            {
                CvInvoke.HConcat(bar2, corner, bar2);
            }
            else
            {
                CvInvoke.HConcat(bar1, corner, bar2);
            }
        }



        CvInvoke.VConcat(beforeafter, bar2, beforeafter);



        CvInvoke.Flip(beforeafter, beforeafter, FlipType.Vertical);

        CvInvoke.CvtColor(beforeafter, beforeafter, ColorConversion.Bgr2Rgb);



        beforeafter.ApplyToTexture2D(result);



        before.Dispose();

        after.Dispose();

        beforeafter.Dispose();

        corner.Dispose();

        bar1.Dispose();

        bar2.Dispose();



        EncodedImageAsPNG = result.EncodeToPNG();



        RawTexture2D = result;
    }
Beispiel #4
0
    public void ConfigureForTexture(Texture tex)
    {
        Debug.Log("Kauel: ConfigureForTexture()");

        //FreeMem

        if (CameraMat32 != null)
        {
            FreeMem();
        }



        //Allocate Mem

        if (tex is Texture2D)
        {
            Debug.Log("Kauel: tex is texture2D");
            CameraColors32 = ((Texture2D)tex).GetPixels32();
        }

        else
        {
            Debug.Log("Kauel: tex is texture");
            CameraColors32 = new Color32[tex.width * tex.height];
        }

        IntPtr CameraPointer32 = Marshal.UnsafeAddrOfPinnedArrayElement(CameraColors32, 0);

        CameraMat32 = new Mat(tex.height, tex.width, DepthType.Cv8U, 4, CameraPointer32, tex.width * 4);



        CameraColors24 = new Byte[tex.width * tex.height * 3];

        IntPtr CameraPointer24 = Marshal.UnsafeAddrOfPinnedArrayElement(CameraColors24, 0);

        CameraMat24 = new Mat(tex.height, tex.width, DepthType.Cv8U, 3, CameraPointer24, tex.width * 3);

        WallMaskBuffer = new byte[tex.height * tex.width * 3];

        IntPtr WallMaskPointer = Marshal.UnsafeAddrOfPinnedArrayElement(WallMaskBuffer, 0);

        WallMask = new Mat(tex.height, tex.width, DepthType.Cv8U, 3, WallMaskPointer, tex.width * 3);

        WallMask.SetTo(Black);

        OutputTexture = new Texture2D(tex.width, tex.height, TextureFormat.RGB24, false);

        OutputMaskTexture = new Texture2D(tex.width, tex.height, TextureFormat.RGB24, false);

        WallMask.ApplyToTexture2D(OutputMaskTexture);



        CvInvoke.CvtColor(CameraMat32, CameraMat24, ColorConversion.Rgba2Rgb, 3);

        //XPhotoInvoke.BalanceWhite(CameraMat24, CameraMat24, WhiteBalanceMethod.Simple, 0, 255, 20, 230);

        CameraMat24.ApplyToTexture2D(OutputTexture);



        RawImageEdit.texture = OutputTexture;



        //Undo Textures

        Undo = new List <Mat>();



        var PanZoomRotation = RawImageEdit.GetComponent <KPanZoomRotation>();

        if (PanZoomRotation)
        {
            Debug.Log("Kauel: ResetPositionAndSize ");

            PanZoomRotation.ResetPositionAndSize();
        }



        TargetMaterial.SetTexture("_MaskTex", OutputMaskTexture);



        Debug.Log("Kauel: Camera Buffers Created with resolution " + tex.width + "x" + tex.height);
    }
Beispiel #5
0
    private IEnumerator Load()

    {
        if (!KProjectManager.CheckIfExists(id))

        {
            Debug.LogError("Kauel: No existe el proyecto " + id);
        }

        else

        {
            string filecolor = Application.persistentDataPath + "/color" + id + ".png";

            string filemask = Application.persistentDataPath + "/mask" + id + ".png";

            string fileinfo = Application.persistentDataPath + "/info" + id + ".ceresita";



            Debug.Log("Kauel: Inicio Load");



            //Imagen de Color

            WWW www1 = new WWW("file://" + filecolor);

            yield return(www1);

            Texture2D www1Tex = www1.texture;

            Kamera.Singleton.StartFile(www1Tex);

            www1.Dispose();



            //Mascara

            WWW www2 = new WWW("file://" + filemask);

            yield return(www2);

            Texture2D www2Tex = www2.texture;

            Mat mask = www2Tex.GetNewMat();

            CvInvoke.Flip(mask, mask, FlipType.Vertical);

            Mat wall = Kamera.Singleton.CameraMask();

            mask.CopyTo(wall);

            wall.ApplyToTexture2D(Kamera.Singleton.OutputMaskTexture);

            mask.Dispose();

            www2.Dispose();



            //Color

            WWW www3 = new WWW("file://" + fileinfo);

            yield return(www3);

            string json = www3.text;

            JsonUtility.FromJsonOverwrite(json, this);

            Kamera.Singleton.SelectedColors[0].CopyColorFromKolor(Kolores.FullList[KolorIndex1]);

            Kamera.Singleton.SelectedColors[1].CopyColorFromKolor(Kolores.FullList[KolorIndex2]);

            www3.Dispose();



            Alert.Singleton.CloseAlert(true);



            Kamera.Singleton.Canvas.ShowOnlyThisPanel(3);
        }
    }