private float GetMultipliertOfLine(ColorMethods.ColorName colorName) { switch (colorName) { case ColorMethods.ColorName.Black: return(1); case ColorMethods.ColorName.Blue: return(1000000); case ColorMethods.ColorName.Brown: return(10); case ColorMethods.ColorName.Gold: return(0.1f); case ColorMethods.ColorName.Gray: return(-1f); case ColorMethods.ColorName.Green: return(100000); case ColorMethods.ColorName.Orange: return(1000); case ColorMethods.ColorName.Purple: return(10000000); case ColorMethods.ColorName.Red: return(100); case ColorMethods.ColorName.Unknown: return(-2f); case ColorMethods.ColorName.White: return(-1f); case ColorMethods.ColorName.Yellow: return(10000); default: return(-2f); } }
private float GetToleranceOfLine(ColorMethods.ColorName colorName) { switch (colorName) { case ColorMethods.ColorName.Black: return(-1); case ColorMethods.ColorName.Blue: return(0.25f); case ColorMethods.ColorName.Brown: return(1); case ColorMethods.ColorName.Gold: return(5); case ColorMethods.ColorName.Gray: return(0.05f); case ColorMethods.ColorName.Green: return(0.5f); case ColorMethods.ColorName.Orange: return(-1); case ColorMethods.ColorName.Purple: return(0.1f); case ColorMethods.ColorName.Red: return(2f); case ColorMethods.ColorName.Unknown: return(-2); case ColorMethods.ColorName.White: return(-1); case ColorMethods.ColorName.Yellow: return(4); default: return(-2); } }
private float GetDigitOfLine(ColorMethods.ColorName colorName) { switch (colorName) { case ColorMethods.ColorName.Black: return(0); case ColorMethods.ColorName.Blue: return(6); case ColorMethods.ColorName.Brown: return(1); case ColorMethods.ColorName.Gold: return(-1); case ColorMethods.ColorName.Gray: return(8); case ColorMethods.ColorName.Green: return(5); case ColorMethods.ColorName.Orange: return(3); case ColorMethods.ColorName.Purple: return(7); case ColorMethods.ColorName.Red: return(2); case ColorMethods.ColorName.Unknown: return(-2); case ColorMethods.ColorName.White: return(9); case ColorMethods.ColorName.Yellow: return(4); default: return(-2); } }
private Color GetPrimitiveColor(ColorMethods.ColorName colorName) { switch (colorName) { case ColorMethods.ColorName.Black: return(Color.black); case ColorMethods.ColorName.Blue: return(Color.blue); case ColorMethods.ColorName.Brown: return(new Color(71f / 255f, 34f / 255f, 10f / 255f)); //Brown case ColorMethods.ColorName.Gray: return(Color.gray); case ColorMethods.ColorName.Green: return(Color.green); case ColorMethods.ColorName.Orange: return(new Color(255f / 255f, 142f / 255f, 0f / 255f)); //Orange case ColorMethods.ColorName.Purple: return(new Color(167f / 255f, 0f / 255f, 255f / 255f)); //Purple case ColorMethods.ColorName.Red: return(Color.red); case ColorMethods.ColorName.Unknown: return(new Color(0, 0, 0, 0)); //Transparent case ColorMethods.ColorName.White: return(Color.white); case ColorMethods.ColorName.Yellow: return(Color.yellow); default: return(new Color(0, 0, 0, 0)); } }
private void Update() { //print(ColorMethods.GetResistorColorCode(new Color(0f, 4f/255f, 13f/255f)).ToString()); if (Input.GetKeyDown(KeyCode.Space)) { var data = t.EncodeToPNG(); File.WriteAllBytes("a.png", data); print("oldu"); } if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began && Input.touches[0].position.x > Screen.width / 2) { Application.CaptureScreenshot("ss" + Time.fixedTime + ".png"); //StartCoroutine(CaptureScreenshotCoroutine(Screen.width, Screen.height)); s += "s"; } if (!camAvailable) { return; } float ratio = (float)backCam.width / (float)backCam.height; fit.aspectRatio = ratio; float zoomValue = 2.7f; float scaleY = backCam.videoVerticallyMirrored ? -1f : 1f; background.rectTransform.localScale = new Vector3(1f * zoomValue, scaleY * zoomValue, 1f); int orient = -backCam.videoRotationAngle; background.rectTransform.localEulerAngles = new Vector3(0, 0, orient); Color color = backCam.GetPixel(backCam.width / 2, backCam.height / 2); ColorMethods.ColorName colorName = ColorMethods.GetResistorColorCode(color); colorDisplayer.color = GetPrimitiveColor(colorName); //colorText.text = "Color: " + colorName.ToString(); infoText.text = ColorMethods.GetHSV(color).ToString() + s; cursor.anchoredPosition = new Vector3(1080 / 2, 1920 / 2, 0f); int width = 75; int heigth = 5; Color[] colorBlock = backCam.GetPixels(backCam.width / 2 - width / 2, backCam.height / 2 - (heigth - 1) / 2, width, heigth); Color[,] colorBlock2D = ArrayTo2DArray(colorBlock, width, heigth); //Color baseColor; //List<ColorData> colorData = ResistorOhmFinder.GetLines(colorBlock2D, out baseColor); //simulator.Set(colorData, baseColor); t = new Texture2D(width, heigth); t.SetPixels(0, 0, width, heigth, colorBlock); t.Apply(); var t2 = MedianBlur(t, 5); t2.Apply(); Color[] colorBlockBlurred = t2.GetPixels(); Color[,] colorBlockBlurred2D = ArrayTo2DArray(colorBlockBlurred, width, heigth); //testTexture2D = MedianBlur(testTexture2D); testImage.texture = t; testImage2.texture = t2; List <ColorMethods.ColorName> colorData = ResistorOhmFinder.GetLines(colorBlockBlurred2D, lineCount); simulator.Set(colorData, lineCount); redLine.sizeDelta = new Vector2(width * zoomValue / 2 * 1.1f, 3); //redLine.sizeDelta = new Vector2(width * ratio / 2 * zoomValue * 1.1f, 3); }
public static List <ColorMethods.ColorName> GetLines(Color[,] data, LineCount lineCount) { List <ColorMethods.ColorName> result = new List <ColorMethods.ColorName>(); if (lineCount == LineCount.four) { //Add most left line ColorMethods.ColorName color = GetColor(data, 1); //if (color != ColorMethods.ColorName.Unknown) result.Add(color); //else // return null; //Add second line int linePosition = data.GetLength(1) / 3; color = GetColor(data, linePosition); //if (color != ColorMethods.ColorName.Unknown) result.Add(color); //else // return null; //Add third line linePosition = data.GetLength(1) / 3 * 2; color = GetColor(data, linePosition); //if (color != ColorMethods.ColorName.Unknown) result.Add(color); //else // return null; //Add fourth line linePosition = data.GetLength(1) - 2; color = GetColor(data, linePosition); //if (color != ColorMethods.ColorName.Unknown) result.Add(color); //else // return null; } else { //Add most left line ColorMethods.ColorName color = GetColor(data, 1); //if (color != ColorMethods.ColorName.Unknown) result.Add(color); //else // return null; //Add second line int linePosition = (int)(data.GetLength(1) * 0.27f); color = GetColor(data, linePosition); //if (color != ColorMethods.ColorName.Unknown) result.Add(color); //else // return null; //Add third line linePosition = (int)(data.GetLength(1) * 0.5f); color = GetColor(data, linePosition); //if (color != ColorMethods.ColorName.Unknown) result.Add(color); //else // return null; //Add fourth line linePosition = (int)(data.GetLength(1) * 0.73f); color = GetColor(data, linePosition); //if (color != ColorMethods.ColorName.Unknown) result.Add(color); //else // return null; //Add fourth line linePosition = data.GetLength(1) - 2; color = GetColor(data, linePosition); //if (color != ColorMethods.ColorName.Unknown) result.Add(color); //else // return null; } //Debug.Log("LINES FOUND!"); return(result); }
private static ColorMethods.ColorName GetColor2(Color[,] data, int i) { int j = (data.GetLength(0) - 1) / 2; ColorMethods.ColorName color = ColorMethods.GetResistorColorCode(data[j, i]); if (color != ColorMethods.ColorName.Unknown) { return(color); } //If color did not recognized, look left.. if (i > 0 && (color = ColorMethods.GetResistorColorCode(data[j, i - 1])) != ColorMethods.ColorName.Unknown) { return(color); } //If not recognized, look rigth if (i < data.GetLength(1) - 1 && (color = ColorMethods.GetResistorColorCode(data[j, i + 1])) != ColorMethods.ColorName.Unknown) { return(color); } //If not recognized, look top if (j > 0 && (color = ColorMethods.GetResistorColorCode(data[j - 1, i])) != ColorMethods.ColorName.Unknown) { return(color); } //If not recognized, look bottom if (data.GetLength(0) > 1 && (color = ColorMethods.GetResistorColorCode(data[j + 1, i])) != ColorMethods.ColorName.Unknown) { return(color); } //If not recognized, look top left if (j > 0 && i > 0 && (color = ColorMethods.GetResistorColorCode(data[j - 1, i - 1])) != ColorMethods.ColorName.Unknown) { return(color); } //If not recognized, look top rigth if (j > 0 && i < data.GetLength(1) - 1 && (color = ColorMethods.GetResistorColorCode(data[j - 1, i + 1])) != ColorMethods.ColorName.Unknown) { return(color); } //If not recognized, look bottom left if (data.GetLength(0) > 1 && i > 0 && (color = ColorMethods.GetResistorColorCode(data[j + 1, i - 1])) != ColorMethods.ColorName.Unknown) { return(color); } //If not recognized, look bottom right if (data.GetLength(0) > 1 && i < data.GetLength(1) - 1 && (color = ColorMethods.GetResistorColorCode(data[j + 1, i + 1])) != ColorMethods.ColorName.Unknown) { return(color); } //If never recognized, return null return(ColorMethods.ColorName.Unknown); }