Пример #1
0
 public void Visualize(FrameResult fr)
 {
     if (fr.QRLocation != null)
     {
         fr.Visual.DrawPolyline(fr.QRLocation, true, new Bgr(0, 0, 255), 2);
         fr.Visual.Draw(new CircleF(fr.QRCenter, 6), new Bgr(0, 255, 0), 2);
         fr.Visual.Draw(new CircleF(fr.QRLocation[0], 6), new Bgr(255, 255, 255), 2);
         fr.Visual.Draw(new CircleF(fr.QRLocation[2], 6), new Bgr(255, 0, 0), 2);
         Point TopMiddle = PointOperations.Middle(fr.QRLocation[0], fr.QRLocation[3]);
         fr.Visual.Draw(new LineSegment2D(fr.QRCenter, TopMiddle), new Bgr(0, 255, 0), 2);
     }
     if (fr.ArucoLocation != null)
     {
         ArucoInvoke.DrawDetectedMarkers(fr.Visual, corners, ids, new MCvScalar(0, 255, 0));
     }
 }
Пример #2
0
        /// <summary>
        /// Обрабатывает один поступивший кадр.
        /// </summary>
        /// <param name="frame">Кадр для анализа.</param>
        /// <returns>Сведения об объектах в кадре.</returns>
        public FrameResult ProcessFrame(Image <Bgr, byte> frame)
        {
            if (bwframe == null)
            {
                bwframe = new Image <Gray, byte>(frame.Size);
            }
            if (grayframe == null)
            {
                grayframe = new Image <Gray, byte>(frame.Size);
            }
            //if (vid == null) vid = new VideoWriter("video.avi", 24, frame.Size, true);
            vid?.Write(frame.Mat);
            grayframe.ConvertFrom(frame);
            int blocksize = 51;

            CvInvoke.AdaptiveThreshold(grayframe, bwframe, 255, Emgu.CV.CvEnum.AdaptiveThresholdType.MeanC, Emgu.CV.CvEnum.ThresholdType.Binary, blocksize, 5);
            FrameResult fr = new FrameResult(frame);

            ArucoInvoke.DetectMarkers(bwframe, ArucoDictionary, corners, ids, _detectorParameters, rejected);
            if (ids.Size > 0)
            {
                fr.ArucoLocation = corners[0].ToArray();
            }
            // Ищем коды на изображении
            List <ZBar.Symbol> symbols = Scanner.Scan(bwframe.ToBitmap());

            if (symbols.Count == 0)
            {
                return(fr);
            }
            ZBar.Symbol s = symbols[0];
            fr.QRLocation = s.Location.ToArray();
            fr.QRCenter   = PointOperations.Middle(fr.QRLocation);
            Point RightMiddle = PointOperations.Middle(fr.QRLocation[3], fr.QRLocation[2]);

            fr.TiltAngle  = Math.Atan2(RightMiddle.Y - fr.QRCenter.Y, RightMiddle.X - fr.QRCenter.X);
            fr.Commentary = s.Data;

            Visualize(fr);
            return(fr);
        }