using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV;
using Emgu.CV.Structure;
using bbiwarg.Detectors.Fingers;

using System.Diagnostics;
using bbiwarg.Utility;
using bbiwarg.Graphics;

namespace bbiwarg.Images
{
    class EdgeImage
    {
        public Image<Gray, Byte> Image { get; private set; }

        public EdgeImage(DepthImage depthImage)
        {
            Image = (depthImage.Image * (255.0f / (float)(depthImage.MaxDepth - depthImage.MinDepth))).Canny(100, 75, 3);
        }

        public EdgeImage(Image<Gray, Byte> edgeImage)
        {
            Image = edgeImage;
        }

        public bool isEdgeAt(Point point)
        {
            return isEdgeAt(point.X, point.Y);
        }

        public bool isEdgeAt(int x, int y)
        {
            return (Image.Data[y, x, 0] > 0);
        }

        public void removeFingerEdges(Finger finger)
        {
            Point[] polygon = finger.getPolygon();

            Image.FillConvexPoly(polygon, new Gray(0));
        }

        public EdgeImage copy()
        {
            return new EdgeImage(Image.Copy());
        }
    }
}
