Пример #1
0
        // Use this for initialization
        void Start()
        {
            Mat mat = Unity.TextureToMat(this.texture);

            Vector3[,] v = new Vector3[mat.Height, mat.Width];
            for (int yi = 0; yi < mat.Height; yi++)
            {
                for (int xi = 0; xi < mat.Width; xi++)
                {
                    Vec3b vyx = mat.At <Vec3b>(yi, xi);
                    v[yi, xi][0] = vyx[0];
                    v[yi, xi][1] = vyx[1];
                    v[yi, xi][2] = vyx[2];
                }
            }
            v = Median(v, mat.Height, mat.Width);
            for (int yi = 0; yi < mat.Height; yi++)
            {
                for (int xi = 0; xi < mat.Width; xi++)
                {
                    Vec3b vyx = new Vec3b();
                    vyx[0] = (byte)v[yi, xi][0];
                    vyx[1] = (byte)v[yi, xi][1];
                    vyx[2] = (byte)v[yi, xi][2];
                    mat.Set <Vec3b>(yi, xi, vyx);
                }
            }
            Texture2D changedTex = Unity.MatToTexture(mat);

            GetComponent <RawImage>().texture = changedTex;
        }
Пример #2
0
 /// <summary>
 /// Writes data to a file storage.
 /// </summary>
 /// <param name="val"></param>
 public FileStorage Add(Vec3b val)
 {
     ThrowIfDisposed();
     NativeMethods.core_FileStorage_shift_Vec3b(ptr, val);
     GC.KeepAlive(this);
     return(this);
 }
Пример #3
0
        // Use this for initialization
        void Start()
        {
            Mat mat = Unity.TextureToMat(this.texture);

            for (int yi = 0; yi < mat.Height; yi++)
            {
                for (int xi = 0; xi < mat.Width; xi++)
                {
                    Vec3b v = mat.At <Vec3b>(yi, xi);
                    Debug.Log(v[0]);
                    float gr = 0.2126f * v[2] + 0.7152f * v[1] + 0.0722f * v[0];
                    if (gr < 128)
                    {
                        gr = 0;
                    }
                    else
                    {
                        gr = 255;
                    }
                    v[0] = (byte)gr;
                    v[1] = (byte)gr;
                    v[2] = (byte)gr;
                    mat.Set <Vec3b>(yi, xi, v);
                }
            }
            Texture2D changedTex = Unity.MatToTexture(mat);

            GetComponent <RawImage>().texture = changedTex;
        }
Пример #4
0
        /// <summary>
        /// Creates a proxy class of the specified Vec*b
        /// </summary>
        /// <param name="vec"></param>
        /// <returns></returns>
        public static InputArray Create(IVec vec)
        {
            if (vec == null)
            {
                throw new ArgumentNullException(nameof(vec));
            }

            return(vec switch
            {
                Vec2b v => new InputArray(new[] { v.Item0, v.Item1 }),
                Vec3b v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }),
                Vec4b v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }),
                Vec6b v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }),
                Vec2s v => new InputArray(new[] { v.Item0, v.Item1 }),
                Vec3s v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }),
                Vec4s v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }),
                Vec6s v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }),
                Vec2w v => new InputArray(new[] { v.Item0, v.Item1 }),
                Vec3w v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }),
                Vec4w v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }),
                Vec6w v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }),
                Vec2i v => new InputArray(new[] { v.Item0, v.Item1 }),
                Vec3i v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }),
                Vec4i v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }),
                Vec6i v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }),
                Vec2f v => new InputArray(new[] { v.Item0, v.Item1 }),
                Vec3f v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }),
                Vec4f v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }),
                Vec6f v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }),
                Vec2d v => new InputArray(new[] { v.Item0, v.Item1 }),
                Vec3d v => new InputArray(new[] { v.Item0, v.Item1, v.Item2 }),
                Vec4d v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3 }),
                Vec6d v => new InputArray(new[] { v.Item0, v.Item1, v.Item2, v.Item3, v.Item4, v.Item5 }),
                _ => throw new ArgumentException($"Not supported type: '{vec.GetType().Name}'", nameof(vec))
            });
