Example #1
0
    void RunTest()
    {
        if (!video)
        {
            mat.SetTexture("_MainTex", textureToTest);
            pic.localScale   = new Vector3(textureToTest.width, textureToTest.height, 1);
            EdgeDetect.image = textureToTest;
            EdgeDetect.Process();
            //var path = LaserPath.ConvertEdge(EdgeDetect.chains);
            //path = LaserPath.OptimizePath(path, 16);

            //var cfile = File.CreateText(@"D:\LZR\MyFiles\temp\coors.txt");

            //cfile.Write("float coorX[] = {");
            //foreach (var node in path)
            //{
            //    cfile.Write(string.Format("{0:F3}f, ", node.pos.x));
            //}
            //cfile.Write("};");
            //cfile.WriteLine("");
            //cfile.Write("float coorY[] = {");
            //foreach (var node in path)
            //{
            //    cfile.Write(string.Format("{0:F3}f, ", node.pos.y));
            //}
            //cfile.Write("};");
            //cfile.WriteLine("");
            //cfile.Write("float coorI[] = {");
            //foreach (var node in path)
            //{
            //    cfile.Write(string.Format("{0:F3}f, ", node.intensity));
            //}
            //cfile.Write("};");
            ////cfile.WriteLine("");

            //cfile.Flush(); cfile.Close();
        }
        else
        {
            mat.SetTexture("_MainTex", rt);
            pic.localScale = new Vector3(rt.width, rt.height, 1);
            tex2d          = new Texture2D(rt.width, rt.height);
            vp.Play();
        }
        //Debug.Log(EdgeDetect.chains.Count);
    }
Example #2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.T))
        {
            RunTest();
        }
        if (video && tex2d)
        {
            EdgeDetect.image = tex2d;
            EdgeDetect.Process();

            //var path = LaserPath.ConvertEdge(EdgeDetect.chains);
            //path = LaserPath.OptimizePath(path, 16);
        }
        //LaserPath.color = Color.HSVToRGB(Mathf.Clamp((EdgeDetect.brightness - 0.5f) * 2 + 1 / 3f, 1 / 6f, 1 / 2f), 1, 1);
        LaserPath.color = EdgeDetect.brightness > 0.5f ? Color.cyan : Color.yellow;
        var path = LaserPath.ConvertEdge(new List <EdgeChain>(EdgeDetect.chains));

        DrawLaserPath(path);
        SerialUtil.instance.dataToSend = path;
    }