Ejemplo n.º 1
0
        // masa do work ni tak boleh panggil object dari WPF i.e. Thread lain
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            // run all background tasks here
            string[] files = Directory.GetFiles(prop_textSource);
            total_input = files.Length;

            //initiate report progress at 0%
            (sender as BackgroundWorker).ReportProgress(0);

            for (int i = 0; i < total_input; i++)
            {
                try
                {
                    string               filePath     = files[i];
                    string               outputfolder = prop_targetSource + "\\";
                    FileInfo             info         = new FileInfo(filePath);
                    System.Drawing.Image img          = System.Drawing.Image.FromFile(filePath);
                    List <Bitmap>        splitted     = ImageUtils.CutImage(img);
                    List <Bitmap>        images       = new List <Bitmap>();
                    img.Dispose();
                    for (int y = 0; y < splitted.Count; y++)
                    {
                        List <RectangleModel> rectangles = new List <RectangleModel>();

                        //check for Vehicle Plate
                        List <RectangleModel> rect_V = VehicleDetection.Start(splitted[y]);

                        //check for Face
                        List <RectangleModel> rect_F = FaceDetection.Start(splitted[y]);

                        if (rect_V.Count > 0)
                        {
                            rectangles.AddRange(rect_V);
                        }
                        if (rect_F.Count > 0)
                        {
                            rectangles.AddRange(rect_F);
                        }
                        // process images to API
                        var item = ImageProcessor.Start(splitted[y], rectangles);
                        // add process image with blurred face/plate into list
                        images.Add(item);
                    }
                    // stich images back into one piece
                    ImageUtils.CombineImgAndSave(images, outputfolder, info.Name);
                    int progressPercentage = Convert.ToInt32(((double)i / total_input) * 100);
                    (sender as BackgroundWorker).ReportProgress(progressPercentage);
                }
                catch (Exception ex)
                {
                    LogHelper.ErrorLog(ex.ToString());
                }
            }
        }