Пример #5
0
        public void Start(cv.Mat color, cv.Mat result1, int filterSize, int levels)
        {
            int[] intensityBin = new int[levels];

            int filterOffset = (filterSize - 1) / 2;
            int currentIntensity = 0, maxIntensity = 0, maxIndex = 0;

            for (int offsetY = filterOffset; offsetY < color.Height - filterOffset; offsetY++)
            {
                for (int offsetX = filterOffset; offsetX < color.Width - filterOffset; offsetX++)
                {
                    maxIntensity = maxIndex = 0;

                    intensityBin = new int[levels];
                    cv.Vec3i[] bins = new cv.Vec3i[levels];

                    for (int y = offsetY - filterOffset; y < offsetY + filterOffset; y++)
                    {
                        for (int x = offsetX - filterOffset; x < offsetX + filterOffset; x++)
                        {
                            cv.Vec3b rgb = color.Get <cv.Vec3b>(y, x);
                            currentIntensity = (int)(Math.Round((Double)(rgb.Item0 + rgb.Item1 + rgb.Item2) / 3.0 * (levels - 1)) / 255.0);

                            intensityBin[currentIntensity] += 1;
                            bins[currentIntensity].Item0   += rgb.Item0;
                            bins[currentIntensity].Item1   += rgb.Item1;
                            bins[currentIntensity].Item2   += rgb.Item2;

                            if (intensityBin[currentIntensity] > maxIntensity)
                            {
                                maxIntensity = intensityBin[currentIntensity];
                                maxIndex     = currentIntensity;
                            }
                        }
                    }

                    if (maxIntensity == 0)
                    {
                        maxIntensity = 1;
                    }
                    double blue  = bins[maxIndex].Item0 / maxIntensity;
                    double green = bins[maxIndex].Item1 / maxIntensity;
                    double red   = bins[maxIndex].Item2 / maxIntensity;

                    result1.Set <cv.Vec3b>(offsetY, offsetX, new cv.Vec3b(ClipByte(blue), ClipByte(green), ClipByte(red)));
                }
            }
        }
        // Use this for initialization
        void Start()
        {
            Mat mat = Unity.TextureToMat(this.texture);

            for (int yi = 0; yi < mat.Height; yi++)
            {
                for (int xi = 0; xi < mat.Width; xi++)
                {
                    Vec3b v = mat.At <Vec3b>(yi, xi);
                    v[0] = (byte)(ReduceColor(v[0]));
                    v[1] = (byte)(ReduceColor(v[1]));
                    v[2] = (byte)(ReduceColor(v[2]));
                    mat.Set <Vec3b>(yi, xi, v);
                }
            }
            Texture2D changedTex = Unity.MatToTexture(mat);

            GetComponent <RawImage>().texture = changedTex;
        }
        // Use this for initialization
        void Start()
        {
            Mat mat = Unity.TextureToMat(this.texture);

            for (int yi = 0; yi < 16; yi++)
            {
                for (int xi = 0; xi < 16; xi++)
                {
                    Vec3b max = new Vec3b();
                    for (int yj = 0; yj < 8; yj++)
                    {
                        for (int xj = 0; xj < 8; xj++)
                        {
                            Vec3b v = mat.At <Vec3b>(yi * 8 + yj, xi * 8 + xj);
                            if (max[0] < v[0])
                            {
                                max[0] = v[0];
                            }
                            if (max[1] < v[1])
                            {
                                max[1] = v[1];
                            }
                            if (max[2] < v[2])
                            {
                                max[2] = v[2];
                            }
                        }
                    }
                    for (int yj = 0; yj < 8; yj++)
                    {
                        for (int xj = 0; xj < 8; xj++)
                        {
                            mat.Set <Vec3b>(yi * 8 + yj, xi * 8 + xj, max);
                        }
                    }
                }
            }
            Texture2D changedTex = Unity.MatToTexture(mat);

            GetComponent <RawImage>().texture = changedTex;
        }
        // Use this for initialization
        void Start()
        {
            Mat mat         = Unity.TextureToMat(this.texture);
            Mat changedMat  = new Mat();
            Mat changedMat1 = new Mat();

            Cv2.CvtColor(mat, changedMat, ColorConversionCodes.BGR2HSV);
            for (int yi = 0; yi < mat.Height; yi++)
            {
                for (int xi = 0; xi < mat.Width; xi++)
                {
                    Vec3b v = changedMat.At <Vec3b>(yi, xi);
                    Debug.Log(v[0]);
                    v[0] = (byte)((v[0] - 180) % 360);
                    changedMat.Set <Vec3b>(yi, xi, v);
                }
            }
            Cv2.CvtColor(changedMat, changedMat1, ColorConversionCodes.HSV2BGR);
            Texture2D changedTex = Unity.MatToTexture(changedMat1);

            GetComponent <RawImage>().texture = changedTex;
        }
        // Use this for initialization
        void Start()
        {
            Mat mat = Unity.TextureToMat(this.texture);

            for (int yi = 0; yi < 16; yi++)
            {
                for (int xi = 0; xi < 16; xi++)
                {
                    Vector3 sum = new Vector3();
                    for (int yj = 0; yj < 8; yj++)
                    {
                        for (int xj = 0; xj < 8; xj++)
                        {
                            Vec3b v = mat.At <Vec3b>(yi * 8 + yj, xi * 8 + xj);
                            sum[0] += v[0];
                            sum[1] += v[1];
                            sum[2] += v[2];
                        }
                    }
                    Debug.Log(sum[0]);
                    Vec3b ave = new Vec3b();
                    ave[0] = (byte)(sum[0] / 64);
                    ave[1] = (byte)(sum[1] / 64);
                    ave[2] = (byte)(sum[2] / 64);

                    for (int yj = 0; yj < 8; yj++)
                    {
                        for (int xj = 0; xj < 8; xj++)
                        {
                            mat.Set <Vec3b>(yi * 8 + yj, xi * 8 + xj, ave);
                        }
                    }
                }
            }
            Texture2D changedTex = Unity.MatToTexture(mat);

            GetComponent <RawImage>().texture = changedTex;
        }
