Пример #1
0
        private byte patternMatch(int r, int c)
        {
            //  А теперь перебрать и попробовать наложение с различными заготовками
            AForge.Imaging.Filters.Difference DiffFilter = new AForge.Imaging.Filters.Difference(finalPics[r, c]);

            int  notBlack = int.MaxValue;
            byte pwr      = 0;

            for (byte i = 1; i < 14; ++i)
            {
                AForge.Imaging.ImageStatistics stat = new AForge.Imaging.ImageStatistics(DiffFilter.Apply(samples[i]));

                if (stat.PixelsCountWithoutBlack < notBlack)
                {
                    notBlack = stat.PixelsCountWithoutBlack;
                    pwr      = i;
                }
            }
            return(pwr);
        }
Пример #2
0
        private void Histogram_Load(object sender, EventArgs e)
        {
            stat1             = new AForge.Imaging.ImageStatistics(citraawal);
            stat2             = new AForge.Imaging.ImageStatistics(citraAFCEDP);
            stat3             = new AForge.Imaging.ImageStatistics(citraACEDP);
            histogram1.Color  = Color.Black; histogram2.Color = Color.Black; histogram3.Color = Color.Black;
            hist1             = stat1.Red; hist2 = stat2.Red; hist3 = stat3.Red;
            histogram1.Values = hist1.Values; histogram2.Values = hist2.Values; histogram3.Values = hist3.Values;
            float aspect1 = Convert.ToSingle((float)citraawal.Width / (float)citraawal.Height);
            float aspect2 = Convert.ToSingle((float)citraAFCEDP.Width / (float)citraAFCEDP.Height);
            float aspect3 = Convert.ToSingle((float)citraACEDP.Width / (float)citraACEDP.Height);

            lbl_awal_aspect.Text = aspect1.ToString("F3"); lbl_AFCEDP_aspec.Text = aspect2.ToString("F3"); lbl_ACEDP_aspect.Text = aspect3.ToString("F3");
            lbl_awal_mean.Text   = stat1.Red.Mean.ToString("F3"); lbl_AFCEDP_mean.Text = stat2.Red.Mean.ToString("F3"); lbl_ACEDP_mean.Text = stat3.Red.Mean.ToString("F3");
            lbl_awal_median.Text = stat1.Red.Median.ToString(); lbl_AFCEDP_median.Text = stat2.Red.Median.ToString(); lbl_ACEDP_median.Text = stat3.Red.Median.ToString();
            lbl_awal_Min.Text    = stat1.Red.Min.ToString(); lbl_AFCEDP_Min.Text = stat2.Red.Min.ToString(); lbl_ACEDP_min.Text = stat3.Red.Min.ToString();
            lbl_awal_max.Text    = stat1.Red.Max.ToString(); lbl_AFCEDP_Max.Text = stat2.Red.Max.ToString(); lbl_ACEDP_max.Text = stat3.Red.Max.ToString();
            lbl_awal_pixels.Text = stat1.Red.TotalCount.ToString(); lbl_AFCEDP_pixels.Text = stat1.Red.TotalCount.ToString(); lbl_ACEDP_pixels.Text = stat1.Red.TotalCount.ToString();
            double stddev1 = AForge.Math.Statistics.StdDev(hist1.Values); double stddev2 = AForge.Math.Statistics.StdDev(hist2.Values); double stddev3 = AForge.Math.Statistics.StdDev(hist3.Values);

            lbl_awal_std.Text = stddev1.ToString("F3"); lbl_AFCEDP_std.Text = stddev2.ToString("F3"); lbl_ACEDP_std.Text = stddev3.ToString("F3");
        }
Пример #3
0
            /// <summary> buffer callback, COULD BE FROM FOREIGN THREAD. </summary>
            int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
            {
                Bitmap bitmap = new Bitmap(m_videoWidth, m_videoHeight, m_stride, PixelFormat.Format24bppRgb, pBuffer);
                bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
                // byte[] bmp = ByteTools.BmpToBytes(bitmap, PixelFormat.Format24bppRgb);
                VisionMessage vm = new VisionMessage(m_videoHeight, m_videoWidth, ByteTools.pixelFormatToBPP(PixelFormat.Format24bppRgb), bitmap);
                msgService.sendMsg(vm);
                //Thread.Sleep((int)(videoInfoHeader.AvgTimePerFrame / 10000));

                if (Constants.EVALUATE_SUCCESS_ENABLED)
                {
                    string tmp = (string)Globals.FRAME_SIGN_HASH["" + Globals.CURRENT_FRAME_INDEX];
                    if (tmp != null)
                    {   // 3 seconds passed. Now there is another sign in the video.
                        if (!Globals.SIGN_IN_FRAME.Contains(Constants.NO_SIGN) && !Globals.SIGN_IN_FRAME_IS_DETECTED)
                        {
                            Globals.NUMBER_OF_MISSES++;
                            Console.WriteLine("MISS:" + Globals.SIGN_IN_FRAME.Substring(Globals.SIGN_IN_FRAME.IndexOf(',')+1));
                            if (currentFrame!=null && (Constants.HARVEST_TYPE == Constants.HarvestType.harvestAll || Constants.HARVEST_TYPE == Constants.HarvestType.harvestMisses))
                                currentFrame.Save(Constants.base_folder + "hasat\\" + Globals.HARVEST_SIGN_ID + "_miss.bmp");
                        }
                        Globals.SIGN_IN_FRAME = tmp;
                        Globals.SIGN_IN_FRAME_IS_DETECTED = false;
                    }
                }
                else if (Constants.LABELING_ENABLED)
                {
                    AForge.Imaging.ImageStatistics statistics = new AForge.Imaging.ImageStatistics(bitmap);
                    if (Math.Abs(Globals.CURRENT_R_MEAN - Math.Round(statistics.Red.Mean)) > 1 || Math.Abs(Globals.CURRENT_G_MEAN - Math.Round(statistics.Green.Mean)) > 1 || Math.Abs(Globals.CURRENT_B_MEAN - Math.Round(statistics.Blue.Mean)) > 2)
                    {
                        Globals.CURRENT_R_MEAN = (int)Math.Round(statistics.Red.Mean);
                        Globals.CURRENT_G_MEAN = (int)Math.Round(statistics.Green.Mean);
                        Globals.CURRENT_B_MEAN = (int)Math.Round(statistics.Blue.Mean);
                    }
                }
                if (Globals.FRAME_COUNT == Globals.CURRENT_FRAME_INDEX)
                {
                    Globals.init();
                }
                else
                {
                    Globals.CURRENT_FRAME_INDEX++;
                }

                currentFrame = bitmap;
                return 0;
            }
Пример #4
0
 private void button39_Click(object sender, EventArgs e)
 {
     AForge.Imaging.ImageStatistics stat = new AForge.Imaging.ImageStatistics(WatermarkedImage);
      //red = stat.Red;
 }