public IHttpActionResult GetImages(int id, int catid)
        {
            List <COMimage> list;

            //if the call was made to get the users image
            if (catid != -1)
            {
                list = BLLimage.Getimages().FindAll(img => img.CategoryID == catid);
            }
            else
            {
                //time is current page number in this category images
                list = BLLimage.Getimages().FindAll(img => img.UserId == id);
            }
            if (list == null)
            {
                return(BadRequest("fail to load images"));
            }
            if (list.Count > 0)
            {
                return(Ok(ImageMat.CreateMat(list, true)));
            }
            else
            {
                return(BadRequest("no more pictures for this category."));
            }
        }
示例#2
0
 private void ShowImage <T>(ImageMat <T> imageMat)
     where T : struct
 {
     image.Height = imageMat.Height;
     image.Width  = imageMat.Width;
     image.Source = imageMat.ToWriteableBitmap();
 }
示例#3
0
        public static WriteableBitmap ToWriteableBitmap <T>(this ImageMat <T> image) where T : struct
        {
            WriteableBitmap bitmap = new WriteableBitmap(image.Width, image.Height, 96, 96, PixelFormats.Bgr24, null);

            bitmap.WritePixels(new System.Windows.Int32Rect(0, 0, image.Width, image.Height), image.ToBGRBytes(), image.Width * 3, 0);
            return(bitmap);
        }
        public void Apply()
        {
            var             image  = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(ImageMat);
            int             dpi    = 96;
            WriteableBitmap bitmap = new WriteableBitmap(image.Width, image.Height, dpi, dpi, PixelFormats.Pbgra32, null);

            using (var stream = ImageMat.ToMemoryStream())
            {
                Image.Value = BitmapFrame.Create(stream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
            }
        }
示例#5
0
        private void ProcessImage()
        {
            if (null == this.ImageMat)
            {
                return;
            }

            try
            {
                CvInvoke.GaussianBlur(this.ImageMat, this.ImageMat, new System.Drawing.Size(5, 5), 0);

                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "MicroMeterCalibrator_GaussianBlur");
                CvInvoke.AdaptiveThreshold(this.ImageMat, this.ImageMat, 255, Emgu.CV.CvEnum.AdaptiveThresholdType.MeanC, Emgu.CV.CvEnum.ThresholdType.BinaryInv, 59, this.AdaptiveThresholdConstant);
                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "MicroMeterCalibrator_AdaptiveThreshold");
                Contours = new VectorOfVectorOfPoint();
                var hierarchy = new Mat();
                CvInvoke.FindContours(this.ImageMat, Contours, hierarchy, Emgu.CV.CvEnum.RetrType.List, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
                var dims = Contours.Size;
                for (var idx = 0; idx < dims; idx++)
                {
                    var con = Contours[idx];
                    if (!(CvInvoke.ContourArea(con) < 800))
                    {
                        continue;
                    }
                    var color = new MCvScalar(0, 0, 0);
                    CvInvoke.FillConvexPoly(this.ImageMat, con, color);
                }

                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "MicroMeterCalibrator_FillConvexPoly");
                var kernelMat1 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new System.Drawing.Size(3, 3), new System.Drawing.Point(-1, -1));
                CvInvoke.MorphologyEx(
                    this.ImageMat,
                    this.ImageMat,
                    Emgu.CV.CvEnum.MorphOp.Open,
                    kernelMat1,
                    new System.Drawing.Point(-1, -1),
                    1, Emgu.CV.CvEnum.BorderType.Default,
                    new MCvScalar());
                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "MicroMeterCalibrator_MorphologyEx_Open");
                var kernelMat2 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(7, 7), new System.Drawing.Point(-1, -1));
                CvInvoke.MorphologyEx(
                    this.ImageMat,
                    this.ImageMat,
                    Emgu.CV.CvEnum.MorphOp.Close,
                    kernelMat2,
                    new Point(-1, -1),
                    2,
                    Emgu.CV.CvEnum.BorderType.Default,
                    new MCvScalar());
                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "MicroMeterCalibrator_MorphologyEx_Close");
                CvInvoke.FindContours(this.ImageMat, Contours, hierarchy, Emgu.CV.CvEnum.RetrType.Tree, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
                ContoursToMeasure = new VectorOfVectorOfPoint();
                ContourImageMat   = new Mat(this.ImageMat.Rows, this.ImageMat.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 4);
                MainWindow.ImageProcessorExaminer.AddImage(ContourImageMat.CreateNewHardCopyFromMat(), "MicroMeterCalibrator_ContourImageMat");
                dims = Contours.Size;

                for (var idx = 0; idx < dims; idx++)
                {
                    var con = Contours[idx];
                    if (CvInvoke.ContourArea(con) < 300)
                    {
                        continue;
                    }
                    if ((int)hierarchy.GetData().GetValue(0, idx, 3) < 0)
                    {
                        continue;
                    }
                    ContoursToMeasure.Push(con);
                    CvInvoke.DrawContours(ContourImageMat, Contours, 0, new MCvScalar(0, 255, 0, 255), 1);

                    var rect = CvInvoke.MinAreaRect(con);
                    this.BoundingBoxes.Add(rect);
                }

                MainWindow.ImageProcessorExaminer.AddImage(ContourImageMat.CreateNewHardCopyFromMat(), "MicroMeterCalibratorContourImageMat_2");
                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "MicroMeterCalibrator_PutText");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
