Пример #1
0
        public IplImage PostProcess(IplImage preProcessedImage, IplImage postProcessedImage)
        {
            using (CvMemStorage storage = new CvMemStorage())
            {
                CvSeq seq   = preProcessedImage.HoughLines2(storage, HoughLinesMethod.Probabilistic, 1, Math.PI / 180, 30, 40, 15);
                var   lines = new List <CvLineSegmentPoint>();
                for (int i = 0; i < seq.Total; i++)
                {
                    var cvLineSegmentPoint = seq.GetSeqElem <CvLineSegmentPoint>(i);
                    if (cvLineSegmentPoint != null)
                    {
                        lines.Add(cvLineSegmentPoint.Value);
                    }
                }

                var groupedLines = RectangleFinder.GroupSegments(lines);

                var rects = RectangleFinder.Convert(groupedLines);
                RectangleFinder.Filter(rects);

                foreach (var cvRect in rects)
                {
                    postProcessedImage.Rectangle(cvRect, CvColor.Red, 3, LineType.AntiAlias);
                }

                //for (int i = 0; i < groupedLines.Count; i++)
                //{
                //    var color = new CvColor(i*255/max,i*255/max,i*255/max);
                //    var group = groupedLines[i];
                //    for (int j = 0; j < group.Lines.Count; j++)
                //    {
                //        CvLineSegmentPoint elem = group.Lines[j];
                //        imgHough.Line(elem.P1, elem.P2, color, 3, LineType.AntiAlias, 0);
                //    }

                //}


                //Console.WriteLine(groupedLines.Count);

                CvSeq <CvCircleSegment> seq1 = preProcessedImage.HoughCircles(storage,
                                                                              HoughCirclesMethod.Gradient, 1,
                                                                              //imgGray.Size.Height / 8, 150, 55, 0, 50);
                                                                              15, 100, 30, 9, 51);

                foreach (CvCircleSegment item in seq1)
                {
                    postProcessedImage.Circle(item.Center, (int)item.Radius, CvColor.Red, 3);
                }
            }
            return(postProcessedImage);
        }
Пример #2
0
        public void BackgroundTest(string exeFileName, string commandLineParameter, bool expectedBackground)
        {
            HtmlToPdfRunner runner = new HtmlToPdfRunner(exeFileName);

            string html = @"<!DOCTYPE html>
<html>
  <head>
  </head>
  <body style=""background-color:blue;"">
   Test Page
  </body>
</html>";

            using (TempHtmlFile htmlFile = new TempHtmlFile(html))
            {
                using (TempPdfFile pdfFile = new TempPdfFile(this.TestContext))
                {
                    string commandLine = string.Empty;

                    if (!string.IsNullOrEmpty(commandLineParameter))
                    {
                        commandLine += $"{commandLineParameter} ";
                    }

                    commandLine += $"\"{htmlFile.FilePath}\" \"{pdfFile.FilePath}\"";
                    HtmlToPdfRunResult result = runner.Run(commandLine);
                    Assert.AreEqual(0, result.ExitCode, result.Output);

                    using (PdfReader pdfReader = new PdfReader(pdfFile.FilePath))
                    {
                        using (PdfDocument pdfDocument = new PdfDocument(pdfReader))
                        {
                            int pageCount = pdfDocument.GetNumberOfPages();
                            Assert.AreEqual(1, pageCount);

                            PdfPage page = pdfDocument.GetPage(1);

                            RectangleFinder rectangleFinder = new RectangleFinder();

                            PdfCanvasProcessor processor = new PdfCanvasProcessor(rectangleFinder);
                            processor.ProcessPageContent(page);

                            ICollection <Rectangle> boxes = rectangleFinder.GetBoundingBoxes();

                            Assert.AreEqual(expectedBackground ? 1 : 0, boxes.Count());
                        }
                    }
                }
            }
        }
Пример #3
0
        private void Snap(object arg)
        {
            object[] argarr = arg as object[];
            IEnumerable <IBoundingBox> tosnap = argarr[0] as IEnumerable <IBoundingBox>;
            int index = (int)argarr[1];

            List <IBoundingBox> allsnapped = new List <IBoundingBox>();


            Bitmap tocrop = Bitmap.FromSystemDrawingBitmap(GetBitmap(index));

            foreach (IBoundingBox rect in tosnap)
            {
                System.Windows.Int32Rect snapped = RectangleFinder.SnapRect(Bitmap.Crop(tocrop, rect));
                BoundingBox snappedbb            = new BoundingBox(snapped.X + rect.Left + 1, snapped.Y + rect.Top + 1, snapped.Width, snapped.Height);
                allsnapped.Add(snappedbb);
            }

            if (RectsSnapped != null)
            {
                RectsSnapped(this, new RectsSnappedArgs(allsnapped));
            }
        }