Esempio n. 1
0
 public static void SimpleShowPicture(Form theFormCalling, Image Image2Show, bool NormalizeImage = false)
 {
     if (theFormCalling.InvokeRequired)
     {
         SimpleShowPictureCallback d = SimpleShowPicture;
         theFormCalling.Invoke(d, new object[] { theFormCalling, Image2Show, NormalizeImage });
     }
     else
     {
         SimpleShowImageForm imgShowForm = new SimpleShowImageForm(Image2Show);
         imgShowForm.Show();
     }
 }
        public void DetectConnected()
        {
            var classificator = new SkyCloudClassification(processingImage, defaultProperties);

            classificator.Classify();
            DenseMatrix        dmSkyIndexDataBinary  = classificator.dmSkyIndexDataBinary();
            Image <Gray, Byte> imgSkyIndexDataBinary = ImageProcessing.grayscaleImageFromDenseMatrixWithFixedValuesBounds(dmSkyIndexDataBinary, 0.0d, 1.0d, true);

            imgSkyIndexDataBinary = imgSkyIndexDataBinary.Mul(classificator.maskImage);
            Image <Bgr, Byte> previewImage = imgSkyIndexDataBinary.CopyBlank().Convert <Bgr, Byte>();


            // Contour<Point> contoursDetected = imgSkyIndexDataBinary.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST);

            #region // EmguCV 3.0
            //VectorOfVectorOfPoint contoursDetected = new VectorOfVectorOfPoint();
            //CvInvoke.FindContours(imgSkyIndexDataBinary, contoursDetected, null, Emgu.CV.CvEnum.RetrType.List,
            //    Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
            //contoursArray = new List<VectorOfPoint>();
            //int count = contoursDetected.Size;
            //var colorGen = new RandomPastelColorGenerator();
            //for (int i = 0; i < count; i++)
            //{
            //    Color currentColor = colorGen.GetNext();
            //    var currentColorBgr = new Bgr(currentColor.B, currentColor.G, currentColor.R);
            //    using (VectorOfPoint currContour = contoursDetected[i])
            //    {
            //        contoursArray.Add(currContour);
            //        previewImage.Draw(currContour.ToArray(), currentColorBgr, -1); //.Draw(currContour, currentColorBgr, -1);
            //    }
            //}
            #endregion // EmguCV 3.0


            List <Contour <Point> >    contoursDetected = imgSkyIndexDataBinary.DetectContours();
            RandomPastelColorGenerator colorGen         = new RandomPastelColorGenerator();
            foreach (Contour <Point> currContour in contoursDetected)
            {
                Color currentColor    = colorGen.GetNext();
                Bgr   currentColorBgr = new Bgr(currentColor.B, currentColor.G, currentColor.R);
                previewImage.Draw(currContour, currentColorBgr, -1);
            }


            ThreadSafeOperations.SetTextTB(tbLog, "Количество выделенных объектов: " + contoursArray.Count + Environment.NewLine, true);


            //ShowImageForm ImgShow = new ShowImageForm(localPreviewBitmap, ParentForm, this);
            var imgShow = new SimpleShowImageForm(previewImage);
            imgShow.Show();
        }
        static void bgwShowPicture_DoWork(object sender, DoWorkEventArgs e)
        {
            object[]            args                 = e.Argument as object[];
            string              pictureTitle         = args[1] as string;
            object              img                  = args[0];
            int                 timeout              = Convert.ToInt32(args[2]);
            SimpleShowImageForm SimpleShowImageForm1 = new SimpleShowImageForm();

            if (img.GetType() == typeof(Image <Bgr, byte>))
            {
                Image <Bgr, byte> imgToShow = img as Image <Bgr, byte>;
                SimpleShowImageForm1 = new SimpleShowImageForm(imgToShow, pictureTitle);
                SimpleShowImageForm1.Show();

                Application.DoEvents();

                Thread.Sleep(timeout);
                //SimpleShowImageForm1.Close();
                //SimpleShowImageForm1.Dispose();
            }
            else if (img.GetType() == typeof(Image <Gray, byte>))
            {
                Image <Gray, byte> imgToShow = img as Image <Gray, byte>;
                SimpleShowImageForm1 = new SimpleShowImageForm(imgToShow, pictureTitle);
                SimpleShowImageForm1.Show();

                Application.DoEvents();

                Thread.Sleep(timeout);
                //SimpleShowImageForm1.Close();
                //SimpleShowImageForm1.Dispose();
            }
            else if (img.GetType() == typeof(Image))
            {
                Image imgToShow = img as Image;
                SimpleShowImageForm1 = new SimpleShowImageForm(imgToShow, pictureTitle);
                SimpleShowImageForm1.Show();

                Application.DoEvents();

                Thread.Sleep(timeout);
                //SimpleShowImageForm1.Close();
                //SimpleShowImageForm1.Dispose();
            }

            e.Result = new object[] { SimpleShowImageForm1 };
        }
        public static void ShowPicture(Image <Gray, byte> imgToShow, string pictureTitle = "")
        {
            SimpleShowImageForm SimpleShowImageForm1 = new SimpleShowImageForm(imgToShow, pictureTitle);

            SimpleShowImageForm1.Show();
        }
        public static void ShowPicture(Image image2show, string pictureTitle = "")
        {
            SimpleShowImageForm SimpleShowImageForm1 = new SimpleShowImageForm(image2show, pictureTitle);

            SimpleShowImageForm1.Show();
        }