Esempio n. 1
0
        /// <summary>
        /// Process the input image and render into the output image
        /// </summary>
        /// <param name="imageIn">The input image</param>
        /// <param name="imageOut">The output image, can be the same as imageIn, in which case we will render directly into the input image</param>
        /// <returns>The messages that we want to display.</returns>
        public string ProcessAndRender(IInputArray imageIn, IInputOutputArray imageOut)
        {
            Stopwatch watch = Stopwatch.StartNew();

            _ocr.SetImage(imageIn);
            if (_ocr.Recognize() != 0)
            {
                throw new Exception("Failed to recognize image");
            }
            String ocrResult = _ocr.GetUTF8Text();

            watch.Stop();

            if (imageOut != imageIn)
            {
                using (InputArray iaImageIn = imageIn.GetInputArray())
                {
                    iaImageIn.CopyTo(imageOut);
                }
            }

            return(String.Format(
                       "tesseract version {2}; lang: {0}; mode: {1}{3}Text Detected:{3}{4}",
                       _lang,
                       _mode.ToString(),
                       Emgu.CV.OCR.Tesseract.VersionString,
                       System.Environment.NewLine, ocrResult));
        }
        /// <summary>
        /// Process the input image and render into the output image
        /// </summary>
        /// <param name="imageIn">The input image</param>
        /// <param name="imageOut">The output image, can be the same as imageIn, in which case we will render directly into the input image</param>
        /// <returns>The messages that we want to display.</returns>
        public string ProcessAndRender(IInputArray imageIn, IInputOutputArray imageOut)
        {
            List <Rectangle> faces = new List <Rectangle>();
            List <Rectangle> eyes  = new List <Rectangle>();

            Stopwatch watch = Stopwatch.StartNew();

            Detect(imageIn, faces, eyes);
            watch.Stop();

            if (imageOut != imageIn)
            {
                using (InputArray iaImageIn = imageIn.GetInputArray())
                {
                    iaImageIn.CopyTo(imageOut);
                }
            }

            //Draw the faces in red
            foreach (Rectangle rect in faces)
            {
                CvInvoke.Rectangle(imageOut, rect, new MCvScalar(0, 0, 255), 2);
            }

            //Draw the eyes in blue
            foreach (Rectangle rect in eyes)
            {
                CvInvoke.Rectangle(imageOut, rect, new MCvScalar(255, 0, 0), 2);
            }

            return(String.Format("Detected in {0} milliseconds.", watch.ElapsedMilliseconds));
        }
        /// <summary>
        /// Process the input image and render into the output image
        /// </summary>
        /// <param name="imageIn">The input image</param>
        /// <param name="imageOut">The output image, can be the same as imageIn, in which case we will render directly into the input image</param>
        /// <returns>The messages that we want to display.</returns>
        public string ProcessAndRender(IInputArray imageIn, IInputOutputArray imageOut)
        {
            if (imageOut != imageIn)
            {
                using (InputArray iaImageIn = imageIn.GetInputArray())
                {
                    iaImageIn.CopyTo(imageOut);
                }
            }

            Stopwatch watch = Stopwatch.StartNew();

            List <DetectedObject> fullFaceRegions    = new List <DetectedObject>();
            List <DetectedObject> partialFaceRegions = new List <DetectedObject>();

            _faceDetector.Detect(imageIn, fullFaceRegions, partialFaceRegions);

            if (partialFaceRegions.Count > 0)
            {
                foreach (DetectedObject face in partialFaceRegions)
                {
                    CvInvoke.Rectangle(imageOut, face.Region, new MCvScalar(0, 255, 0));
                }
            }

            if (fullFaceRegions.Count > 0)
            {
                foreach (DetectedObject face in fullFaceRegions)
                {
                    CvInvoke.Rectangle(imageOut, face.Region, new MCvScalar(0, 255, 0));
                }

                var fullFaceRegionsArr = fullFaceRegions.ToArray();
                var rectRegionArr      = Array.ConvertAll(fullFaceRegionsArr, r => r.Region);

                using (VectorOfVectorOfPointF landmarks = _facemarkDetector.Detect(imageIn, rectRegionArr))
                {
                    int len = landmarks.Size;
                    for (int i = 0; i < len; i++)
                    {
                        using (VectorOfPointF vpf = landmarks[i])
                            FaceInvoke.DrawFacemarks(imageOut, vpf, new MCvScalar(255, 0, 0));
                    }
                }
            }
            watch.Stop();
            return(String.Format("Detected in {0} milliseconds.", watch.ElapsedMilliseconds));
        }
