Beispiel #1
0
 /// <summary>
 /// 图片均衡操作,将传入图片自动转换,imgWidth:设定图片宽度,imgHeight图片设定高度
 /// 图片(forexample:a.bmp)另存为同文件夹下面的_a.bmp
 /// </summary>
 /// <param name="ImagePath"></param>
 public void QualizerImage(string ImagePath, int imgWidth, int imgHeight)
 {
     try
     {
         if ((ImagePath.Length == 0) || (!File.Exists(ImagePath)))
         {
             return;
         }
         EImageBW8 EBW8ImageOrig = new EImageBW8(); // EImageBW8 instance
         EImageBW8 EBW8ImageDest = new EImageBW8(); // EImageBW8 instance
         EBW8ImageOrig.SetSize(imgWidth, imgHeight);
         // Make image black
         EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), EBW8ImageOrig);
         EBW8ImageOrig.Load(ImagePath);
         EBW8ImageDest.SetSize(imgWidth, imgHeight);
         // Make image black
         EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), EBW8ImageDest);
         EBW8ImageDest.SetSize(EBW8ImageOrig);
         EasyImage.Equalize(EBW8ImageOrig, EBW8ImageDest);
         EBW8ImageOrig.Dispose();
         //EBW8ImageDest.Save(ImagePath);
         EBW8ImageDest.Save(ImageSaveAsPath(ImagePath));
     }
     catch
     {
         throw;
     }
 }
        private void backgroundToolStripMenuItem_Click(object sender, EventArgs e)
        {
            float PictureBoxSizeRatio, ImageSizeRatio;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Background.Load(openFileDialog1.FileName);
                PictureBoxSizeRatio = (float)pbImg3.Width / pbImg3.Height;
                ImageSizeRatio      = (float)Background.Width / Background.Height;
                if (ImageSizeRatio > PictureBoxSizeRatio)
                {
                    ScalingRatio = (float)pbImg3.Width / Background.Width;
                }
                else
                {
                    ScalingRatio = (float)pbImg3.Height / Background.Height;
                }

                //顯示影像於Picturebox
                pbImg3.Refresh();                                       //先清除目前圖像
                Background.Draw(pbImg3.CreateGraphics(), ScalingRatio); //再繪製上去

                BackgroundGray.SetSize(Background);
                EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), BackgroundGray);
                EasyImage.Convert(Background, BackgroundGray); //轉灰階
            }
        }
Beispiel #3
0
        public override EImageBW8 Run(EImageBW8 img)
        {
            if (!Enable)
            {
                return(img);
            }
            EImageBW8 imgBw8 = new EImageBW8();

            imgBw8.SetSize(img);
            switch (Type)
            {
            case MorphologyType.Square:
                EasyImage.DilateBox(img, imgBw8, Width);
                break;

            case MorphologyType.Rectangle:
                EasyImage.DilateBox(img, imgBw8, Width, Height);
                break;

            case MorphologyType.Circle:
                EasyImage.DilateDisk(img, imgBw8, Width);
                break;

            default: EasyImage.DilateBox(img, imgBw8, Width);
                break;
            }
            img.Dispose();
            img = new EImageBW8();
            return(imgBw8);
        }
Beispiel #4
0
        public override EImageBW8 Run(EImageBW8 img)
        {
            if (!Enable)
            {
                return(img);
            }
            EImageBW8 imgBw8 = new EImageBW8();

            imgBw8.SetSize(img);
            switch (Mode)
            {
            case MyThresholdMode.Auto:
                EBW8 value1 = EasyImage.AutoThreshold(img, EThresholdMode.MinResidue);
                AbsoluteValue = value1.Value;
                break;

            case MyThresholdMode.Absolute:
                break;

            case MyThresholdMode.Relative:
                EBW8 value2 = EasyImage.AutoThreshold(img, EThresholdMode.Relative, RelativeValue);
                AbsoluteValue = value2.Value;
                break;

            default:
                break;
            }
            EasyImage.Threshold(img, imgBw8, AbsoluteValue);
            img.Dispose();
            img = new EImageBW8();
            return(imgBw8);
        }
