private void timer_Camera_Tick(object sender, EventArgs e) { currentFrameN++; Bitmap bitm = MainForm.videoplayer.SnapPicture(); Image <Bgr, Byte> frame = new Image <Bgr, Byte>(bitm); if (frame == null) { timer_Video.Enabled = false; return; } Image <Bgr, Byte> frame2 = frame.Resize(500, 500, Emgu.CV.CvEnum.INTER.CV_INTER_NN);//frame.Copy(); IntPtr ptr = frame2.MIplImage.imageData; string data = ptr.ToString(); int width = frame2.MIplImage.width; int height = frame2.MIplImage.height; if (isShowVirtualCoil) { for (int i = 0; i < virtualCoilList.Count; i++) { frame2.Draw(virtualCoilList[i], new Bgr(Color.Red), 1); } } pictureBox1.Image = frame2.Bitmap; int flag2 = 0; flag2 = ExternalCall.Detect(ptr, width, height, currentFrameN, laneNum, fps); if (flag2 == 1) { int vehicleNum = ExternalCall.GetVechileCount(); double speed = ExternalCall.GetVechileSpeed(); string speedStr = ""; if (speed == 0) { speedStr = "--"; } else { speedStr = Convert.ToString(Math.Round(speed, 0)); } string type = ""; int typeint = ExternalCall.GetVechileType(); if (typeint == 0) { type = "小型车"; } else if (typeint == 1) { type = "中型车"; } else if (typeint == 2) { type = "大型车"; } else { type = "--"; } ListViewItem lvi = new ListViewItem(); int itemCount = listView_Vehicle_Info.Items.Count; lvi.Text = Convert.ToString(itemCount + 1); //lvi.SubItems.Add(type); lvi.SubItems.Add(speedStr); if (bVideoType)//是网络视频时,输出检测时间 { lvi.SubItems.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } else { lvi.SubItems.Add("--"); } this.listView_Vehicle_Info.Items.Add(lvi); this.listView_Vehicle_Info.EndUpdate(); //IntPtr laneVechileNumPtr=ExternalCall.GetVechileNum4Lanes(); //Marshal.Copy(laneVechileNumPtr, laneVechileNum, 0, laneNum); //for(int i=0;i<laneNum;i++) //{ // ListViewItem lv = new ListViewItem(); // lv.SubItems.Add(Convert.ToString(i+1)); // lv.SubItems.Add(laneVechileNum[0].ToString()); // lv.SubItems.Add(laneVechileNum[1].ToString()); // lv.SubItems.Add(laneVechileNum[2].ToString()); // ListView_VechileType.Items[i] = lv; //} } }
void display(Bitmap bitm) { if (!isDetect) { Graphics g = pictureBox1.CreateGraphics(); System.Drawing.Rectangle rct = new System.Drawing.Rectangle(pictureBox1.Location.X, pictureBox1.Location.Y, bitm.Width, bitm.Height); g.DrawImage(bitm, rct); g.Dispose(); //pictureBox1.Image = bitm; } if (isDetect) { currentFrameN++; Image <Bgr, Byte> frame = new Image <Bgr, Byte>(bitm); Image <Bgr, Byte> frame2 = frame.Resize(500, 500, Emgu.CV.CvEnum.INTER.CV_INTER_NN);//frame.Copy(); IntPtr ptr = frame2.MIplImage.imageData; string data = ptr.ToString(); int width = frame2.MIplImage.width; int height = frame2.MIplImage.height; if (isShowVirtualCoil) { for (int i = 0; i < virtualCoilList.Count; i++) { frame2.Draw(virtualCoilList[i], new Bgr(Color.Red), 1); } } pictureBox1.Image = frame2.Bitmap; int flag2 = 0; flag2 = ExternalCall.Detect(ptr, width, height, currentFrameN, laneNum, fps); if (flag2 == 1) { double speed = ExternalCall.GetVechileSpeed(); string speedStr = ""; if (speed == 0) { speedStr = "--"; } else { speedStr = Convert.ToString(Math.Round(speed, 0)); } string type = ""; int typeint = ExternalCall.GetVechileType(); if (typeint == 0) { type = "小型车"; } else if (typeint == 1) { type = "中型车"; } else if (typeint == 2) { type = "大型车"; } ListViewItem lvi = new ListViewItem(); int itemCount = listView_Vehicle_Info.Items.Count; lvi.Text = Convert.ToString(itemCount + 1); lvi.SubItems.Add(type); lvi.SubItems.Add(speedStr); this.listView_Vehicle_Info.Items.Add(lvi); this.listView_Vehicle_Info.EndUpdate(); } } }
private void timer_Video_Tick(object sender, EventArgs e) { currentFrameN++; Image <Bgr, Byte> frame = capture.QueryFrame(); if (frame == null) { timer_Video.Enabled = false; return; } Image <Bgr, Byte> frame2 = frame.Resize(500, 500, Emgu.CV.CvEnum.INTER.CV_INTER_NN);//frame.Copy(); IntPtr ptr = frame2.MIplImage.imageData; string data = ptr.ToString(); int width = frame2.MIplImage.width; int height = frame2.MIplImage.height; if (isShowVirtualCoil) { for (int i = 0; i < virtualCoilList.Count; i++) { frame2.Draw(virtualCoilList[i], new Bgr(Color.Red), 1); } } pictureBox1.Image = frame2.Bitmap; int flag2 = 0; try { flag2 = ExternalCall.Detect(ptr, width, height, currentFrameN, laneNum, fps); } catch (Exception) { throw; } #region 检测车道,待完成 /* * if (flag2 == 1) * { * IntPtr laneVechileNumPtr=ExternalCall.GetVechileInfo(); * Marshal.Copy(laneVechileNumPtr, laneVechileNum, 0, laneNum*3); * * int count = laneVechileNum.Count() / 3; * * for (int i = 0; i < count; i++) * { * * int laneNo = laneVechileNum[0 + i * laneNum]; * int speed=laneVechileNum[1+i*laneNum]; * int typeint = laneVechileNum[1 + i * laneNum]; * * if (laneNo <= 0) * continue; * * string speedStr = ""; * if (speed == 0) * speedStr = "--"; * else * speedStr = Convert.ToString(speed); * * string type = ""; * * if (typeint == 0) * type = "小型车"; * else if (typeint == 1) * type = "中型车"; * else if (typeint == 2) * type = "大型车"; * else * type = "--"; * * ListViewItem lvi = new ListViewItem(); * * int itemCount = listView_Vehicle_Info.Items.Count; * * lvi.Text = Convert.ToString(itemCount + 1); * * lvi.SubItems.Add(type); * * lvi.SubItems.Add(speedStr); * * this.listView_Vehicle_Info.Items.Add(lvi); * * this.listView_Vehicle_Info.EndUpdate(); * * } * } */ #endregion if (flag2 == 1) { int vehicleNum = ExternalCall.GetVechileCount(); double speed = ExternalCall.GetVechileSpeed(); string speedStr = ""; if (speed == 0) { speedStr = "--"; } else { speedStr = Convert.ToString(Math.Round(speed, 0)); } string type = ""; int typeint = ExternalCall.GetVechileType(); if (typeint == 0) { type = "小型车"; } else if (typeint == 1) { type = "中型车"; } else if (typeint == 2) { type = "大型车"; } else { type = "--"; } ListViewItem lvi = new ListViewItem(); int itemCount = listView_Vehicle_Info.Items.Count; lvi.Text = Convert.ToString(itemCount + 1); //lvi.SubItems.Add(type); lvi.SubItems.Add(speedStr); if (bVideoType)//是网络视频时,输出检测时间 { lvi.SubItems.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } else { lvi.SubItems.Add("--"); } this.listView_Vehicle_Info.Items.Add(lvi); this.listView_Vehicle_Info.EndUpdate(); //IntPtr laneVechileNumPtr=ExternalCall.GetVechileNum4Lanes(); //Marshal.Copy(laneVechileNumPtr, laneVechileNum, 0, laneNum); //for(int i=0;i<laneNum;i++) //{ // ListViewItem lv = new ListViewItem(); // lv.SubItems.Add(Convert.ToString(i+1)); // lv.SubItems.Add(laneVechileNum[0].ToString()); // lv.SubItems.Add(laneVechileNum[1].ToString()); // lv.SubItems.Add(laneVechileNum[2].ToString()); // ListView_VechileType.Items[i] = lv; //} } }