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_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;
                //}
            }
        }
        //开始检测
        private void button_Detect_Click(object sender, EventArgs e)
        {
            #region 界面元素设置

            this.Button_VideoFile_Open.Enabled = false;
            this.button_Detect.Enabled         = false;
            this.Button_Detect_Stop.Enabled    = true;

            //this.listView_Vehicle_Info.Items.Clear();

            #endregion

            ReadDemarcateFile(textBox_Path.Text);

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            //读取上次输入参数的值
            fps = Convert.ToInt32(config.AppSettings.Settings["fps"].Value);

            if (detect_1.Count() == 0 || detect_2.Count() == 0 || detect_3.Count() == 0)
            {
                ReadDemarcateFile(textBox_Path.Text);
            }

            if (virtualCoilList == null || virtualCoilList.Count == 0)
            {
                virtualCoilList = ConvertInts2Rects(detect_1, 3);
            }

            ExternalCall.SetDemarcate(detect_1, detect_2, detect_3, laneNum);

            #region 配置检测参数

            //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            double lanesWidth      = Convert.ToInt32(config.AppSettings.Settings["LanesWidth"].Value);
            double whiteLineLength = Convert.ToInt32(config.AppSettings.Settings["WhiteLineLength"].Value);
            double whiteLineWidth  = Convert.ToInt32(config.AppSettings.Settings["WhiteLineWidth"].Value);

            ExternalCall.SetLaneWidth(lanesWidth);

            ExternalCall.SetWhiteLine(whiteLineLength, whiteLineWidth);

            #endregion

            #region 配置检测参数2

            float  Small_Car_Length_Threshold = Convert.ToInt32(config.AppSettings.Settings["Small_Car_Length_Threshold"].Value);
            int    min_car_frame_num          = Convert.ToInt32(config.AppSettings.Settings["min_car_frame_num"].Value);
            double touchEdgeThreshold         = Convert.ToDouble(config.AppSettings.Settings["touchEdgeThreshold"].Value);
            double leftAndRightBoundaryRatio  = Convert.ToDouble(config.AppSettings.Settings["leftAndRightBoundaryRatio"].Value);
            double similarity_scale_threshold = Convert.ToDouble(config.AppSettings.Settings["similarity_scale_threshold"].Value);

            ExternalCall.SetDetectParameters(Small_Car_Length_Threshold, //小型车长阈值
                                             min_car_frame_num,          //最小的车尾通过虚拟线圈的帧数
                                             touchEdgeThreshold,         //边的阈值
                                             leftAndRightBoundaryRatio,  //左右边界检测的最小比率
                                             similarity_scale_threshold  //相似度阈值
                                             );

            #endregion



            if (!bVideoType)
            {
                timer_Video.Enabled = true;
            }

            if (bVideoType)
            {
                timer_Camera.Enabled = true;

                MainForm.videoplayer.Parent = this.pictureBox1; // 子窗体的父容器
                MainForm.videoplayer.Dock   = DockStyle.Fill;
            }

            /*
             * if (!isNetVideoType)
             * {
             *  capture = new Capture(videoFileName);
             *
             *
             *  timer_Video.Enabled = true;
             * }
             * else
             * {
             *  isDetect = true;
             * }
             */
        }
        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;
                //}
            }
        }