Beispiel #5
0
        public override EImageBW8 Run(EImageBW8 img)
        {
            if (!Enable)
            {
                return(img);
            }
            EImageBW8 imgBw8 = new EImageBW8();
            float     a = 0f, x = 0f, y = 0f;

            if (Value % 180 < 90)
            {
                //当前角度
                a = (float)Math.Atan2((float)img.Height / 2, (float)img.Width / 2);
                //旋转后角度
                float b = a + Value % 90 * ((float)Math.PI / 180);
                float c = a - Value % 90 * ((float)Math.PI / 180);
                //斜边
                float z = (float)Math.Sqrt(img.Width * img.Width + img.Height * img.Height) / 2;
                //xy增量
                x = (float)(Math.Cos(c) - Math.Cos(a)) * z;
                y = (float)(Math.Sin(b) - Math.Sin(a)) * z;
                //设置新图片大小
                imgBw8.SetSize((int)(img.Width + 2 * x), (int)(img.Height + 2 * y));
            }
            else if (Value % 180 >= 90)
            {
                //当前角度
                a = (float)Math.Atan2((float)img.Height / 2, (float)img.Width / 2);
                //旋转后角度
                float b = a + Value % 90 * ((float)Math.PI / 180);
                float c = a - Value % 90 * ((float)Math.PI / 180);
                //斜边
                float z = (float)Math.Sqrt(img.Width * img.Width + img.Height * img.Height) / 2;
                //xy增量
                y = (float)(Math.Cos(c) - Math.Cos(a)) * z;
                x = (float)(Math.Sin(b) - Math.Sin(a)) * z;
                //设置新图片大小
                imgBw8.SetSize((int)(img.Height + 2 * x), (int)(img.Width + 2 * y));
            }
            EasyImage.ScaleRotate(img, (float)img.Width / 2, (float)img.Height / 2, (float)imgBw8.Width / 2, (float)imgBw8.Height / 2, 1, 1, Value, imgBw8, 0);
            img.Dispose();
            img = new EImageBW8();
            return(imgBw8);
        }
Beispiel #6
0
        public override EImageBW8 Run(EImageBW8 img)
        {
            if (!Enable)
            {
                return(img);
            }
            EImageBW8 imgBw8 = new EImageBW8();

            imgBw8.SetSize(img);
            EasyImage.GainOffset(img, imgBw8, Gain, Offset);
            img.Dispose();
            img = new EImageBW8();
            return(imgBw8);
        }
Beispiel #7
0
        public override EImageBW8 Run(EImageBW8 img)
        {
            if (!Enable)
            {
                return(img);
            }
            EImageBW8 imgBw8 = new EImageBW8();

            imgBw8.SetSize(img);
            EasyImage.Median(img, imgBw8);
            img.Dispose();
            img = new EImageBW8();
            return(imgBw8);
        }
Beispiel #8
0
        public EImageBW8 Execute(EImageBW8 original, double zoomFactor)
        {
            try
            {
                EImageBW8 resized = new EImageBW8(original);
                resized.SetSize((int)(original.Width * zoomFactor), (int)(original.Height * zoomFactor));
                return(resized);
            }

            catch (Exception e)
            {
                //Maximum Size Reached
                throw new Exception("ResizeImage Failed" + e.Message);
            }
        }
