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

<ul dir="auto">
<li>OpenCV =&gt; 3.4.0</li>
<li>Operating System / Platform =&gt;Windows 10</li>
<li>Compiler =&gt; Visual Studio 10</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">vector subscript out of range during trainAuto with default parameters</p>
<p dir="auto">This originates here: svm.cpp line 1448</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" //check that while cross-validation there were the samples from all the classes
            if( class_ranges[class_count] &lt;= 0 )
                CV_Error( CV_StsBadArg, &quot;While cross-validation one or more of the classes have &quot;
                &quot;been fell out of the sample. Try to reduce &lt;Params::k_fold&gt;&quot; );"><pre class="notranslate"><code class="notranslate"> //check that while cross-validation there were the samples from all the classes
            if( class_ranges[class_count] &lt;= 0 )
                CV_Error( CV_StsBadArg, "While cross-validation one or more of the classes have "
                "been fell out of the sample. Try to reduce &lt;Params::k_fold&gt;" );
</code></pre></div>
<p dir="auto">class_ranges have a size of 5 and class_count is 5</p>
<p dir="auto">I am aware that in the example I am training the svm with an inadequate and small sample set, and that with small sample set or with underrepresented classes the kfold should be adjusted.</p>
<h5 dir="auto">Steps to reproduce</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  cv::Mat trainDataProjected;
       cv::Mat trainLabels;
      {
        cv::FileStorage file(&quot;trainDataProjected.xml&quot;, cv::FileStorage::READ);
        file[&quot;trainDataProjected&quot;] &gt;&gt; trainDataProjected;
      }
      {
        cv::FileStorage file(&quot;trainLabels.xml&quot;, cv::FileStorage::READ);
        file[&quot;trainLabels&quot;] &gt;&gt; trainLabels;
      }

      auto svm = cv::ml::SVM::create();
      svm-&gt;setType(cv::ml::SVM::NU_SVC);
      svm-&gt;setKernel(cv::ml::SVM::RBF);
      svm-&gt;setNu(0.5);
      svm-&gt;trainAuto(trainDataProjected,cv::ml::ROW_SAMPLE,trainLabels);"><pre class="notranslate"><code class="notranslate">  cv::Mat trainDataProjected;
       cv::Mat trainLabels;
      {
        cv::FileStorage file("trainDataProjected.xml", cv::FileStorage::READ);
        file["trainDataProjected"] &gt;&gt; trainDataProjected;
      }
      {
        cv::FileStorage file("trainLabels.xml", cv::FileStorage::READ);
        file["trainLabels"] &gt;&gt; trainLabels;
      }

      auto svm = cv::ml::SVM::create();
      svm-&gt;setType(cv::ml::SVM::NU_SVC);
      svm-&gt;setKernel(cv::ml::SVM::RBF);
      svm-&gt;setNu(0.5);
      svm-&gt;trainAuto(trainDataProjected,cv::ml::ROW_SAMPLE,trainLabels);
</code></pre></div>
<p dir="auto">Data:<br>
<a href="https://github.com/opencv/opencv/files/2495186/tmp.zip">tmp.zip</a></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> 4.1.2</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> macOS 10.15</li>
<li>Compiler =&gt; ❔ CMake</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">Build error when compiling gfluidbuffer.cpp</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorage&gt; cv::gapi::fluid::{anonymous}::createStorage(int, int, int, int, cv::gapi::fluid::BorderOpt)':
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:350:16: error: cannot bind 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithBorder&gt;' lvalue to 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithBorder&gt;&amp;&amp;'
         return storage;
                ^
In file included from /usr/local/include/c++/4.9.4/memory:81:0,
                 from /opencv/modules/core/include/opencv2/core/cvstd_wrapper.hpp:11,
                 from /opencv/modules/core/include/opencv2/core/cvstd.hpp:81,
                 from /opencv/modules/core/include/opencv2/core/base.hpp:58,
                 from /opencv/modules/core/include/opencv2/core.hpp:54,
                 from /opencv/modules/gapi/src/precomp.hpp:12,
                 from /opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:8:
/usr/local/include/c++/4.9.4/bits/unique_ptr.h:220:2: note: initializing argument 1 of 'std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(std::unique_ptr&lt;_Up, _Ep&gt;&amp;&amp;) [with _Up = cv::gapi::fluid::BufferStorageWithBorder; _Ep = std::default_delete&lt;cv::gapi::fluid::BufferStorageWithBorder&gt;; &lt;template-parameter-2-3&gt; = void; _Tp = cv::gapi::fluid::BufferStorage; _Dp = std::default_delete&lt;cv::gapi::fluid::BufferStorage&gt;]'
  unique_ptr(unique_ptr&lt;_Up, _Ep&gt;&amp;&amp; __u) noexcept
  ^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:355:12: error: cannot bind 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;' lvalue to 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;&amp;&amp;'
     return storage;
            ^
In file included from /usr/local/include/c++/4.9.4/memory:81:0,
                 from /opencv/modules/core/include/opencv2/core/cvstd_wrapper.hpp:11,
                 from /opencv/modules/core/include/opencv2/core/cvstd.hpp:81,
                 from /opencv/modules/core/include/opencv2/core/base.hpp:58,
                 from /opencv/modules/core/include/opencv2/core.hpp:54,
                 from /opencv/modules/gapi/src/precomp.hpp:12,
                 from /opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:8:
/usr/local/include/c++/4.9.4/bits/unique_ptr.h:220:2: note: initializing argument 1 of 'std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(std::unique_ptr&lt;_Up, _Ep&gt;&amp;&amp;) [with _Up = cv::gapi::fluid::BufferStorageWithoutBorder; _Ep = std::default_delete&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;; &lt;template-parameter-2-3&gt; = void; _Tp = cv::gapi::fluid::BufferStorage; _Dp = std::default_delete&lt;cv::gapi::fluid::BufferStorage&gt;]'
  unique_ptr(unique_ptr&lt;_Up, _Ep&gt;&amp;&amp; __u) noexcept
  ^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorage&gt; cv::gapi::fluid::{anonymous}::createStorage(const cv::gapi::own::Mat&amp;, cv::gapi::own::Rect)':
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:363:12: error: cannot bind 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;' lvalue to 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;&amp;&amp;'
     return storage;
            ^
In file included from /usr/local/include/c++/4.9.4/memory:81:0,
                 from /opencv/modules/core/include/opencv2/core/cvstd_wrapper.hpp:11,
                 from /opencv/modules/core/include/opencv2/core/cvstd.hpp:81,
                 from /opencv/modules/core/include/opencv2/core/base.hpp:58,
                 from /opencv/modules/core/include/opencv2/core.hpp:54,
                 from /opencv/modules/gapi/src/precomp.hpp:12,
                 from /opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:8:
/usr/local/include/c++/4.9.4/bits/unique_ptr.h:220:2: note: initializing argument 1 of 'std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(std::unique_ptr&lt;_Up, _Ep&gt;&amp;&amp;) [with _Up = cv::gapi::fluid::BufferStorageWithoutBorder; _Ep = std::default_delete&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;; &lt;template-parameter-2-3&gt; = void; _Tp = cv::gapi::fluid::BufferStorage; _Dp = std::default_delete&lt;cv::gapi::fluid::BufferStorage&gt;]'
  unique_ptr(unique_ptr&lt;_Up, _Ep&gt;&amp;&amp; __u) noexcept
  ^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorage&gt; cv::gapi::fluid::{anonymous}::createStorage(int, int, int, int, cv::gapi::fluid::BorderOpt)':
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:356:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorage&gt; cv::gapi::fluid::{anonymous}::createStorage(const cv::gapi::own::Mat&amp;, cv::gapi::own::Rect)':
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:364:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1plus: some warnings being treated as errors"><pre class="notranslate"><code class="notranslate">/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorage&gt; cv::gapi::fluid::{anonymous}::createStorage(int, int, int, int, cv::gapi::fluid::BorderOpt)':
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:350:16: error: cannot bind 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithBorder&gt;' lvalue to 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithBorder&gt;&amp;&amp;'
         return storage;
                ^
In file included from /usr/local/include/c++/4.9.4/memory:81:0,
                 from /opencv/modules/core/include/opencv2/core/cvstd_wrapper.hpp:11,
                 from /opencv/modules/core/include/opencv2/core/cvstd.hpp:81,
                 from /opencv/modules/core/include/opencv2/core/base.hpp:58,
                 from /opencv/modules/core/include/opencv2/core.hpp:54,
                 from /opencv/modules/gapi/src/precomp.hpp:12,
                 from /opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:8:
/usr/local/include/c++/4.9.4/bits/unique_ptr.h:220:2: note: initializing argument 1 of 'std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(std::unique_ptr&lt;_Up, _Ep&gt;&amp;&amp;) [with _Up = cv::gapi::fluid::BufferStorageWithBorder; _Ep = std::default_delete&lt;cv::gapi::fluid::BufferStorageWithBorder&gt;; &lt;template-parameter-2-3&gt; = void; _Tp = cv::gapi::fluid::BufferStorage; _Dp = std::default_delete&lt;cv::gapi::fluid::BufferStorage&gt;]'
  unique_ptr(unique_ptr&lt;_Up, _Ep&gt;&amp;&amp; __u) noexcept
  ^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:355:12: error: cannot bind 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;' lvalue to 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;&amp;&amp;'
     return storage;
            ^
In file included from /usr/local/include/c++/4.9.4/memory:81:0,
                 from /opencv/modules/core/include/opencv2/core/cvstd_wrapper.hpp:11,
                 from /opencv/modules/core/include/opencv2/core/cvstd.hpp:81,
                 from /opencv/modules/core/include/opencv2/core/base.hpp:58,
                 from /opencv/modules/core/include/opencv2/core.hpp:54,
                 from /opencv/modules/gapi/src/precomp.hpp:12,
                 from /opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:8:
/usr/local/include/c++/4.9.4/bits/unique_ptr.h:220:2: note: initializing argument 1 of 'std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(std::unique_ptr&lt;_Up, _Ep&gt;&amp;&amp;) [with _Up = cv::gapi::fluid::BufferStorageWithoutBorder; _Ep = std::default_delete&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;; &lt;template-parameter-2-3&gt; = void; _Tp = cv::gapi::fluid::BufferStorage; _Dp = std::default_delete&lt;cv::gapi::fluid::BufferStorage&gt;]'
  unique_ptr(unique_ptr&lt;_Up, _Ep&gt;&amp;&amp; __u) noexcept
  ^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorage&gt; cv::gapi::fluid::{anonymous}::createStorage(const cv::gapi::own::Mat&amp;, cv::gapi::own::Rect)':
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:363:12: error: cannot bind 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;' lvalue to 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;&amp;&amp;'
     return storage;
            ^
In file included from /usr/local/include/c++/4.9.4/memory:81:0,
                 from /opencv/modules/core/include/opencv2/core/cvstd_wrapper.hpp:11,
                 from /opencv/modules/core/include/opencv2/core/cvstd.hpp:81,
                 from /opencv/modules/core/include/opencv2/core/base.hpp:58,
                 from /opencv/modules/core/include/opencv2/core.hpp:54,
                 from /opencv/modules/gapi/src/precomp.hpp:12,
                 from /opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:8:
/usr/local/include/c++/4.9.4/bits/unique_ptr.h:220:2: note: initializing argument 1 of 'std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(std::unique_ptr&lt;_Up, _Ep&gt;&amp;&amp;) [with _Up = cv::gapi::fluid::BufferStorageWithoutBorder; _Ep = std::default_delete&lt;cv::gapi::fluid::BufferStorageWithoutBorder&gt;; &lt;template-parameter-2-3&gt; = void; _Tp = cv::gapi::fluid::BufferStorage; _Dp = std::default_delete&lt;cv::gapi::fluid::BufferStorage&gt;]'
  unique_ptr(unique_ptr&lt;_Up, _Ep&gt;&amp;&amp; __u) noexcept
  ^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorage&gt; cv::gapi::fluid::{anonymous}::createStorage(int, int, int, int, cv::gapi::fluid::BorderOpt)':
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:356:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr&lt;cv::gapi::fluid::BufferStorage&gt; cv::gapi::fluid::{anonymous}::createStorage(const cv::gapi::own::Mat&amp;, cv::gapi::own::Rect)':
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:364:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1plus: some warnings being treated as errors
</code></pre></div>
<h5 dir="auto">Steps to reproduce</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="```
git clone git clone https://github.com/opencv/opencv.git
cd opencv/
mkdir build
cd build
cmake ..
```"><pre class="notranslate"><code class="notranslate">```
git clone git clone https://github.com/opencv/opencv.git
cd opencv/
mkdir build
cd build
cmake ..
```
</code></pre></div>