Пример #10
0
 public static extern ExceptionStatus core_FileStorage_shift_Vec3b(IntPtr fs, Vec3b val);
Пример #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(Vec3b other)
 {
     return(Item0 == other.Item0 && Item1 == other.Item1 && Item2 == other.Item2);
 }
 public static extern void core_FileStorage_shift_Vec3b(IntPtr fs, Vec3b val);
Пример #13
0
 public static void Run(IntPtr ptr, Vec3b v) => NativeMethods.core_Mat_push_back_Vec3b(ptr, v);
 public static extern ExceptionStatus core_FileNode_read_Vec3b(IntPtr node, out Vec3b returnValue);
 public static extern ExceptionStatus core_Mat_push_back_Vec3b(IntPtr self, Vec3b v);
Пример #16
0
 public static extern void core_Mat_push_back_Vec3b(IntPtr self, Vec3b v);
        // Use this for initialization
        void Start()
        {
            Mat mat = Unity.TextureToMat(this.texture);

            float[] results = new float[256];
            float[,] grs = new float[mat.Height, mat.Width];
            for (int yi = 0; yi < mat.Height; yi++)
            {
                for (int xi = 0; xi < mat.Width; xi++)
                {
                    Vec3b v  = mat.At <Vec3b>(yi, xi);
                    float gr = 0.2126f * v[2] + 0.7152f * v[1] + 0.0722f * v[0];
                    grs[yi, xi] = gr;
                }
            }
            for (int thi = 1; thi < 255; thi++)
            {
                int   w0 = 0;
                int   w1 = 0;
                float M0 = 0;
                float M1 = 0;
                foreach (float gr in grs)
                {
                    if (gr < thi)
                    {
                        w0++;
                        M0 += gr;
                    }
                    else
                    {
                        w1++;
                        M1 += gr;
                    }
                }
                Debug.Log(w0 + w1);
                float tmp0 = w0 == 0 ? 0 : M0 / w0;
                float tmp1 = w1 == 0 ? 0 : M1 / w1;
                results[thi] = ((float)w0 / (mat.Height * mat.Width)) * ((float)w1 / (mat.Height * mat.Width)) * Mathf.Pow(tmp0 - tmp1, 2);
            }
            int z = 0;

            for (int i = 1; i < 255; i++)
            {
                if (results[i] > results[z])
                {
                    z = i;
                }
            }
            for (int yi = 0; yi < mat.Height; yi++)
            {
                for (int xi = 0; xi < mat.Width; xi++)
                {
                    if (grs[yi, xi] < z)
                    {
                        Vec3b v = new Vec3b();
                        v[0] = (byte)0; v[1] = (byte)0; v[2] = (byte)0;
                        mat.Set <Vec3b>(yi, xi, v);
                    }
                    else
                    {
                        Vec3b v = new Vec3b();
                        v[0] = (byte)255; v[1] = (byte)255; v[2] = (byte)255;
                        mat.Set <Vec3b>(yi, xi, v);
                    }
                }
            }
            Texture2D changedTex = Unity.MatToTexture(mat);

            GetComponent <RawImage>().texture = changedTex;
        }