// Update is called once per frame // void Update () {} public void Select(string categoria) { Kolores.Select(categoria); for (int i = 0; i < Kolores.FullList.Count; i++) { Kolores k = Kolores.FullList[i]; Image img = transform.GetChild(k.index).GetComponent <Image>(); KolorContainer kc = img.GetComponent <KolorContainer>(); kc.Kolor = k; img.color = k.RGBA; if (k.Selected) { img.gameObject.SetActive(true); } else { img.gameObject.SetActive(false); } } }
public void LoadKolores() { if (TheKamera != null) { TheKamera.Init(); } if ((Colores != null) && (Kolores.FullList.Count <= 0)) { Kolores.ParseFromFile(Colores); SetChildrenCount(Kolores.FullList.Count); Select("grises"); foreach (CopyColor t in Targets) { if (t) { t.CopyColorFromKolor(Kolores.FullList[DefaultColor]); } } } int projectCount = KProjectManager.SearchForProjects(); Debug.Log("Kauel: Proyectos existentes = " + projectCount); }
public static void ClearSelectStatus(bool status) { for (int i = 0; i < FullList.Count; i++) { Kolores k = FullList[i]; k.Selected = status; } }
public void CopyColorFromKolor(Kolores kolor) { SelectedKolor = kolor; Image img2 = GetComponent <Image>(); if (img2) { img2.color = kolor.RGBA; } if (TargetMaterial) { string stargetcolor = "_TargetColor" + TargetColor; string stargetlum = "_LumWall" + TargetColor; TargetMaterial.SetColor(stargetcolor, kolor.RGBA); float targetlum = (kolor.HSL.z - 0.5f) * 0.5f + 0.75f; TargetMaterial.SetFloat(stargetlum, targetlum); } if (TargetText) { TargetText.text = kolor.FullName; } }
//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; }
public static void ParseFromFile(TextAsset file) { string fs = file.text; string[] Lines = Regex.Split(fs, "\n|\r|\r\n"); fs = null; FullList.Clear(); //var Lines = File.ReadAllLines(filename); for (int i = 0; i < Lines.Length; i++) { var Col = Lines[i].Split(";"[0]); if (Col.Length >= 5) { Kolores K = new Kolores(); K.Code = Col[0]; K.Name = Col[3]; K.FullName = Col[1]; K.RGBA = hexToColor(Col[4]); K.HSL = RGBtoHSL(new Vector3(K.RGBA.r, K.RGBA.g, K.RGBA.b)); K.index = FullList.Count; K.Selected = false; //Solo algunos colores tienen este campo. //Se implemento inicialmente para identificar manualmente //los colores por grupos, por ejemplo: los grises. if (Col.Length > 5) { K.tag = Col[5]; } else { K.tag = "None"; } FullList.Add(K); } Col = null; } Lines = null; Debug.Log("Kauel: Total de Colores = " + FullList.Count); }
public static void Select(string categoria) { SelectedList.Clear(); ClearSelectStatus(false); for (int i = 0; i < FullList.Count; i++) { Kolores k = FullList[i]; bool add = false; float hue = k.HSL.x * 360; float sat = k.HSL.y; float lum = k.HSL.z; float deltahue = 40; //60 float minsat = 0.2f; //0.1 string cat = categoria.ToLowerInvariant(); if (k.tag == cat) { add = true; Debug.Log("Kauel: Selected by Tag " + k.Code); } switch (cat) { case "verdes": if ((hue > 135 - deltahue) && (hue < 135 + deltahue) && (sat > minsat)) { add = true; } break; case "purpuras": if ((hue > 270 - deltahue) && (hue < 270 + deltahue) && (sat > minsat)) { add = true; } break; case "azules": if ((hue > 240 - deltahue * 0.5f) && (hue < 240 + deltahue * 0.5f) && (sat > minsat)) { add = true; } break; case "blancos": if ((sat < 0.2f) && (lum > 0.7f)) { add = true; } break; case "aqua": if ((hue > 180 - deltahue * 0.5f) && (hue < 180 + deltahue * 0.5f) && (sat > minsat)) { add = true; } break; case "grises": if (k.tag.CompareTo("gray") == 0) { add = true; } break; case "amarillos": if ((hue > 60 - deltahue * 0.25f) && (hue < 60 + deltahue * 0.25f) && (sat > minsat)) { add = true; } break; case "cafes": if ((hue > 30 - deltahue * 0.25f) && (hue < 30 + deltahue * 0.25f) && (sat > minsat) && (sat < 0.5f)) { add = true; } break; case "naranjos": if ((hue > 30 - deltahue * 0.25f) && (hue < 30 + deltahue * 0.25f) && (sat > 0.5f)) { add = true; } break; case "rojos": if (((hue < deltahue * 0.25f) || (hue > 360 - deltahue * 0.25f)) && (sat > 0.35f)) { add = true; } break; case "rosados": if ((hue > 320 - deltahue * 0.5f) && (hue < 320 + deltahue * 0.5f) && (sat > minsat)) { add = true; } break; case "todos": add = true; break; default: add = true; break; } if (add) { k.Selected = true; SelectedList.Add(k); } ; } Debug.Log("Seleccionados = " + SelectedList.Count); }