/// <summary> /// Returns the image based on its label and image selection method. /// </summary> /// <param name="nIdx">Specifies the image index to use when loading sequentially.</param> /// <param name="labelSelectionMethod">Specifies the label selection method.</param> /// <param name="imageSelectionMethod">Specifies the image selection method.</param> /// <param name="log">Specifies the Log for status output.</param> /// <param name="bLoadDataCriteria">Specifies to load the data criteria data (default = false).</param> /// <param name="bLoadDebugData">Specifies to load the debug data (default = false).</param> /// <returns>The SimpleDatum containing the image is returned.</returns> public SimpleDatum GetImage(int nIdx, IMGDB_LABEL_SELECTION_METHOD labelSelectionMethod, IMGDB_IMAGE_SELECTION_METHOD imageSelectionMethod, Log log, bool bLoadDataCriteria = false, bool bLoadDebugData = false) { lock (m_syncObj) { SimpleDatum[] rgImages = m_rgImages; if (m_nLoadLimit > 0 && m_rgImagesLimitLoaded.Count == m_nLoadLimit) { rgImages = m_rgImagesLimitLoaded.ToArray(); } if (rgImages.Length == 0) { throw new Exception("There are no images in the dataset '" + m_src.Name + "' to select from!"); } SimpleDatum sd = null; if ((labelSelectionMethod & IMGDB_LABEL_SELECTION_METHOD.RANDOM) == IMGDB_LABEL_SELECTION_METHOD.RANDOM) { if (m_rgLabelSet.Count == 0) { throw new Exception("There are no label specified in the Labels table for the dataset '" + m_src.Name + "'!"); } LabelSet labelSet = getLabelSet(labelSelectionMethod); sd = labelSet.GetImage(nIdx, imageSelectionMethod); } int nImageIdx = 0; if (sd == null) { sd = LabelSet.GetImage(rgImages, rgImages.Length, nIdx, m_random, imageSelectionMethod, ref m_nLastIdx, ref m_nFixedIndex, out nImageIdx); } //----------------------------------------- // Handle dynamic loading of the image. //----------------------------------------- bool bRawDataLoaded = false; if (sd == null) { int nRetries = 1; if ((imageSelectionMethod & IMGDB_IMAGE_SELECTION_METHOD.RANDOM) == IMGDB_IMAGE_SELECTION_METHOD.RANDOM) { nRetries = 5; } for (int i = 0; i < nRetries; i++) { sd = m_factory.LoadImageAt(nImageIdx, bLoadDataCriteria, bLoadDebugData); if (sd != null) { bRawDataLoaded = true; Add(nImageIdx, sd); break; } if (i < nRetries - 1) { nImageIdx = m_random.Next(rgImages.Length); } } if (sd == null) { log.WriteLine("WARNING! The dataset needs to be re-indexed. Could not find the image at index " + nImageIdx.ToString() + " - attempting several random queries to get an image."); } } if (!bRawDataLoaded) { m_factory.LoadRawData(sd, bLoadDebugData, bLoadDataCriteria); } return(sd); } }
/// <summary> /// Directly load an image, preempting the backgroud load - used by LOAD_ON_DEMAND for images not already loaded. /// </summary> /// <param name="nIdx">Specifies the image index.</param> /// <returns>The image at the image index is returned.</returns> private SimpleDatum directLoadImage(int nIdx) { return(m_factory.LoadImageAt(nIdx)); }