private void writeFeature(HaarFeatureNode node)
        {
            writer.Write("new HaarFeatureNode({0}, {1}, {2}, ",
                         node.Threshold.ToString("R", NumberFormatInfo.InvariantInfo),
                         node.LeftValue.ToString("R", NumberFormatInfo.InvariantInfo),
                         node.RightValue.ToString("R", NumberFormatInfo.InvariantInfo));

            if (node.Feature.Tilted)
            {
                writer.Write("true, ");
            }

            // Write Haar-like rectangular features
            for (int k = 0; k < node.Feature.Rectangles.Length; k++)
            {
                writeRectangle(node.Feature.Rectangles[k]);

                if (k < node.Feature.Rectangles.Length - 1)
                {
                    writer.Write(", ");
                }
            }

            writer.Write(" )");
        }
Beispiel #2
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        ///
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        ///
        public object Clone()
        {
            HaarFeatureNode[][] newTrees = new HaarFeatureNode[Trees.Length][];

            for (int i = 0; i < newTrees.Length; i++)
            {
                HaarFeatureNode[] tree    = Trees[i];
                HaarFeatureNode[] newTree = newTrees[i] =
                    new HaarFeatureNode[tree.Length];

                for (int j = 0; j < newTree.Length; j++)
                {
                    newTree[j] = (HaarFeatureNode)tree[j].Clone();
                }
            }

            HaarCascadeStage r = new HaarCascadeStage();

            r.NextIndex   = NextIndex;
            r.ParentIndex = ParentIndex;
            r.Threshold   = Threshold;
            r.Trees       = newTrees;

            return(r);
        }
        public bool Classify(IntegralImage2 image, int x, int y, double factor)
        {
            double value = 0;

            // For each feature in the feature tree of the current stage,
            foreach (HaarFeatureNode[] tree in Trees)
            {
                int current = 0;

                do
                {
                    // Get the feature node from the tree
                    HaarFeatureNode node = tree[current];

                    // Evaluate the node's feature
                    double sum = node.Feature.GetSum(image, x, y);

                    // And increase the value accumulator
                    if (sum < node.Threshold * factor)
                    {
                        value  += node.LeftValue;
                        current = node.LeftNodeIndex;
                    }
                    else
                    {
                        value  += node.RightValue;
                        current = node.RightNodeIndex;
                    }
                } while (current > 0);

                // Stop early if we have already surpassed the stage threshold value.
                //if (value >= this.Threshold)
                //    return true;
            }

            // After we have evaluated the output for the
            //  current stage, we will check if the value
            //  is still lesser than the stage threshold.
            if (value < this.Threshold)
            {
                // If it is, the stage has rejected the current
                // image and it doesn't contains our object.
                return(false);
            }
            else
            {
                // The stage has accepted the current image
                return(true);
            }
        }
Beispiel #4
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        ///
        public object Clone()
        {
            HaarFeatureNode r = new HaarFeatureNode();

            r.Feature   = (HaarFeature)Feature.Clone();
            r.Threshold = Threshold;

            r.RightValue = RightValue;
            r.LeftValue  = LeftValue;

            r.LeftNodeIndex  = leftNodeIndex;
            r.RightNodeIndex = rightNodeIndex;

            return(r);
        }
        private void writeFeature(HaarFeatureNode node)
        {

            writer.Write("new HaarFeatureNode({0}, {1}, {2}, ",
                node.Threshold.ToString("R", NumberFormatInfo.InvariantInfo),
                node.LeftValue.ToString("R", NumberFormatInfo.InvariantInfo),
                node.RightValue.ToString("R", NumberFormatInfo.InvariantInfo));

            if (node.Feature.Tilted)
                writer.Write("true, ");

            // Write Haar-like rectangular features
            for (int k = 0; k < node.Feature.Rectangles.Length; k++)
            {
                writeRectangle(node.Feature.Rectangles[k]);

                if (k < node.Feature.Rectangles.Length - 1)
                    writer.Write(", ");
            }

            writer.Write(" )");
        }
Beispiel #6
0
        private void equals(HaarFeatureNode expected, HaarFeatureNode actual)
        {
            Assert.AreNotEqual(expected, actual);

            Assert.AreEqual(expected.LeftNodeIndex, actual.LeftNodeIndex);
            Assert.AreEqual(expected.LeftValue, actual.LeftValue);
            Assert.AreEqual(expected.RightNodeIndex, actual.RightNodeIndex);
            Assert.AreEqual(expected.RightValue, actual.RightValue);
            Assert.AreEqual(expected.Threshold, actual.Threshold);

            equals(expected.Feature, actual.Feature);
        }
Beispiel #7
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        /// 
        public object Clone()
        {
            HaarFeatureNode r = new HaarFeatureNode();

            r.Feature = (HaarFeature)Feature.Clone();
            r.Threshold = Threshold;

            r.RightValue = RightValue;
            r.LeftValue = LeftValue;

            r.LeftNodeIndex = leftNodeIndex;
            r.RightNodeIndex = rightNodeIndex;

            return r;
        }
Beispiel #8
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        /// 
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        /// 
        public object Clone()
        {
            HaarFeatureNode[][] newTrees = new HaarFeatureNode[Trees.Length][];

            for (int i = 0; i < newTrees.Length; i++)
            {
                HaarFeatureNode[] tree = Trees[i];
                HaarFeatureNode[] newTree = newTrees[i] =
                    new HaarFeatureNode[tree.Length];

                for (int j = 0; j < newTree.Length; j++)
                    newTree[j] = (HaarFeatureNode)tree[j].Clone();
            }

            HaarCascadeStage r = new HaarCascadeStage();
            r.NextIndex = NextIndex;
            r.ParentIndex = ParentIndex;
            r.Threshold = Threshold;
            r.Trees = newTrees;

            return r;
        }