Beispiel #1
0
        public frmNnClassifier(NnClassifier classifier, frmMain frmMain)
        {
            InitializeComponent();
            _frmMain    = frmMain;
            _classifier = classifier;

            FillWithConfiguration();
        }
Beispiel #2
0
        public void RejectPatches()
        {
            // arrange - create object model
            ObjectModelStub objectModel = new ObjectModelStub();

            // arrange - create scanning window generator with dummy windows
            ScanningWindowGeneratorStub swg = new ScanningWindowGeneratorStub();

            swg.ScanningWindows = new IBoundingBox[]
            {
                new BoundingBox(new PointF(10, 10), new SizeF(5, 5)),
                new BoundingBox(new PointF(10, 10), new SizeF(5, 5)),
                new BoundingBox(new PointF(10, 10), new SizeF(5, 5)),
            };

            // arrange - create nn classifier
            NnClassifier classifier = new NnClassifier(swg, objectModel, 0.75f, 0.6f);

            classifier.PostInstantiation();
            classifier.Initialize(new Image <Gray, byte>(new Size(0, 0)), new BoundingBox(new PointF(), new SizeF()));

            // arrange - hard code relative similarities of patches in scanning windows
            // 1. relative similarity of the patch in the first scanning window
            // is below the threshold -> scanning window is rejected
            // 2. relative similarity of the patch in the second scanning window
            // is the same as the threshold -> scanning window is rejected
            // 3. relative similarity of the patch in the third scanning window
            // is above the threshold -> scanning window is accepted
            objectModel.RelativeSimilarities = new List <float>()
            {
                0.1f, 0.6f, 0.9f
            };
            objectModel.PnnSimilarities = new List <float>()
            {
                0, 0.9f, 0.9f
            };
            objectModel.NnnSimilarities = new List <float>()
            {
                1, 0.9f, 0
            };

            // define expected accepted scanning windows
            List <int> expected = new List <int>()
            {
                2
            };

            // get actual accepted scanning windows
            List <int> actual = classifier.AcceptedWindows(new Image <Gray, byte>(new Size(1, 1)), new List <int>()
            {
                0, 1, 2
            });

            // assert
            CollectionAssert.AreEqual(expected, actual);
        }
Beispiel #3
0
        public void RejectPatches()
        {
            // arrange - create object model
            IObjectModel objectModel = new ObjectModel(new Size(15, 15));

            objectModel.PostInstantiation();
            // -> create 2 positive and 2 negative patches
            Image <Gray, byte> helpImage = new Image <Gray, byte>(Path.Combine(_resourceDir, "violeta_1.jpg"));
            Image <Gray, byte> posPatch1 = helpImage.GetPatch(new PointF(168, 178), new Size(80, 40)).Resize(objectModel.PatchSize.Width, objectModel.PatchSize.Height, INTER.CV_INTER_LINEAR);
            Image <Gray, byte> posPatch2 = helpImage.GetPatch(new PointF(169, 179), new Size(81, 41)).Resize(objectModel.PatchSize.Width, objectModel.PatchSize.Height, INTER.CV_INTER_LINEAR);
            Image <Gray, byte> negPatch1 = helpImage.GetPatch(new PointF(300, 200), new Size(50, 50)).Resize(objectModel.PatchSize.Width, objectModel.PatchSize.Height, INTER.CV_INTER_LINEAR);
            Image <Gray, byte> negPatch2 = helpImage.GetPatch(new PointF(200, 300), new Size(50, 50)).Resize(objectModel.PatchSize.Width, objectModel.PatchSize.Height, INTER.CV_INTER_LINEAR);

            // -> add patches to the object model
            objectModel.AddPositivePatch(posPatch1);
            objectModel.AddPositivePatch(posPatch2);
            objectModel.AddNegativePatch(negPatch1);
            objectModel.AddNegativePatch(negPatch2);

            // arrange - create scanning window generator with stub windows
            ScanningWindowGeneratorStub swg = new ScanningWindowGeneratorStub();

            swg.ScanningWindows = new IBoundingBox[]
            {
                new BoundingBox(new PointF(167, 177), new SizeF(79, 39)),
                new BoundingBox(new PointF(300, 300), new SizeF(80, 40))
            };

            // arrange - create classifier
            NnClassifier classifier = new NnClassifier(swg, objectModel, 0.75f, 0.6f);

            classifier.PostInstantiation();
            classifier.Initialize(new Image <Gray, byte>(new Size(0, 0)), new BoundingBox(new PointF(), new SizeF()));

            // define expected accepted patches
            List <int> expected = new List <int>()
            {
                0
            };

            // get actual accepted patches
            List <int> actual = classifier.AcceptedWindows(helpImage, new List <int>()
            {
                0, 1
            });

            // assert
            CollectionAssert.AreEqual(expected, actual);
        }
