Esempio n. 1
0
        public static SampleCollection LoadPosSamples(string dir, bool isPositive, ColorType colorType)
        {
            if (false == Directory.Exists(dir))
            {
                throw new DirectoryNotFoundException(string.Format("目录\"{0}\"不存在", dir));
            }
            string[]         files = ListImageFiles(dir);
            SampleCollection coll  = new SampleCollection(files.Length * 4);

            foreach (string filename in files)
            {
                Image <Bgr, Byte> img = new Image <Bgr, Byte>(filename);
                ISample           sample;

                sample = new HaarSample(img, isPositive, colorType);
                coll.Add(sample);

                img._Flip(FLIP.HORIZONTAL);
                sample = new HaarSample(img, isPositive, colorType);
                coll.Add(sample);

                img._Flip(FLIP.VERTICAL);
                sample = new HaarSample(img, isPositive, colorType);
                coll.Add(sample);

                img._Flip(FLIP.HORIZONTAL);
                sample = new HaarSample(img, isPositive, colorType);
                coll.Add(sample);
            }
            return(coll);
        }
Esempio n. 2
0
        public SampleCollection GetNegSamples(int maxSampleNum)
        {
            int[]            indices = RandomList(_samples.Count, maxSampleNum);
            SampleCollection coll    = new SampleCollection(indices.Length);

            foreach (int i in indices)
            {
                coll.Add(_samples[i]);
            }
            return(coll);
        }
Esempio n. 3
0
        /// <summary>
        /// 使用当前的级联分类器对负目标negSamples进行分类,返回错分的目标,作为新的负样本集negSamples
        /// </summary>
        /// <param name="negSamples"></param>
        /// <returns></returns>
        private SampleCollection GetPositivePredictedSamples(SampleCollection samplecoll)
        {
            SampleCollection newCollection = new SampleCollection(samplecoll.Count);

            foreach (ISample sample in samplecoll)
            {
                if (true == this.Predict(sample))
                {
                    newCollection.Add(sample);
                }
            }
            newCollection.TrimExcess();
            return(newCollection);
        }