Esempio n. 4
0
 /// <summary>
 /// Process the input image and render into the output image
 /// </summary>
 /// <param name="imageIn">The input image</param>
 /// <param name="imageOut">The output image, can be the same as imageIn, in which case we will render directly into the input image</param>
 /// <param name="matchScoreThreshold">A threshold used to filter boxes by score.</param>
 /// <param name="nmsThreshold">A threshold used in non maximum suppression.</param>
 /// <returns>The messages that we want to display.</returns>
 public void ProcessAndRender(IInputArray imageIn, IInputOutputArray imageOut, float matchScoreThreshold = 0.5f, float nmsThreshold = 0.4f)
 {
     MaskedObject[] objects = Detect(imageIn, matchScoreThreshold, nmsThreshold);
     if (imageOut != imageIn)
     {
         using (InputArray iaImageIn = imageIn.GetInputArray())
         {
             iaImageIn.CopyTo(imageOut);
         }
     }
     foreach (var obj in objects)
     {
         obj.Render(imageOut, new MCvScalar(0, 0, 255), _colors[obj.ClassId]);
         obj.Dispose();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Process the input image and render into the output image
        /// </summary>
        /// <param name="imageIn">The input image</param>
        /// <param name="imageOut">The output image, can be the same as imageIn, in which case we will render directly into the input image</param>
        /// <returns>The messages that we want to display.</returns>
        public String ProcessAndRender(IInputArray imageIn, IInputOutputArray imageOut)
        {
            Stopwatch watch      = Stopwatch.StartNew();
            var       sceneTexts = Detect(imageIn);

            watch.Stop();
            if (imageOut != imageIn)
            {
                using (InputArray iaImageIn = imageIn.GetInputArray())
                {
                    iaImageIn.CopyTo(imageOut);
                }
            }
            Render(imageOut, sceneTexts);
            return(String.Format("Detected in {0} milliseconds.", watch.ElapsedMilliseconds));
        }
Esempio n. 6
0
        /// <summary>
        /// Process the input image and render into the output image
        /// </summary>
        /// <param name="imageIn">The input image</param>
        /// <param name="imageOut">The output image, can be the same as imageIn, in which case we will render directly into the input image</param>
        /// <returns>The messages that we want to display.</returns>

        public String ProcessAndRender(IInputArray imageIn, IInputOutputArray imageOut)
        {
            Stopwatch watch           = Stopwatch.StartNew();
            var       detectedObjects = Detect(imageIn);

            watch.Stop();

            if (imageOut != imageIn)
            {
                using (InputArray iaImageIn = imageIn.GetInputArray())
                {
                    iaImageIn.CopyTo(imageOut);
                }
            }

            foreach (var detected in detectedObjects)
            {
                detected.Render(imageOut, new MCvScalar(0, 0, 255));
            }
            return(String.Format("Detected in {0} milliseconds.", watch.ElapsedMilliseconds));
        }
Esempio n. 7
0
        /// <summary>
        /// Process the input image and render into the output image
        /// </summary>
        /// <param name="imageIn">The input image</param>
        /// <param name="imageOut">The output image, can be the same as imageIn, in which case we will render directly into the input image</param>
        /// <returns>The messages that we want to display.</returns>
        public string ProcessAndRender(IInputArray imageIn, IInputOutputArray imageOut)
        {
            Stopwatch watch = Stopwatch.StartNew();

            Rectangle[] pedestrians = Find(imageIn);
            watch.Stop();

            if (imageOut != imageIn)
            {
                using (InputArray iaImageIn = imageIn.GetInputArray())
                {
                    iaImageIn.CopyTo(imageOut);
                }
            }

            foreach (Rectangle rect in pedestrians)
            {
                CvInvoke.Rectangle(imageOut, rect, new MCvScalar(0, 0, 255), 2);
            }

            return(String.Format("Detected in {0} milliseconds.", watch.ElapsedMilliseconds));
        }
        /// <summary>
        /// Process the input image and render into the output image
        /// </summary>
        /// <param name="imageIn">The input image</param>
        /// <param name="imageOut">The output image, can be the same as imageIn, in which case we will render directly into the input image</param>
        /// <returns>The messages that we want to display.</returns>

        public String ProcessAndRender(IInputArray imageIn, IInputOutputArray imageOut)
        {
            using (VectorOfMat points = new VectorOfMat())
            {
                Stopwatch watch        = Stopwatch.StartNew();
                String[]  qrCodesFound = _weChatQRCodeDetectionModel.DetectAndDecode(imageIn, points);
                watch.Stop();
                for (int i = 0; i < qrCodesFound.Length; i++)
                {
                    using (Mat p = points[i])
                    {
                        Point[] contour = MatToPoints(p);

                        using (VectorOfVectorOfPoint vpp = new VectorOfVectorOfPoint(new Point[][] { contour }))
                        {
                            CvInvoke.DrawContours(imageOut, vpp, -1, new MCvScalar(255, 0, 0));
                        }
                    }
                    //CvInvoke.DrawContours(imageOut, points, i, new MCvScalar(255, 0, 0));
                    //CvInvoke.PutText(imageOut, qrCodesFound[i],  );
                }
                if (imageOut != imageIn)
                {
                    using (InputArray iaImageIn = imageIn.GetInputArray())
                    {
                        iaImageIn.CopyTo(imageOut);
                    }
                }

                //foreach (var detected in detectedObjects)
                //    detected.Render(imageOut, new MCvScalar(0, 0, 255));
                return(String.Format(
                           "QR codes found (in {1} milliseconds): {0}",
                           String.Join(";", String.Format("\"{0}\"", qrCodesFound)),
                           watch.ElapsedMilliseconds));
            }

            //var detectedObjects = Detect(imageIn);
        }