Beispiel #4
0
        public void RejectPatches_FrameRoiIsNotSetAfterProcessing()
        {
            // arrange - create object model
            IObjectModel objectModel = new ObjectModel(new Size(15, 15));

            objectModel.PostInstantiation();
            // -> create 1 patch
            Image <Gray, byte> helpImage = new Image <Gray, byte>(Path.Combine(_resourceDir, "violeta_1.jpg"));
            Image <Gray, byte> patch     = helpImage.GetPatch(new PointF(168, 178), new Size(80, 40)).Resize(objectModel.PatchSize.Width, objectModel.PatchSize.Height, INTER.CV_INTER_LINEAR);

            // -> add patch to the object model
            objectModel.AddPositivePatch(patch);

            // arrange - create scanning window generator with stub windows
            ScanningWindowGeneratorStub swg = new ScanningWindowGeneratorStub();

            swg.ScanningWindows = new IBoundingBox[]
            {
                new BoundingBox(new PointF(167, 177), new SizeF(79, 39))
            };

            // arrange - create classifier
            NnClassifier classifier = new NnClassifier(swg, objectModel, 0.75f, 0.6f);

            classifier.PostInstantiation();
            classifier.Initialize(new Image <Gray, byte>(new Size(0, 0)), new BoundingBox(new PointF(), new SizeF()));

            // define expected frame ROI after processing
            Rectangle expected = new Rectangle(new Point(), helpImage.Size);

            // get actual frame ROI after processing
            classifier.AcceptedWindows(helpImage, new List <int>()
            {
                0
            });
            Rectangle actual = helpImage.ROI;

            // assert
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(!helpImage.IsROISet);  // just in case
        }
Beispiel #5
0
        private static IDetector LoadDetector(IObjectModel objectModel)
        {
            // scanning window generator
            IScanningWindowGenerator scanningWindowGenerator = new ScanningWindowGenerator
                                                               (
                1.2f,
                0.1f,
                0.1f,
                100
                                                               );

            // cascaded classifier

            //      variance classifier
            IClassifier varianceClassifier = new VarianceClassifier(scanningWindowGenerator, 0.5);

            //      ensemble classifier
            int width  = objectModel.PatchSize.Width;
            int height = objectModel.PatchSize.Height;
            IPixelComparisonScheduler pcs  = new PixelComparisonScheduler(12, 3, width, height);
            IClassifier ensembleClassifier = new EnsembleClassifier(scanningWindowGenerator, pcs, 2);

            //      nn classifier
            NnClassifier nnClassifier = new NnClassifier(scanningWindowGenerator, objectModel, 0.75f, 0.55f);

            // instantiate cascaded classifier
            IClassifier cascadedClassifier = new CascadedClassifier(varianceClassifier, ensembleClassifier, nnClassifier);

            IDetector detector = new Detector
                                 (
                scanningWindowGenerator,
                cascadedClassifier,
                Service.NonMaximalBoundingBoxSuppress
                                 );

            return(detector);
        }
Beispiel #6
0
        public Learner(
            IObjectModel objectModel,
            IDetector detector,
            PositivePatchSynthesisInfo initPositivePatchSysthesisInfo,
            NegativePatchPickingInfo initNegativePatchPickingInfo,
            PositivePatchSynthesisInfo runtimePositivePatchSysthesisInfo,
            NegativePatchPickingInfo runtimeNegativePatchPickingInfo,
            float sameSimilarityThreshold,
            float validConservativeSimilarityThreshold
            )
        {
            _objectModel = objectModel;
            _detector    = detector;
            _initPositivePatchSynthesisInfo       = initPositivePatchSysthesisInfo;
            _initNegativePatchPickingInfo         = initNegativePatchPickingInfo;
            _runtimePosPatchSynthesisInfo         = runtimePositivePatchSysthesisInfo;
            _runtimeNegativePatchPickingInfo      = runtimeNegativePatchPickingInfo;
            _sameSimilarityThreshold              = sameSimilarityThreshold;
            _validConservativeSimilarityThreshold = validConservativeSimilarityThreshold;

            _varianceClassifier = ((_detector as Detector).CascadedClassifier as CascadedClassifier).VarianceClassifier as VarianceClassifier;
            _ensembleClassifier = ((_detector as Detector).CascadedClassifier as CascadedClassifier).EnsembleClassifier as EnsembleClassifier;
            _nnClassifier       = ((_detector as Detector).CascadedClassifier as CascadedClassifier).NnClassifier as NnClassifier;
        }