Esempio n. 1
0
        private static Bitmap GetBitmapFrom(AreaRect source)
        {
            int size = (int)Math.Sqrt(source.Pixels.Count());

            Bitmap tmp   = new Bitmap(size, size);
            int    index = 0;

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    var   val   = source.Pixels[index];
                    Color color = Color.FromArgb(255, val, val, val);
                    tmp.SetPixel(x, y, color);
                    index++;
                }
            }

            return(tmp);
        }
Esempio n. 2
0
 public AreaRectGroup(AreaRect leftArea, AreaRect rightArea)
 {
     this.LeftAreaRect  = leftArea;
     this.RightAreaRect = rightArea;
 }
Esempio n. 3
0
        private static void VideoCaptureDevice_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            //  HistogramEqualization filter = new HistogramEqualization();
            //// ContrastCorrection filter2 = new ContrastCorrection(int.MaxValue);
            //BrightnessCorrection filter2 = new BrightnessCorrection(-50);
            //// process image
            // GammaCorrection filter = new GammaCorrection(0.8);
            // apply the filter



            if (countframe >= framerate)
            {
                Bitmap tmp = (Bitmap)eventArgs.Frame;
                //   filter.ApplyInPlace(tmp);

                //AreaRect wbArea = GetPixelsFromArea(tmp, 0, 0, 5, 5);
                //int tilt = (130 - wbArea.Pixels[0]);
                //BrightnessCorrection filter2 = new BrightnessCorrection(tilt);
                // filter2.ApplyInPlace(tmp);

                //   double tilt = (wbArea.Pixels[0] / 100 );

                //Color t = BwArea(tmp, 0, 0, 5);



                //Color t = GetBwColor(tmp);
                //tmp = ColorBalance(tmp, t.B, t.G, t.R);


                AreaRect leftUpArea  = GetPixelsFromArea(tmp, 0, 0, 96, 4, true);
                AreaRect RightUpArea = GetPixelsFromArea(tmp, 1184, 0, 96, 4, true);


                upArea = new AreaRectGroup(leftUpArea, RightUpArea);
                if (IsConfigurationMode)
                {
                    context.Post(PostImageConfig, MergeImage(GetBitmapFrom(leftUpArea), GetBitmapFrom(RightUpArea)));
                }
                else
                {
                    //YCbCrLinear filter = new YCbCrLinear();
                    //filter.InCb = new AForge.Range(-0.276f, 0.163f);
                    //filter.InCr = new AForge.Range(-0.202f, 0.500f);
                    //filter.ApplyInPlace(tmp);

                    //AreaRect wbArea = GetPixelsFromArea(tmp, 0, 0, 5, 5);
                    //int tilt = (100 - wbArea.Pixels[0]);
                    //BrightnessCorrection filter2 = new BrightnessCorrection(tilt);
                    //filter2.ApplyInPlace(tmp);

                    //Color t = BwArea(tmp, 0, 0, 10);
                    //tmp = ColorBalance(tmp, t.B, t.G, t.R);



                    //context.Post(PostImageConfig, new Bitmap(tmp, new Size(640, 480)));

                    if (CheckedArea())
                    {
                        if (!IsImageRecived)
                        {
                            context.Post(PostImage, new Bitmap(tmp, new Size(640, 480)));
                            StoreImage     = new Bitmap(tmp, new Size(32, 24));
                            IsImageRecived = true;
                        }
                        else
                        {
                            if (!CheckEqualsImage(new Bitmap(tmp, new Size(32, 24)), StoreImage))
                            {
                                IsImageRecived = false; ElapsedSec = 0;
                            }
                        }
                    }
                }

                countframe = 0;
            }
            countframe++;
        }