예제 #1
0
        /// <summary>
        /// Returns the image mean for the ImageSet.
        /// </summary>
        /// <param name="log">Specifies the Log used to output status.</param>
        /// <param name="rgAbort">Specifies a set of wait handles for aborting the operation.</param>
        /// <param name="bQueryOnly">Specifies whether or not to only query for the mean and not calculate if missing.</param>
        /// <returns>The SimpleDatum with the image mean is returned.</returns>
        public SimpleDatum GetImageMean(Log log, WaitHandle[] rgAbort, bool bQueryOnly)
        {
            if (m_imgMean != null || bQueryOnly)
            {
                return(m_imgMean);
            }

            int nLoadedCount = GetLoadedCount();
            int nTotalCount  = GetTotalCount();

            if (nLoadedCount < nTotalCount)
            {
                double dfPct = (double)nLoadedCount / (double)nTotalCount;

                if (log != null)
                {
                    log.WriteLine("WARNING: Cannot create the image mean until all images have loaded - the data is currently " + dfPct.ToString("P") + " loaded.");
                }

                return(null);
            }

            if (OnCalculateImageMean != null)
            {
                CalculateImageMeanArgs args = new CalculateImageMeanArgs(m_rgImages);
                OnCalculateImageMean(this, args);

                if (args.Cancelled)
                {
                    return(null);
                }

                m_imgMean = args.ImageMean;
                return(m_imgMean);
            }

            RawImageMean imgMean = m_factory.GetRawImageMean();

            if (m_imgMean != null)
            {
                m_imgMean = m_factory.LoadDatum(imgMean);
            }
            else
            {
                log.WriteLine("Calculating mean...");
                m_imgMean = SimpleDatum.CalculateMean(log, m_rgImages, rgAbort);
                m_factory.PutRawImageMean(m_imgMean, true);
            }

            m_imgMean.SetLabel(0);

            return(m_imgMean);
        }
예제 #2
0
        /// <summary>
        /// Returns the image mean for the ImageSet.
        /// </summary>
        /// <param name="log">Specifies the Log used to output status.</param>
        /// <param name="rgAbort">Specifies a set of wait handles for aborting the operation.</param>
        /// <returns>The SimpleDatum with the image mean is returned.</returns>
        public SimpleDatum GetImageMean(Log log, WaitHandle[] rgAbort)
        {
            if (m_imgMean != null)
            {
                return(m_imgMean);
            }

            if (m_rgImages.Length == 0)
            {
                if (log != null)
                {
                    log.WriteLine("WARNING: Cannot create image mean with no images!");
                }
                return(null);
            }

            if (m_loadMethod != IMAGEDB_LOAD_METHOD.LOAD_ALL)
            {
                throw new Exception("Can only create image mean when using LOAD_ALL.");
            }

            if (m_nLoadLimit != 0)
            {
                throw new Exception("Can only create image mean when LoadLimit = 0.");
            }

            if (OnCalculateImageMean != null)
            {
                CalculateImageMeanArgs args = new CalculateImageMeanArgs(m_rgImages);
                OnCalculateImageMean(this, args);

                if (args.Cancelled)
                {
                    return(null);
                }

                m_imgMean = args.ImageMean;
                return(m_imgMean);
            }

            m_imgMean = SimpleDatum.CalculateMean(log, m_rgImages, rgAbort);
            m_imgMean.SetLabel(0);

            return(m_imgMean);
        }
예제 #3
0
        private bool loadXmlAnnotationFile(Log log, string strFile, SimpleDatum datum, Dictionary <string, int> rgNameToLabel)
        {
            XDocument doc  = XDocument.Load(strFile);
            XElement  size = doc.Descendants("size").First();
            XElement  val;

            val = size.Descendants("width").First();
            int nWidth = int.Parse(val.Value);

            val = size.Descendants("height").First();
            int nHeight = int.Parse(val.Value);

            val = size.Descendants("depth").First();
            int nChannels = int.Parse(val.Value);

            if (datum.Height != nHeight || datum.Width != nWidth || datum.Channels != nChannels)
            {
                log.FAIL("Inconsistent image size, expected (" + datum.Channels.ToString() + "," + datum.Height.ToString() + "," + datum.Width.ToString() + ") but annotation has size (" + nChannels.ToString() + "," + nHeight.ToString() + "," + nWidth.ToString() + ").");
            }

            int nInstanceId = 0;

            List <XElement> objects = doc.Descendants("object").ToList();

            foreach (XElement obj in objects)
            {
                val = obj.Descendants("name").First();
                string strName = val.Value;

                val = obj.Descendants("difficult").First();
                bool bDifficult = (val.Value == "0") ? false : true;

                XElement bndbox = obj.Descendants("bndbox").First();

                val = bndbox.Descendants("xmin").First();
                float fxmin = float.Parse(val.Value);
                if (fxmin > nWidth || fxmin < 0)
                {
                    log.WriteLine("WARNING: '" + strFile + "' bounding box exceeds image boundary.");
                }

                val = bndbox.Descendants("ymin").First();
                float fymin = float.Parse(val.Value);
                if (fymin > nHeight || fymin < 0)
                {
                    log.WriteLine("WARNING: '" + strFile + "' bounding box exceeds image boundary.");
                }

                val = bndbox.Descendants("xmax").First();
                float fxmax = float.Parse(val.Value);
                if (fxmax > nWidth || fxmax < 0)
                {
                    log.WriteLine("WARNING: '" + strFile + "' bounding box exceeds image boundary.");
                }

                val = bndbox.Descendants("ymax").First();
                float fymax = float.Parse(val.Value);
                if (fymax > nHeight || fymax < 0)
                {
                    log.WriteLine("WARNING: '" + strFile + "' bounding box exceeds image boundary.");
                }

                if (!rgNameToLabel.ContainsKey(strName))
                {
                    log.FAIL("Could not find the label '" + strName + "' in the label mapping!");
                    return(false);
                }

                int            nLabel = rgNameToLabel[strName];
                NormalizedBBox bbox   = new NormalizedBBox(fxmin / nWidth, fymin / nHeight, fxmax / nWidth, fymax / nHeight, nLabel, bDifficult);
                datum.SetLabel(nLabel);

                foreach (AnnotationGroup g in datum.annotation_group)
                {
                    if (nLabel == g.group_label)
                    {
                        if (g.annotations.Count == 0)
                        {
                            nInstanceId = 0;
                        }
                        else
                        {
                            nInstanceId = g.annotations[g.annotations.Count - 1].instance_id + 1;
                        }

                        g.annotations.Add(new Annotation(bbox, nInstanceId));
                        bbox = null;
                        break;
                    }
                }

                if (bbox != null)
                {
                    nInstanceId = 0;
                    AnnotationGroup grp = new AnnotationGroup(null, nLabel);
                    grp.annotations.Add(new Annotation(bbox, nInstanceId));
                    datum.annotation_group.Add(grp);
                    bbox = null;
                }
            }

            return(true);
        }