Beispiel #9
0
 private void btn_loadImg_Click(object sender, EventArgs e)
 {
     if (mPicBox1.LoadImg())
     {
         roi.Attach(mPicBox1.Image);
         btn_action.Visible     = true;
         btn_learn.Visible      = true;
         btn_loadMoudle.Visible = true;
         btn_save.Visible       = true;
         btn_process.Visible    = true;
         ckbox_inRoi.Visible    = true;
         copyImg = new EImageBW8();
         copyImg.SetSize(mPicBox1.Image);
         EasyImage.Copy(mPicBox1.Image, copyImg);
     }
 }
        public override bool Run(bool isTaskRun = false)
        {
            int index = config.SelectImgIndex - 1;

            if (index < 0 || index >= ParentTask.Imgs.Count)
            {
                OutputImg = InputImg = null;
                ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Events.IndexOf(this)));
                return(false);
            }
            InputImg = ParentTask.Imgs[index].Img;
            if (InputImg == null || InputImg.IsVoid)
            {
                OutputImg = null;
                ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Events.IndexOf(this)));
                return(false);
            }
            OutputImg = new EImageBW8();
            OutputImg.SetSize(InputImg);
            EasyImage.Copy(InputImg, OutputImg);
            foreach (var item in config.CfgGroup)
            {
                OutputImg = item.Run(OutputImg);
            }

            if (isTaskRun)
            {
                ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Events.IndexOf(this)));
            }
            else
            {
                ImgDictionary imgdic = ParentTask.Imgs.Find(s => { return(s.Config == Config); });
                if (imgdic != null)
                {
                    imgdic.Img = OutputImg;
                }
            }
            return(true);
        }
