Пример #1
0
        public static List <Stack> processFrame(Image <Bgr, Byte> img)
        {
            Dictionary <Stack, List <Rectangle> > correlatedFinds = new Dictionary <Stack, List <Rectangle> >();

            foreach (Rectangle rect in Instance.foundThisFrame)
            {
                if (!correlateRectangles(rect, correlatedFinds))
                {
                    Stack stack = new Stack();
                    stack.location         = rect;
                    correlatedFinds[stack] = new List <Rectangle>();
                    correlatedFinds[stack].Add(rect);
                }
            }
            foreach (Stack stack in correlatedFinds.Keys)
            {
                List <Bgr> colorSamples = new List <Bgr>();
                trimRange(stack, correlatedFinds[stack]);
                stack.samplePoints = pickColorPoints(stack.location);
                foreach (Point point in stack.samplePoints)
                {
                    colorSamples.Add(img[point]);
                }
                stack.color = ColorFinder.guessColor(colorSamples.ToArray());
            }
            Instance.foundThisFrame.Clear();
            return(new List <Stack>(correlatedFinds.Keys));
        }
Пример #2
0
        public static void trainChip(Image <Bgr, Byte> img, Point[] samplePoints, Stack.Color color)
        {
            List <Bgr> colorSamples = new List <Bgr>();

            foreach (Point point in samplePoints)
            {
                colorSamples.Add(img[point]);
            }
            ColorFinder.addTrainingPoint(colorSamples.ToArray(), color);
        }
Пример #3
0
 private void button6_Click(object sender, EventArgs e)
 {
     ColorFinder.retrain();
 }
Пример #4
0
        public void findChips()
        {
            try
            {
                //CudaImage<Bgr,Byte> gpuImg = new CudaImage<Bgr,Byte>(sourceImage);
                //VectorOfGpuMat outVec = new VectorOfGpuMat();
                //CudaGaussianFilter gaussFilter = new CudaGaussianFilter(DepthType.new Size(11,11),0.8,0.8,BorderType.Constant,BorderType.Constant);
                //gaussFilter.Apply(gpuImg, gpuImg, null);
                diagnosticImage = sourceImage.Clone();
                Rectangle[] rects = cc.DetectMultiScale(sourceImage.Convert <Gray, Byte>(), 1.1, 4, new System.Drawing.Size(10, 10));
                //cc.ScaleFactor = 1.1;
                //cc.MinNeighbors = 4;
                //cc.MinObjectSize = new Size(10, 10);
                //cc.DetectMultiScale(gpuImg.Convert<Gray, Byte>(), outVec);
                //Rectangle[] rects = cc.Convert(outVec);

                foreach (Rectangle rect in rects)
                {
                    StackRegistry.stackFound(rect);
                }

                List <Stack> processedStacks = StackRegistry.processFrame(sourceImage);

                if (foundChipColor != null)
                {
                    if (processedStacks.Count == 1)
                    {
                        ColorFinder.trainChip(sourceImage, processedStacks[0].samplePoints, (Stack.Color)foundChipColor);
                    }
                }

                foreach (Stack stack in processedStacks)
                {
                    Bgr col = new Bgr(Color.Magenta);
                    switch (stack.color)
                    {
                    case Stack.Color.Black:
                        col = new Bgr(Color.Black);
                        break;

                    case Stack.Color.Blue:
                        col = new Bgr(Color.Blue);
                        break;

                    case Stack.Color.Red:
                        col = new Bgr(Color.Red);
                        break;

                    case Stack.Color.Green:
                        col = new Bgr(Color.Green);
                        break;

                    case Stack.Color.White:
                        col = new Bgr(Color.White);
                        break;
                    }
                    diagnosticImage.Draw(stack.location, col, 2);
                    foreach (Point sample in stack.samplePoints)
                    {
                        diagnosticImage.Draw(new Rectangle(sample, new Size(1, 1)), new Bgr(System.Drawing.Color.Yellow), 2);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace.ToString());
            }
        }