<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 4.0.0</li>
<li>Operating System / Platform =&gt; Windows7</li>
<li>Compiler =&gt; VS</li>
</ul>
<h5 dir="auto">Detailed description</h5>

<p dir="auto">In <code class="notranslate">haarfeatures.cpp</code> in OpenCV I see the following implementation for V &amp; J Haar features:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" void CvHaarEvaluator::generateFeatures()
{
    int mode = ((const CvHaarFeatureParams*)((CvFeatureParams*)featureParams))-&gt;mode;
    int offset = winSize.width + 1;
    for( int x = 0; x &lt; winSize.width; x++ )
    {
        for( int y = 0; y &lt; winSize.height; y++ )
        {
            for( int dx = 1; dx &lt;= winSize.width; dx++ )
            {
                for( int dy = 1; dy &lt;= winSize.height; dy++ )
                {
                    // haar_x2
                    if ( (x+dx*2 &lt;= winSize.width) &amp;&amp; (y+dy &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x,    y, dx*2, dy, -1,
                            x+dx, y, dx  , dy, +2 ) );
                    }
                    // haar_y2
                    if ( (x+dx &lt;= winSize.width) &amp;&amp; (y+dy*2 &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x,    y, dx, dy*2, -1,
                            x, y+dy, dx, dy,   +2 ) );
                    }
                    // haar_x3
                    if ( (x+dx*3 &lt;= winSize.width) &amp;&amp; (y+dy &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x,    y, dx*3, dy, -1,
                            x+dx, y, dx  , dy, +3 ) );
                    }
                    // haar_y3
                    if ( (x+dx &lt;= winSize.width) &amp;&amp; (y+dy*3 &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x, y,    dx, dy*3, -1,
                            x, y+dy, dx, dy,   +3 ) );
                    }
                    // x2_y2
                    if ( (x+dx*2 &lt;= winSize.width) &amp;&amp; (y+dy*2 &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x,    y,    dx*2, dy*2, -1,
                            x,    y,    dx,   dy,   +2,
                            x+dx, y+dy, dx,   dy,   +2 ) );
                    }

                }
            }
        }
    }
    numFeatures = (int)features.size();
} "><pre class="notranslate"><code class="notranslate"> void CvHaarEvaluator::generateFeatures()
{
    int mode = ((const CvHaarFeatureParams*)((CvFeatureParams*)featureParams))-&gt;mode;
    int offset = winSize.width + 1;
    for( int x = 0; x &lt; winSize.width; x++ )
    {
        for( int y = 0; y &lt; winSize.height; y++ )
        {
            for( int dx = 1; dx &lt;= winSize.width; dx++ )
            {
                for( int dy = 1; dy &lt;= winSize.height; dy++ )
                {
                    // haar_x2
                    if ( (x+dx*2 &lt;= winSize.width) &amp;&amp; (y+dy &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x,    y, dx*2, dy, -1,
                            x+dx, y, dx  , dy, +2 ) );
                    }
                    // haar_y2
                    if ( (x+dx &lt;= winSize.width) &amp;&amp; (y+dy*2 &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x,    y, dx, dy*2, -1,
                            x, y+dy, dx, dy,   +2 ) );
                    }
                    // haar_x3
                    if ( (x+dx*3 &lt;= winSize.width) &amp;&amp; (y+dy &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x,    y, dx*3, dy, -1,
                            x+dx, y, dx  , dy, +3 ) );
                    }
                    // haar_y3
                    if ( (x+dx &lt;= winSize.width) &amp;&amp; (y+dy*3 &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x, y,    dx, dy*3, -1,
                            x, y+dy, dx, dy,   +3 ) );
                    }
                    // x2_y2
                    if ( (x+dx*2 &lt;= winSize.width) &amp;&amp; (y+dy*2 &lt;= winSize.height) )
                    {
                        features.push_back( Feature( offset, false,
                            x,    y,    dx*2, dy*2, -1,
                            x,    y,    dx,   dy,   +2,
                            x+dx, y+dy, dx,   dy,   +2 ) );
                    }

                }
            }
        }
    }
    numFeatures = (int)features.size();
} 
</code></pre></div>
<p dir="auto">Where each feature is represented by two (haar_x2, haar_y2, haar_x3, haar_y3) or three (x2_y2) rectangles and <strong>corresponding weights</strong> in order to compute the feature from the integral image.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="inline float CvHaarEvaluator::Feature::calc( const cv::Mat &amp;_sum, const cv::Mat &amp;_tilted, size_t y) const
{
    const int* img = tilted ? _tilted.ptr&lt;int&gt;((int)y) : _sum.ptr&lt;int&gt;((int)y);
    float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) +
        rect[1].weight * (img[fastRect[1].p0] - img[fastRect[1].p1] - img[fastRect[1].p2] + img[fastRect[1].p3] );
    if( rect[2].weight != 0.0f )
        ret += rect[2].weight * (img[fastRect[2].p0] - img[fastRect[2].p1] - img[fastRect[2].p2] + img[fastRect[2].p3] );
    return ret;
}"><pre class="notranslate"><code class="notranslate">inline float CvHaarEvaluator::Feature::calc( const cv::Mat &amp;_sum, const cv::Mat &amp;_tilted, size_t y) const
{
    const int* img = tilted ? _tilted.ptr&lt;int&gt;((int)y) : _sum.ptr&lt;int&gt;((int)y);
    float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) +
        rect[1].weight * (img[fastRect[1].p0] - img[fastRect[1].p1] - img[fastRect[1].p2] + img[fastRect[1].p3] );
    if( rect[2].weight != 0.0f )
        ret += rect[2].weight * (img[fastRect[2].p0] - img[fastRect[2].p1] - img[fastRect[2].p2] + img[fastRect[2].p3] );
    return ret;
}
</code></pre></div>
<p dir="auto">For haar_x2 the configuration is:</p>
<p dir="auto"><a href="https://i.stack.imgur.com/uS6WH.png" rel="nofollow"><img src="https://camo.githubusercontent.com/18ba84726d5c264f90bf84d9cfcef257c697025614a113887e45b31faa5fef17/68747470733a2f2f692e737461636b2e696d6775722e636f6d2f75533657482e706e67" alt="enter image description here" data-canonical-src="https://i.stack.imgur.com/uS6WH.png" style="max-width: 100%;"></a></p>
<p dir="auto">so the first rectangle <code class="notranslate">(x, y, dx*2, dy)</code> represents the sum A+B (with weight -1)<br>
and the second rectangle <code class="notranslate">(x+dx, y, dx, dy)</code> represents just B (with weight +2)<br>
summing up with weights gives -(A + B) + 2 * B = B - A as it should. the same holds for haar_y2</p>
<p dir="auto">for x2_y2 the configuration is:</p>
<p dir="auto"><a href="https://i.stack.imgur.com/zWzKo.png" rel="nofollow"><img src="https://camo.githubusercontent.com/6ba309f087983faec533564c207fd37c575528b8202d21cf968e087276a07cc4/68747470733a2f2f692e737461636b2e696d6775722e636f6d2f7a577a4b6f2e706e67" alt="enter image description here" data-canonical-src="https://i.stack.imgur.com/zWzKo.png" style="max-width: 100%;"></a></p>
<p dir="auto">Here the first rectangle <code class="notranslate">(x, y, dx*2, dy*2)</code> represents (A + B + C + D),<br>
the second rectangle <code class="notranslate">(x, y, dx, dy)</code> represents A<br>
and the third rectangle <code class="notranslate">(x+dx, y+dy, dx, dy)</code> represents D<br>
so with weights we get -(A + B + C + D) + 2 * A + 2 * D = A + D - (B + C)<br>
as we should.</p>
<p dir="auto"><strong>But</strong> for haar_x3 (and y3) the configuration is:</p>
<p dir="auto"><a href="https://i.stack.imgur.com/2fyGl.png" rel="nofollow"><img src="https://camo.githubusercontent.com/8d9d2f203079e424c1bf05b14ce9d400425ebaa89472341ff3b65cc9ab17472b/68747470733a2f2f692e737461636b2e696d6775722e636f6d2f326679476c2e706e67" alt="enter image description here" data-canonical-src="https://i.stack.imgur.com/2fyGl.png" style="max-width: 100%;"></a></p>
<p dir="auto">so the first rectangle <code class="notranslate">(x, y, dx*3, dy)</code> represents (A + B + C)<br>
and the second rectangle <code class="notranslate">(x+dx, y, dx, dy)</code> represents B.</p>
<p dir="auto">Now, with weights we get -(A + B + C) + <strong>3*B</strong>  = 2 * B - (A + C)<br>
while the V &amp; J paper states that</p>
<blockquote>
<p dir="auto">"A three rectangle feature computes the sum within two outside<br>
rectangles substracted from the sum in the center rectangle"</p>
</blockquote>
<p dir="auto"><a href="https://i.stack.imgur.com/Hffw5.png" rel="nofollow"><img src="https://camo.githubusercontent.com/efa665a761f5f9e528568181c1f5d08b2495654ceaeb50f017c5978ac60f8432/68747470733a2f2f692e737461636b2e696d6775722e636f6d2f48666677352e706e67" alt="enter image description here" data-canonical-src="https://i.stack.imgur.com/Hffw5.png" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>I read this as B - (A + C) and not 2 * B - (A + C)!.</strong></p>
<p dir="auto">Am I missing something here? or is this a bug? can anyone confirm this?</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Can anyone suggest how to create pbtxt file for architecture other than ssd, mask -rcnn and faster-rcnn.</p>

<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; <g-emoji class="g-emoji" alias="grey_question" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2754.png">❔</g-emoji></li>
<li>Operating System / Platform =&gt; <g-emoji class="g-emoji" alias="grey_question" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2754.png">❔</g-emoji></li>
<li>Compiler =&gt; <g-emoji class="g-emoji" alias="grey_question" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2754.png">❔</g-emoji></li>
</ul>
<h5 dir="auto">Detailed description</h5>

<h5 dir="auto">Steps to reproduce</h5>