Beispiel #11
0
        public override bool Run(bool isTaskRun = false)
        {
            OutputImg = new EImageBW8();
            switch (config.SelectMode)
            {
            case 0:
                if (ParentTask.SourceImg != null)
                {
                    OutputImg.SetSize(ParentTask.SourceImg);
                    EasyImage.Copy(ParentTask.SourceImg, OutputImg);
                }
                else
                {
                    OutputImg = null;
                }

                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 1:
                if (!File.Exists(config.ImgPath))
                {
                    return(false);
                }

                OutputImg.Load(config.ImgPath);
                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 2:
                if (!Directory.Exists(config.FolderPath))
                {
                    return(false);
                }
                DirectoryInfo dir = new DirectoryInfo(config.FolderPath);
                FileInfo[]    fil = dir.GetFiles("*.bmp", SearchOption.TopDirectoryOnly);
                if (fil.Length == 0)
                {
                    return(false);
                }
                if (selectImg >= fil.Length)
                {
                    selectImg = 0;
                }
                OutputImg.Load(fil[selectImg++].FullName);
                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 3:
                if (config.SelectCCD > 0)
                {
                    int select = config.SelectCCD - 1;
                    if (ParentTask.Cameras[select].IsConnect)
                    {
                        ImgAtt att = ParentTask.Cameras[select].Grab();
                        OutputImg = new EImageBW8();
                        OutputImg.SetImagePtr(att.ImgWidth, att.ImgHeight, att.ImgPointer);

                        if (isTaskRun)
                        {
                            ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                        }
                    }
                    else
                    {
                        OutputImg = null;
                        return(false);
                    }
                }
                else
                {
                    OutputImg = null;
                    return(false);
                }

                break;

            default:
                return(false);
            }
            return(true);
        }
        private void excelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Excel_APP1 = new Excel.Application();
            Excel_WB1  = Excel_APP1.Workbooks.Add();
            Excel_WS1  = new Excel.Worksheet();

            saveFileDialog1.Filter = "Excel|*.xlsx";
            saveFileDialog1.Title  = "Save a Excel";

            Excel_WS1              = Excel_WB1.Worksheets[1];
            Excel_WS1.Name         = "Data";
            Excel_APP1.Cells[1, 1] = "圖片(.jpg)";
            Excel_APP1.Cells[1, 2] = "Profile下";
            Excel_APP1.Cells[1, 3] = "Profile上";

            OriginalImg1.Load(files[0]);

            /*============================計算scaling ratio============================*/
            float PictureBoxSizeRatio = (float)pbImg1.Width / pbImg1.Height;
            float ImageSizeRatio      = (float)OriginalImg1.Width / OriginalImg1.Height;

            if (ImageSizeRatio > PictureBoxSizeRatio)
            {
                ScalingRatio = (float)pbImg1.Width / OriginalImg1.Width;
            }
            else
            {
                ScalingRatio = (float)pbImg1.Height / OriginalImg1.Height;
            }
            /*=========================================================================*/

            for (int i = 0; i < FileListBox.Items.Count; i++)
            {
                FileListBox.SelectedIndex = i;
                FileListBox.Refresh();
                OriginalImg1.Load(files[i]);
                OriginalImg1.Draw(pbImg1.CreateGraphics(), ScalingRatio);

                //EC24Image2.SetSize(EC24Image1);
                //EasyImage.Oper(EArithmeticLogicOperation.Copy, new EC24(0, 0, 0), EC24Image2);

                //EC24Image1.ColorSystem = EColorSystem.Rgb;
                //EColorLookup1.ConvertFromRgb(EColorSystem.Yiq);
                //EColorLookup1.Transform(EC24Image1, EC24Image2);

                //EC24Image2.Draw(pbImg2.CreateGraphics(), ScalingRatio);

                GrayImg1.SetSize(OriginalImg1);
                EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), GrayImg1);
                EasyImage.Convert(OriginalImg1, GrayImg1); //轉灰階

                //EasyImage.Oper(EArithmeticLogicOperation.Subtract, GrayImg1, BackgroundGray, GrayImg1);
                //EasyImage.Threshold(GrayImg1, GrayImg1, 56);
                //EasyImage.OpenBox(GrayImg1, GrayImg1, settings.set_value_3());

                GrayImg1.Draw(pbImg2.CreateGraphics(), ScalingRatio);

                EasyImage.ImageToLineSegment(GrayImg1, In, 1485, 700, 1683, 700);  //設定車子進入的偵測線,判斷車子是否準備進來
                EasyImage.ImageToLineSegment(GrayImg1, Out, 1485, 400, 1683, 400); //設定車子出去的偵測線,判斷車子是否準備出去

                Excel_APP1.Cells[2 + i, 1] = Path.GetFileNameWithoutExtension(files[i]);
                Excel_APP1.Cells[2 + i, 2] = getProfileValueSum(In);
                Excel_APP1.Cells[2 + i, 3] = getProfileValueSum(Out);

                //Console.WriteLine(files[i]);
            }

            if (saveFileDialog1.ShowDialog() == DialogResult.OK && saveFileDialog1.FileName != "")
            {
                Excel_WB1.SaveAs(saveFileDialog1.FileName);
            }

            Excel_WS1 = null;
            Excel_WB1.Close();
            Excel_WB1 = null;
            Excel_APP1.Quit();
            Excel_APP1 = null;
        }
        private async void videoPlayToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (video == null)
            {
                return;
            }

            if (!play)
            {
                play = true;
                videoPlayToolStripMenuItem.Text = "VideoPause";
            }
            else
            {
                play = false;
                videoPlayToolStripMenuItem.Text = "VideoPlay";
            }

            try
            {
                while (play)
                {
                    Mat frame = new Mat();



                    if (frame == null)
                    {
                        break;
                    }

                    pbImg1.Image = frame.Bitmap;                                                                                 //顯示frame

                    fps        = video.GetCaptureProperty(CapProp.Fps);                                                          //抓影片的fps
                    videotime  = Math.Round(video.GetCaptureProperty(CapProp.PosMsec) / 1000, 3, MidpointRounding.AwayFromZero); //抓影片時間
                    framecount = video.GetCaptureProperty(CapProp.PosFrames);

                    refBitmap(frame);

                    OriginalImg1 = BitmapToEImageC24(ref bitmap);

                    if (!firstSet)
                    {
                        GrayImg1.SetSize(OriginalImg1);
                        GrayImg3.SetSize(OriginalImg1);
                        BackgroundGray.SetSize(OriginalImg1);
                        EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), GrayImg1);
                        EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), GrayImg3);
                        EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), BackgroundGray);
                        EasyImage.Convert(OriginalImg1, GrayImg1);       //轉灰階
                        EasyImage.Convert(OriginalImg1, BackgroundGray); //轉灰階
                        firstSet = true;
                    }
                    else
                    {
                        EasyImage.Convert(OriginalImg1, GrayImg1); //轉灰階
                        //EasyImage.Oper(EArithmeticLogicOperation.Subtract, GrayImg1, BackgroundGray, GrayImg3);

                        //double profilevalue_in = getProfileValueSum(In);
                        //double profilevalue_out = getProfileValueSum(Out);

                        //if (profilevalue_in < 2500 && profilevalue_out < 2500)
                        //{
                        //    Console.WriteLine("Background:" + profilevalue_in);
                        //    EasyImage.Convert(OriginalImg1, BackgroundGray); //轉灰階
                        //}
                        //else
                        //{
                        //    Console.WriteLine("有車進入:" + profilevalue_in);
                        //    EasyImage.Convert(OriginalImg1, BackgroundGray); //轉灰階
                        //}
                    }

                    EasyImage.ImageToLineSegment(GrayImg1, In, 968, 585, 1747, 585);  //設定車子進入的偵測線,判斷車子是否準備進來
                    EasyImage.ImageToLineSegment(GrayImg1, Out, 968, 209, 1747, 209); //設定車子出去的偵測線,判斷車子是否準備出去

                    Console.WriteLine(getProfileValueSum(In));

                    ShowImage(GrayImg1, pbImg2);
                    //ShowImage(BackgroundGray, pbImg3);

                    bitmap.Dispose();
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();

                    videoInfo.setValue(totalframe, framecount, videotime, fps);

                    await Task.Delay(1000 / Convert.ToInt32(fps)); //延遲
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #14
0
        private static void ProcessingCallback(MC.SIGNALINFO signalInfo)
        {
            isImageReady = false;

            UInt32 currentChannel = (UInt32)signalInfo.Context;

            currentSurface = signalInfo.SignalInfo;

            // + GrablinkSnapshotTrigger Sample Program

            try
            {
                // Update the image with the acquired image buffer data
                Int32  width, height, bufferPitch;
                IntPtr bufferAddress;
                MC.GetParam(currentChannel, "ImageSizeX", out width);
                MC.GetParam(currentChannel, "ImageSizeY", out height);
                MC.GetParam(currentChannel, "BufferPitch", out bufferPitch);
                MC.GetParam(currentSurface, "SurfaceAddr", out bufferAddress);

                try
                {
                    imageMutex.WaitOne();

                    image  = new System.Drawing.Bitmap(width, height, bufferPitch, PixelFormat.Format8bppIndexed, bufferAddress);
                    imgpal = image.Palette;

                    // Build bitmap palette Y8
                    for (uint i = 0; i < 256; i++)
                    {
                        imgpal.Entries[i] = Color.FromArgb(
                            (byte)0xFF,
                            (byte)i,
                            (byte)i,
                            (byte)i);
                    }

                    image.Palette = imgpal;

                    string path_directory = @"D:\Waftech\BDMVision\Log\Temp\";
                    System.IO.Directory.CreateDirectory(path_directory);
                    string fullPath = path_directory + "test.jpg";

                    image.Save(fullPath);
                    eImage = new EImageBW8();
                    eImage.SetSize(image.Width, image.Height);
                    eImage.Load(fullPath);
                }
                finally
                {
                    imageMutex.ReleaseMutex();
                }

                isImageReady = true;

                // Retrieve the frame rate
                double frameRate_Hz;
                MC.GetParam(channel, "PerSecond_Fr", out frameRate_Hz);

                // Retrieve the channel state
                string channelState;
                MC.GetParam(channel, "ChannelState", out channelState);

                // Log frame rate and channel state
                VisionLogger.Log(WaftechLibraries.Log.LogType.Log, "E2VCameraHelper", string.Format("Frame Rate: {0:f2}, Channel State: {1}", frameRate_Hz, channelState));
            }
            catch (Euresys.MultiCamException ex)
            {
                VisionLogger.Log(WaftechLibraries.Log.LogType.Exception, "E2VCameraHelper", ex);
                VisionNotifier.AddNotification("MultiCam Exception: " + ex.Message);
                errorMessage = "MultiCam Exception: " + ex.Message;
            }
            catch (System.Exception ex)
            {
                VisionLogger.Log(WaftechLibraries.Log.LogType.Exception, "E2VCameraHelper", ex);
                VisionNotifier.AddNotification("System Exception: " + ex.Message);
                errorMessage = "System Exception: " + ex.Message;
            }
        }
