Beispiel #1
0
        /// <summary>
        /// Returns the query state based on the handle and data source where the dataset that owns the data source is first located and the query handle is then used to lookup
        /// the QueryState for that dataset.
        /// </summary>
        /// <param name="lQueryState">Specifies the query state handle.</param>
        /// <param name="nSrcId">Specifies the dataset source who's dataset is used.</param>
        /// <returns>The query state is returned.</returns>
        public QueryState FindQueryState(long lQueryState, int nSrcId)
        {
            lock (m_syncObj)
            {
                foreach (DatasetEx2 ds in m_rgDatasets)
                {
                    ImageSet2 imgSet = ds.Find(nSrcId);

                    if (imgSet != null)
                    {
                        return(ds.FindQueryState(lQueryState, imgSet.ImageSetType));
                    }
                }

                throw new Exception("Could not find query state for data source with ID = " + nSrcId.ToString() + "!");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns the query state based on the handle and data source where the dataset that owns the data source is first located and the query handle is then used to lookup
        /// the QueryState for that dataset.
        /// </summary>
        /// <param name="lQueryState">Specifies the query state handle.</param>
        /// <param name="strSource">Specifies the dataset source who's dataset is used.</param>
        /// <returns>The query state is returned.</returns>
        public QueryState FindQueryState(long lQueryState, string strSource)
        {
            lock (m_syncObj)
            {
                foreach (DatasetEx2 ds in m_rgDatasets)
                {
                    ImageSet2 imgSet = ds.Find(strSource);

                    if (imgSet != null)
                    {
                        return(ds.FindQueryState(lQueryState, imgSet.ImageSetType));
                    }
                }

                throw new Exception("Could not find query state for data source with Name = " + strSource + "!");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Searches for the ImageSet with a given data source name.
        /// </summary>
        /// <param name="strSource">Specifies the name of the data source.</param>
        /// <returns>If found, the ImageSet is returned, otherwise an Exception is thrown.</returns>
        public ImageSet2 FindImageset(string strSource)
        {
            lock (m_syncObj)
            {
                if (m_lastImgSet != null && m_lastImgSet.Source.Name == strSource)
                {
                    return(m_lastImgSet);
                }

                foreach (DatasetEx2 ds in m_rgDatasets)
                {
                    ImageSet2 imgSet = ds.Find(strSource);

                    if (imgSet != null)
                    {
                        m_lastImgSet = imgSet;
                        return(imgSet);
                    }
                }

                throw new Exception("Could not find source with Name = " + strSource + "!");
            }
        }
Beispiel #4
0
        /// <summary>
        /// Searches for the ImageSet with a given data source ID.
        /// </summary>
        /// <param name="nSourceID">Specifies the ID of the data source.</param>
        /// <returns>If found, the ImageSet is returned, otherwise an Exception is thrown.</returns>
        public ImageSet2 FindImageset(int nSourceID)
        {
            lock (m_syncObj)
            {
                if (m_lastImgSet != null && m_lastImgSet.Source.ID == nSourceID)
                {
                    return(m_lastImgSet);
                }

                foreach (DatasetEx2 ds in m_rgDatasets)
                {
                    ImageSet2 imgSet = ds.Find(nSourceID);

                    if (imgSet != null)
                    {
                        m_lastImgSet = imgSet;
                        return(imgSet);
                    }
                }

                throw new Exception("Could not find source with ID = " + nSourceID.ToString() + "!");
            }
        }
Beispiel #5
0
        /// <summary>
        /// Releases all resources used.
        /// </summary>
        /// <param name="bDisposing">Set to <i>true</i> when called by Dispose().</param>
        protected virtual void Dispose(bool bDisposing)
        {
            m_ds = null;

            StopAutomaticRefreshSchedule(true, true);

            if (m_TestingImages != null)
            {
                m_TestingImages.Dispose();
                m_TestingImages = null;
            }

            if (m_TrainingImages != null)
            {
                m_TrainingImages.Dispose();
                m_TrainingImages = null;
            }

            if (m_factory != null)
            {
                m_factory.Dispose();
                m_factory = null;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Initialize the DatasetEx by loading the training and testing data sources into memory.
        /// </summary>
        /// <param name="ds">Specifies the dataset to load.</param>
        /// <param name="rgAbort">Specifies a set of wait handles used to cancel the load.</param>
        /// <param name="nPadW">Optionally, specifies a pad to apply to the width of each item (default = 0).</param>
        /// <param name="nPadH">Optionally, specifies a pad to apply to the height of each item (default = 0).</param>
        /// <param name="log">Optionally, specifies an external Log to output status (default = null).</param>
        /// <param name="loadMethod">Optionally, specifies the load method to use (default = LOAD_ALL).</param>
        /// <param name="bSkipMeanCheck">Optionally, specifies to skip the mean check (default = false).</param>
        /// <param name="nImageDbLoadLimit">Optionally, specifies the load limit (default = 0).</param>
        /// <param name="nImageDbAutoRefreshScheduledUpdateInMs">Optionally, specifies the scheduled refresh update period in ms (default = 0).</param>
        /// <param name="dfImageDbAutoRefreshScheduledReplacementPct">Optionally, specifies the scheduled refresh replacement percent (default = 0).</param>
        /// <returns>Upon loading the dataset a handle to the default QueryState is returned, or 0 on cancel.</returns>
        public long Initialize(DatasetDescriptor ds, WaitHandle[] rgAbort, int nPadW = 0, int nPadH = 0, Log log = null, IMAGEDB_LOAD_METHOD loadMethod = IMAGEDB_LOAD_METHOD.LOAD_ALL, bool bSkipMeanCheck = false, int nImageDbLoadLimit = 0, int nImageDbAutoRefreshScheduledUpdateInMs = 0, double dfImageDbAutoRefreshScheduledReplacementPct = 0)
        {
            lock (m_syncObj)
            {
                m_log = log;

                if (ds != null)
                {
                    m_ds = ds;
                }

                if (m_ds.TrainingSource.ImageWidth == -1 || m_ds.TrainingSource.ImageHeight == -1)
                {
                    log.WriteLine("WARNING: Cannot create a mean image for data sources that contain variable sized images.  The mean check will be skipped.");
                    bSkipMeanCheck = true;
                }

                bool bSilentLoad = (loadMethod == IMAGEDB_LOAD_METHOD.LOAD_ON_DEMAND_BACKGROUND) ? true : false;

                m_TrainingImages = new ImageSet2(ImageSet2.TYPE.TRAIN, log, m_factory, m_ds.TrainingSource, loadMethod, m_random, rgAbort);
                m_TrainingImages.OnCalculateImageMean += OnCalculateImageMean;
                QueryState  qsTraining = m_TrainingImages.Initialize(bSilentLoad, true, true, nImageDbLoadLimit);
                SimpleDatum sdMean     = null;

                if (!bSkipMeanCheck)
                {
                    bool bQueryOnly = false;
                    if (EntitiesConnection.GlobalDatabaseConnectInfo.Location == ConnectInfo.TYPE.AZURE)
                    {
                        bQueryOnly = true;
                    }

                    sdMean = m_TrainingImages.GetImageMean(log, rgAbort, bQueryOnly);
                }

                if (EventWaitHandle.WaitAny(rgAbort, 0) != EventWaitHandle.WaitTimeout)
                {
                    return(0);
                }

                m_TestingImages = new ImageSet2(ImageSet2.TYPE.TEST, log, m_factory, m_ds.TestingSource, loadMethod, m_random, rgAbort);
                m_TestingImages.OnCalculateImageMean += OnCalculateImageMean;
                QueryState qsTesting = m_TestingImages.Initialize(bSilentLoad, true, true, nImageDbLoadLimit);

                if (!bSkipMeanCheck)
                {
                    bool bSave = true;
                    if (EntitiesConnection.GlobalDatabaseConnectInfo.Location == ConnectInfo.TYPE.AZURE)
                    {
                        bSave = false;
                    }

                    m_TestingImages.SetImageMean(sdMean, bSave);
                }

                if (EventWaitHandle.WaitAny(rgAbort, 0) != EventWaitHandle.WaitTimeout)
                {
                    return(0);
                }

                if (loadMethod == IMAGEDB_LOAD_METHOD.LOAD_ALL && nImageDbAutoRefreshScheduledUpdateInMs > 0 && dfImageDbAutoRefreshScheduledReplacementPct > 0)
                {
                    StartAutomaticRefreshSchedule(true, true, nImageDbAutoRefreshScheduledUpdateInMs, dfImageDbAutoRefreshScheduledReplacementPct);
                }

                m_lDefaultQueryState = m_queryStates.CreateNewState(qsTraining, qsTesting);
                return(m_lDefaultQueryState);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Resets the last image set used to <i>null</i>, thus clearing it.
 /// </summary>
 public void Reset()
 {
     m_lastImgSet = null;
 }