Esempio n. 1
0
        private bool loadFile(string strImagesFile, string strSourceName, int nExtractTotal, ref int nExtractIdx, int nTotal, ref int nIdx, Log log, bool bExtractFiles, Dictionary <string, int> rgNameToLabel)
        {
            Stopwatch sw = new Stopwatch();

            reportProgress(nIdx, nTotal, " Source: " + strSourceName);
            reportProgress(nIdx, nTotal, "  loading " + strImagesFile + "...");

            FileStream fs = null;

            try
            {
                int nSrcId = m_factory.AddSource(strSourceName, 3, -1, -1, false);
                addLabels(nSrcId, rgNameToLabel);
                m_factory.Open(nSrcId, 500, Database.FORCE_LOAD.NONE, log);

                int    nPos    = strImagesFile.ToLower().LastIndexOf(".tar");
                string strPath = strImagesFile.Substring(0, nPos);

                if (!Directory.Exists(strPath))
                {
                    Directory.CreateDirectory(strPath);
                }

                if (bExtractFiles)
                {
                    log.Progress = (double)nIdx / nExtractTotal;
                    log.WriteLine("Extracting files from '" + strImagesFile + "'...");

                    if ((nExtractIdx = TarFile.ExtractTar(strImagesFile, strPath, m_evtCancel, log, nExtractTotal, nExtractIdx)) == 0)
                    {
                        log.WriteLine("Aborted.");
                        return(false);
                    }
                }

                // Load the annotations.
                SimpleDatum.ANNOTATION_TYPE type = SimpleDatum.ANNOTATION_TYPE.BBOX;
                int nResizeHeight = 0;
                int nResizeWidth  = 0;

                // Create the training database images.
                // Create the master list file.
                List <Tuple <string, string> > rgFiles = createFileList(log, strPath);

                sw.Start();
                for (int i = 0; i < rgFiles.Count; i++)
                {
                    SimpleDatum datum = loadDatum(log, rgFiles[i].Item1, rgFiles[i].Item2, nResizeHeight, nResizeWidth, type, rgNameToLabel);
                    m_factory.PutRawImageCache(nIdx, datum);
                    nIdx++;

                    if (m_evtCancel.WaitOne(0))
                    {
                        log.WriteLine("Aborted.");
                        return(false);
                    }

                    if (sw.Elapsed.TotalMilliseconds > 1000)
                    {
                        log.Progress = (double)nIdx / nTotal;
                        log.WriteLine("Loading file " + i.ToString() + " of " + rgFiles.Count.ToString() + "...");
                        sw.Restart();
                    }
                }

                m_factory.ClearImageCashe(true);
                m_factory.Close();
            }
            finally
            {
                if (fs != null)
                {
                    fs.Dispose();
                }
            }

            return(true);
        }