示例#6
0
 internal MatLine(ImageMat <T> imageMat, int line)
 {
     this.imageMat = imageMat;
     this.line     = line;
 }
示例#7
0
        public void Process()
        {
            if (null == this.ImageMat)
            {
                return;
            }

            try
            {
                this.OgImageMat = this.ImageMat.CreateNewHardCopyFromMat();

                //Itt megkellene nézni, hogy mik vannak minden enum mögött, hogy van-e jobb alternatíva
                //Blurring image
                var tempSize = new Size(5, 5);
                //Using input | output arrays instead of temp objects
                CvInvoke.GaussianBlur(this.ImageMat, this.ImageMat, tempSize, 0);

                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "ImageProcessor_GaussianBlur");
                //Adaptive threshold
                var tempAdaptiveThreshold = this.AdaptiveThresholdConstant;
                //Azt az 59-et majd meg kell lesni, hogy miért az van


                CvInvoke.AdaptiveThreshold(this.ImageMat, this.ImageMat, 255, Emgu.CV.CvEnum.AdaptiveThresholdType.MeanC, Emgu.CV.CvEnum.ThresholdType.BinaryInv, 59, this.AdaptiveThresholdConstant);
                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "ImageProcessor_AdaptiveThreshold");
                //Get contours and remove small patches
                Contours = new VectorOfVectorOfPoint();
                Mat hierarchy = new Mat();
                // meg kellene nézni miez ez a mat, vactorofvectorpoint és input, output és inoutputarrayek
                CvInvoke.FindContours(this.ImageMat, Contours, hierarchy, Emgu.CV.CvEnum.RetrType.List, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);

                var dims = Contours.Size;
                for (var idx = 0; idx < dims; idx++)
                {
                    var con = Contours[idx];
                    if (!(CvInvoke.ContourArea(con) < 800))
                    {
                        continue;
                    }
                    var color = new MCvScalar(0, 0, 0);
                    //CvInvoke.FillPoly(this.ImageMat, con, color);
                    //TODO ezt lehet meg kellene még vizsgálni
                    CvInvoke.FillConvexPoly(this.ImageMat, con, color);
                }

                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "ImageProcessor_FillConvexPoly");
                //Open then close to close gaps
                var kernelMat1 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
                CvInvoke.MorphologyEx(
                    this.ImageMat,
                    this.ImageMat,
                    Emgu.CV.CvEnum.MorphOp.Open,
                    kernelMat1,
                    new Point(-1, -1),
                    1, Emgu.CV.CvEnum.BorderType.Default,
                    new MCvScalar());
                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "ImageProcessor_MorphologyEx_Open");
                var kernelMat2 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(7, 7), new Point(-1, -1));
                CvInvoke.MorphologyEx(
                    this.ImageMat,
                    this.ImageMat,
                    Emgu.CV.CvEnum.MorphOp.Close,
                    kernelMat2,
                    new Point(-1, -1),
                    2,
                    Emgu.CV.CvEnum.BorderType.Default,
                    new MCvScalar());
                MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "ImageProcessor_MorphologyEx_Close");
                //Get new contours find the correct ones by size and hierarchy draw them onto the img, draw bounding box, and length
                CvInvoke.FindContours(this.ImageMat, Contours, hierarchy, Emgu.CV.CvEnum.RetrType.Tree, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
                //Empty out objects contours
                ContoursToReturn = new VectorOfVectorOfPoint();
                //Image to be overlayed, with alpha values
                //ContourImageMat = new Mat(this.ImageMat.Rows, this.ImageMat.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 4);
                ContourImageMat = OgImageMat.CreateNewHardCopyFromMat();
                CvInvoke.CvtColor(ContourImageMat, ContourImageMat, ColorConversion.Gray2Bgr);
                //ContourImageMat = new Mat(this.ImageMat.Rows, this.ImageMat.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
                //MainWindow.ImageProcessorExaminer.AddImage(ContourImageMat.CreateNewHardCopyFromMat(), "ImageProcessor_ContourImageMat");
                dims = Contours.Size;

                var tempVoVoPointF = new VectorOfVectorOfPointF();

                for (var idx = 0; idx < dims; idx++)
                {
                    var con = Contours[idx];
                    //Skip small patches
                    if (CvInvoke.ContourArea(con) < 300)
                    {
                        continue;
                    }
                    //Only use ones that have parents, so the inner ones
                    //https://stackoverflow.com/questions/41560048/c-sharp-emgu-cv-findcontours-hierarchy-data-always-null
                    //https://stackoverflow.com/questions/37408481/navigate-through-hierarchy-of-contours-found-by-findcontours-method/37470968#37470968
                    //http://www.emgu.com/forum/viewtopic.php?t=6333
                    //http://www.emgu.com/forum/viewtopic.php?f=7&t=5263
                    //https://stackoverrun.com/fr/q/11437249
                    if ((int)hierarchy.GetData().GetValue(0, idx, 3) < 0)
                    {
                        continue;
                    }
                    ContoursToReturn.Push(con);
                    //UprightBoundingRectangles.Add(CvInvoke.BoundingRectangle(con));
                    //CvInvoke.DrawContours(ContourImageMat, Contours, 0, new MCvScalar(0, 255, 0, 255), 2);
                    CvInvoke.DrawContours(ContourImageMat, Contours, -1, new MCvScalar(0, 255, 0, 255), 1);

                    var rect   = CvInvoke.MinAreaRect(con);
                    var box    = CvInvoke.BoxPoints(rect);
                    var boxVec = new VectorOfPointF(box);
                    tempVoVoPointF.Push(boxVec);

                    /*
                     * var rect = CvInvoke.MinAreaRect(con);
                     * //var box = CvInvoke.BoxPoints(rect);
                     * //VectorOfPointF boxVec = new VectorOfPointF(box);
                     * VectorOfVectorOfPoint boxVec = new VectorOfVectorOfPoint(con);
                     * //az jókérdés, hogy ez most a megfelelő alak-e vagy sem
                     * CvInvoke.DrawContours(ContourImageMat, boxVec, 0, new MCvScalar(0, 255, 0, 255), 2);
                     */
                }
                MainWindow.ImageProcessorExaminer.AddImage(ContourImageMat.CreateNewHardCopyFromMat(), "ImageProcessor_ContourImageMat");
                this.AngledBoundingBoxesToReturn = tempVoVoPointF.ConvertToVectorOfPoint();

                MainWindow.ImageProcessorExaminer.AddImage(ContourImageMat.CreateNewHardCopyFromMat(), "ImageProcessor_ContourImageMat_2");
                //CvInvoke.PutText(this.ImageMat, "{" + ContoursToReturn.Size + "}", new Point(100, 300), Emgu.CV.CvEnum.FontFace.HersheySimplex, 8.0, new MCvScalar(255), 5);
                //this.DetectedCellCount = ContoursToReturn.Size;
                //MainWindow.ImageProcessorExaminer.AddImage(ImageMat.CreateNewHardCopyFromMat(), "ImageProcessor_PutText");
                //CvInvoke.EqualizeHist(this.ImageMat,this.ImageMat);

                //new PopupImage(ImageMat, "ImgProcessor_ImageMat").Show();
                //new PopupImage(ContourImageMat, "ImgProcessor_ContourImageMat").Show();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }