Beispiel #1
0
        public static ImageLogoInfo ProccessImage(string imgPath, bool includeprocessedimage)
        {
            ImageLogoInfo info = new ImageLogoInfo();

            info.ImagePath = imgPath;
            var sw = Stopwatch.StartNew();

            try
            {
                Bitmap source = GetBitmap(imgPath);
                var    min    = Math.Min(source.Width, source.Height);
                var    scales = min > 500 ? new float[] { 1 } : (min > 400 ? new float[] { 1, 1.5f } : new float[] { 1, 1.5f, 2f });
                foreach (var scale in scales)
                {
                    var image      = source.Crop(65, 65, scale);
                    var firstCheck = MyTemplateMatching.DetectLogo(image);
                    info.HasLogo    = firstCheck > 50;
                    info.Confidence = (int)firstCheck;
                    if (includeprocessedimage)
                    {
                        info.ProcessedImage = image;
                    }

                    if (info.HasLogo)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex) { info.Error = ex.FullErrorMessage(); }
            sw.Stop();
            info.ProcessingTime = sw.ElapsedMilliseconds;

            return(info);
        }
Beispiel #2
0
        internal ImageLogoInfo Clone()
        {
            var i = new ImageLogoInfo();

            i.Confidence = Confidence;

            i.Error     = Error;
            i.HasLogo   = HasLogo;
            i.ImagePath = ImagePath;
            if (ProcessedImage != null)
            {
                i.ProcessedImage = (Bitmap)ProcessedImage.Clone();
            }
            i.ProcessingTime = ProcessingTime;

            return(i);
        }
Beispiel #3
0
        /// <summary>
        /// Insert processedimage to db and get its ID
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public long  InsertItemToSqlite(ImageLogoInfo info)
        {
            using (SQLiteCommand cmd = new SQLiteCommand())
            {
                cmd.Connection = conn;
                _OpenDBConn();

                SQLiteHelper sh = new SQLiteHelper(cmd);

                var dic = new Dictionary <string, object>();
                dic["ImagePath"]      = info.ImagePath;
                dic["HasLogo"]        = info.HasLogo ?1:0;
                dic["Confidence"]     = info.Confidence;
                dic["ConfusedImage"]  = info.ConfusedImage ?1:0;
                dic["Error"]          = info.Error?.Message;
                dic["ProcessingTime"] = info.ProcessingTime;


                sh.Insert(tb.TableName, dic);
                return(sh.LastInsertRowId());
            }
        }
Beispiel #4
0
        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            //processedImages.Clear();
            string folderPath = e.Argument + "";


            processPaused           = false;
            processStopwatch        = Stopwatch.StartNew();
            cancellationTokenSource = new CancellationTokenSource();
            // bool export_csv_auto = chk_auto_csv_file.Checked;
            auto_csv_file = txt_auto_csv_file.Text;
            // if (export_csv_auto)
            // {
            if (CSV_Autofile != null)
            {
                CSV_Autofile.Dispose();
            }
            CSV_Autofile = new StreamWriter(auto_csv_file, previousLogs.Count > 0);
            if (previousLogs.Count == 0)
            {
                WriteToCSV_Auto(CSV_Autofile, "Image Path,Has Logo,Processing Time,Confidence,Error");
            }
            //}
            Parallel.ForEach(MyDirectory.GetFiles(folderPath, imgExts, previousLogs, SearchOption.AllDirectories), new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = cancellationTokenSource.Token
            }, (item) =>
            {
                try
                {
                    if (backgroundWorker1.CancellationPending)
                    {
                        return;
                    }
                    while (processPaused && !backgroundWorker1.CancellationPending)
                    {
                        Thread.Sleep(1000);
                    }
                    var info = ImageLogoInfo.ProccessImage(item, false);
                    Stat_info.Total_process_time += info.ProcessingTime;



                    // lock (processedImages) processedImages.Add(info);
                    WriteToCSV_Auto(CSV_Autofile, info.ImagePath + "," + (info.ConfusedImage == true ? "Maybe" : info.HasLogo + "") + "," + info.ProcessingTime + "ms," + info.Confidence + "%" + "," + info.Error);

                    if (!string.IsNullOrWhiteSpace(info.Error))
                    {
                        Stat_info.Failed_logos++;
                    }
                    if (info.HasLogo)
                    {
                        Stat_info.Has_Logos++;
                    }
                    else if (info.ConfusedImage)
                    {
                        Stat_info.Confused_Logos++;
                    }
                    else if (!info.HasLogo)
                    {
                        Stat_info.Has_noLogos++;
                    }
                }
                catch (Exception er)
                {
                    Stat_info.Failed_logos++;
                    WriteToCSV_Auto(CSV_Autofile, "{ERROR},,,," + er.FullErrorMessage());
                }
            });
        }
Beispiel #5
0
        internal List <ImageLogoInfo> FindAll(bool haslogo, bool hasnologo, bool hasconfusedimages, bool hasError)
        {
            List <ImageLogoInfo> items = new List <ImageLogoInfo>();

            if (!haslogo && !hasnologo & !hasError)
            {
                return(items);
            }
            using (SQLiteCommand cmd = new SQLiteCommand())
            {
                cmd.Connection = conn;
                _OpenDBConn();

                SQLiteHelper sh = new SQLiteHelper(cmd);


                var sql = "select * from " + tb.TableName + " where ";
                if (hasError)
                {
                    sql += " Error is not null";
                }
                else
                {
                    sql += " Error is  null";
                }

                if (!haslogo || !hasnologo)
                {
                    if (hasError && haslogo)
                    {
                        sql += " or HasLogo=1 ";
                    }
                    else if (!hasError && hasnologo)
                    {
                        sql += " and HasLogo=0 ";
                    }

                    if (hasError && hasnologo)
                    {
                        sql += " or HasLogo=0 ";
                    }
                    else if (!hasError && hasnologo)
                    {
                        sql += " and HasLogo=0 ";
                    }
                }
                else if (hasError && haslogo && hasnologo)
                {
                    sql += " or HasLogo=0 or haslogo=1 ";
                }
                else if (haslogo && hasnologo)
                {
                    sql += " and (HasLogo=0 or haslogo=1 )";
                }



                var dt = sh.Select(sql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        var info = new ImageLogoInfo
                        {
                            Confidence     = int.Parse(row["Confidence"] + ""),
                            ImagePath      = row["ImagePath"] + "",
                            ProcessingTime = long.Parse(row["ProcessingTime"] + ""),
                            HasLogo        = row["HasLogo"].ToString() == "1" ? true : false
                        };
                        if (info.ConfusedImage && !hasconfusedimages)
                        {
                            continue;
                        }
                        if (!string.IsNullOrWhiteSpace(row["Error"] + ""))
                        {
                            info.Error = new Exception(row["Error"] + "");
                        }
                        items.Add(info);
                    }
                }

                return(items);
            }
        }