示例#1
0
        void videoCapture_InitFrame(object sender, EventArgs e)
        {
            videoCapture.ReadTo(ref frame);
            if (frame == null)
            {
                return;
            }

            if (isROISelected)
            {
                initTracking(frame);
                Application.Idle -= videoCapture_InitFrame;
                Application.Idle += videoCapture_NewFrame;
                return;
            }
            else
            {
                frame.Draw(roi, Bgr <byte> .Red, 3);
            }
            this.pictureBox.Image = frame.ToBitmap(); //it will be just casted (data is shared)

            GC.Collect();
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            const int BORDER_OFFSET = 20;

            scale += 10 * dScale; if (scale > 300) dScale = -1; if (scale < 100) dScale = 1;
            angle += 5 * dAngle;  if (angle > 360) dAngle = -1; if (dAngle < 0) dAngle = 1;

            var transformation = Transforms2D.Combine
               (
                    Transforms2D.Rotation((float)Angle.ToRadians(angle)),
                    Transforms2D.Scale(scale, scale)
               );

            IEnumerable<PointF> pts = modelPts.Transform(transformation);

            var box = pts.BoundingRect(); //maybe apply it to bounding box instead of points (expensive)
            pts = pts.Transform(Transforms2D.Translation(-box.X + BORDER_OFFSET, -box.Y + BORDER_OFFSET));

            var image = new Bgr<byte>[scale + BORDER_OFFSET * 2, scale + BORDER_OFFSET * 2];
            drawContour(pts.ToList(), image);
            pictureBox.Image = image.ToBitmap();
        }