public static Bitmap CaptureScreen(VideoFeedControl vfc) { if (!vfc.IsDisposed) { try { var cnt = vfc.browser; var screen = Screen.FromPoint(cnt.Location); Point location = cnt.PointToScreen(cnt.Location); var bm = new Bitmap(cnt.ClientSize.Width + 500, cnt.ClientSize.Height + 150); var g = Graphics.FromImage(bm); g.CopyFromScreen(location.X + 130, location.Y + 40, 0, 0, bm.Size); return(bm); } catch { return(null); } } return(null); }
public Vehicle(Rectangle rct, int id, VideoFeedControl vfc) { this.rct = rct; this.id = id; this.isc = vfc; AddToList(this); CreatePath(this); }
public Bitmap DetectVehicle(Bitmap img, VideoFeedControl vfc) { if (!vfc.IsDisposed) { Graphics g = Graphics.FromImage(img); if (vfc.road.Width > 0 && vfc.road.Height > 0) { VhlList(vfc); Image <Bgr, byte> grayImage = new Image <Bgr, byte>(img); Rectangle[] rcts = clsfr.DetectMultiScale(grayImage, 1.05, 3); int i = 0; foreach (var rct in rcts) { var car = new Vehicle(rct, i, vfc); var speed = GetSpeed(vfc, car); Pen pen; if (CompareSpeed(speed, vfc)) { pen = new Pen(Color.Blue, 2); } else { pen = new Pen(Color.Red, 2); } g.DrawRectangle(pen, rct); SpeedDisplay(g, pen.Color, speed, car); if (!CompareSpeed(speed, vfc)) { var path = SaveBm(img, vfc.vs.name + "_перевищення_швидкості"); Log.AddToLog("На трансляції під назвою " + vfc.vs.name + "було виявлено правопорушення;\r\nПравопорушення збереженно за адресою: " + path + ";"); } i++; } TrackVehicle(g, vfc, Color.Blue); } else { g.DrawString("Виділіть на записі дорогу ", new Font(FontFamily.GenericSansSerif, 17, FontStyle.Regular), new SolidBrush(Color.Blue), 3, 3); } return(img); } return(null); }
private bool CompareSpeed(float?speed, VideoFeedControl vfc) { if (vfc.vs.max_speed != null && speed != null) { if (speed > vfc.vs.max_speed) { return(false); } } return(true); }
private float?GetSpeed(VideoFeedControl vfc, Vehicle vehicle) { if (vfc.vs.road_size != null) { var time = DateTime.Now - vfc.start; return(SpeedEst.Estimate(vfc.road, (float)vfc.vs.road_size, vehicle, (float)time.TotalMilliseconds)); } else { return(null); } }
private void VhlList(VideoFeedControl vfc) { if (vfc.vehicles == null) { vfc.vehicles = new List <List <Vehicle> >(); vfc.vehicles.Add(new List <Vehicle>()); } else { vfc.vehicles.Add(new List <Vehicle>()); } }
private void BuildPanel2() { this.splitContainer1.Panel2.Controls.Clear(); if (vsList != null) { foreach (var stream in vsList) { var feed = new VideoFeedControl(stream, this); if (!feed.IsDisposed) this.splitContainer1.Panel2.Controls.Add(feed); } } }
private void hjbjbToolStripMenuItem_Click(object sender, EventArgs e) { var vs = new VideoStream(this); var nvs = new NewVideoStream(vs); this.panel2Width = splitContainer1.Panel2.Width; if (nvs.DialogResult == DialogResult.Yes) { var feed = new VideoFeedControl(vs, this); if (!feed.IsDisposed) this.splitContainer1.Panel2.Controls.Add(feed); BuildPanel2(); Log.AddToLog("Створено трансляцію під назвою " + vs.name + ";"); } }
private void TrackVehicle(Graphics g, VideoFeedControl vfc, Color color) { if (vfc.vehicles != null) { var vhls = vfc.vehicles[vfc.vehicles.Count - 1]; foreach (var vhl in vhls) { var pen = new Pen(color, 2); if (vhl.path.Count >= 1) { for (int i = 1; i < vhl.path.Count; i++) { g.DrawLine(pen, vhl.path[i - 1], vhl.path[i]); } } } } }
private void прмпрToolStripMenuItem_Click(object sender, EventArgs e) { var vs = new VideoStream(this); this.panel2Width = splitContainer1.Panel2.Width; vs.url = "https://youtu.be/wqctLW0Hb_0"; vs.name = "Завантажена дорога"; vs.road_size = (float?)0.2; vs.max_speed = 60; vs.AddToList(); var feed = new VideoFeedControl(vs, this); if (!feed.IsDisposed) this.splitContainer1.Panel2.Controls.Add(feed); BuildPanel2(); Log.AddToLog("Створено трансляцію під назвою " + vs.name + ";"); }
public async void Begin(VideoFeedControl vfc) { IVideoFeedControl isc = vfc; isc.bgn = true; int i = 0; while (isc.bgn) { vfc.start = DateTime.Now; var bm = CaptureScreen(vfc); isc.bm = bm; var fnd = new FindVehicle(); fnd.DisplayImage(vfc, bm); await Task.Delay(20); i++; } }
public void DisplayImage(VideoFeedControl vfc, Bitmap bm) { DetectVehicle(bm, vfc); vfc.pictureBox1.Image = bm; }