Beispiel #15
0
        private void btnDetect_Click(object sender, EventArgs e)
        {
            double t1 = 0, t2 = 0, timeDiff = 0, fov = 5.0, speed = 0;
            bool   hascar = false;

            valuein  = double.Parse(Value_In.Text);
            valueout = double.Parse(Value_Out.Text);
            last_In  = 0;
            last_Out = 0;

            EC24Image1.Load(files[0]);

            /*============================計算scaling ratio============================*/
            float PictureBoxSizeRatio = (float)pbimg.Width / pbimg.Height;
            float ImageSizeRatio      = (float)EC24Image1.Width / EC24Image1.Height;

            if (ImageSizeRatio > PictureBoxSizeRatio)
            {
                ScalingRatio = (float)pbimg.Width / EC24Image1.Width;
            }
            else
            {
                ScalingRatio = (float)pbimg.Height / EC24Image1.Height;
            }
            /*=========================================================================*/

            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                listBox1.SelectedIndex = i;
                listBox1.Refresh();
                EC24Image1.Load(files[i]);
                EC24Image1.Draw(pbimg.CreateGraphics(), ScalingRatio);

                EBW8Image1.SetSize(EC24Image1);
                EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), EBW8Image1);
                EasyImage.Convert(EC24Image1, EBW8Image1);                            //轉灰階

                EasyImage.ImageToLineSegment(EBW8Image1, In, 1000, 1079, 1750, 1079); //設定偵測線在最底部,判斷車子是否準備進來
                EasyImage.ImageToLineSegment(EBW8Image1, Out, 1000, 0, 1750, 0);      //設定偵測線在最頂部,判斷車子是否準備出去

                if (CarIn(In) && !hascar)                                             //假如沒有車子,且CarIn有偵測到車子情況下,視同進入
                {
                    previous = i;                                                     //記錄車子進來的圖片張數
                    //t1 = DateTime.Now.TimeOfDay.Seconds + DateTime.Now.TimeOfDay.Milliseconds / 1000.0; //記錄進來的時間
                    speed  = 0;
                    hascar = true;
                }
                else if (CarOut(Out) && hascar && speed == 0)                  //假如有車子,且CarOut有偵測到車子並尚未計算速度的情況下,視同出去
                {
                    current = i;                                               //記錄車子出去的圖片張數
                    if (current - previous <= 10 || current - previous >= 100) //防呆機制,假如10張內或超過100張視同有問題
                    {
                        //last_Out = 0;
                        hascar = false;
                    }
                    else
                    {
                        Console.WriteLine("車子進來的第一張圖片:" + files[previous]);
                        Console.WriteLine("車子出去的最後一張圖片:" + files[current]);
                        t1 = Double.Parse(Path.GetFileNameWithoutExtension(files[previous])); //擷取進來的圖檔名當作進來的時間
                        t2 = Double.Parse(Path.GetFileNameWithoutExtension(files[current]));  //擷取出去的圖檔名當作出去的時間
                        //t2 = DateTime.Now.TimeOfDay.Seconds + DateTime.Now.TimeOfDay.Milliseconds / 1000.0; //記錄出去的時間
                        Console.WriteLine("T1=" + t1.ToString());
                        Console.WriteLine("T2=" + t2.ToString());
                        //秒數做溢位處理

                        /*
                         * if (t1 > t2)
                         *  timeDiff = (t2 + 60) - t1;
                         * else
                         */
                        timeDiff = t2 - t1;                                                    //出去的時間減去進來的時間
                        Console.WriteLine("timeDiff = " + timeDiff);
                        speed           = fov / (timeDiff / 4) * 3.6;                          //計算車子的速度,因為採用4倍慢速錄影所以時間要除以4,速度單位為km/hr
                        speed           = Math.Round(speed, 2, MidpointRounding.AwayFromZero); //將速度四捨五入
                        labelSpeed.Text = "Speed: " + speed.ToString();
                        Console.WriteLine("Speed: " + speed);
                        labelSpeed.Update();
                        last_In = 0;
                        hascar  = false;
                    }
                }
            }
        }