Ejemplo n.º 1
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());
            }
        }