Issue 1:
System information (version)

OpenCV => 3.4.0

Operating System / Platform =>Windows 10

Compiler => Visual Studio 10

Detailed description

vector subscript out of range during trainAuto with default parameters

This originates here: svm.cpp line 1448

//check that while cross-validation there were the samples from all the classes
if( class_ranges[class_count] <= 0 )
CV_Error( CV_StsBadArg, "While cross-validation one or more of the classes have "
"been fell out of the sample. Try to reduce <Params::k_fold>" );

class_ranges have a size of 5 and class_count is 5

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.

Steps to reproduce

cv::Mat trainDataProjected;
cv::Mat trainLabels;
{
cv::FileStorage file("trainDataProjected.xml", cv::FileStorage::READ);
file["trainDataProjected"] >> trainDataProjected;
}
{
cv::FileStorage file("trainLabels.xml", cv::FileStorage::READ);
file["trainLabels"] >> trainLabels;
}

auto svm = cv::ml::SVM::create();
svm->setType(cv::ml::SVM::NU_SVC);
svm->setKernel(cv::ml::SVM::RBF);
svm->setNu(0.5);
svm->trainAuto(trainDataProjected,cv::ml::ROW_SAMPLE,trainLabels);

Data:

tmp.zip

Issue 2:
System information (version)

OpenCV => ❔ 4.1.2

Operating System / Platform => ❔ macOS 10.15

Compiler => ❔ CMake

Detailed description

Build error when compiling gfluidbuffer.cpp

/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr<cv::gapi::fluid::BufferStorage> 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<cv::gapi::fluid::BufferStorageWithBorder>' lvalue to 'std::unique_ptr<cv::gapi::fluid::BufferStorageWithBorder>&&'
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<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Up, _Ep>&&) [with _Up = cv::gapi::fluid::BufferStorageWithBorder; _Ep = std::default_delete<cv::gapi::fluid::BufferStorageWithBorder>; <template-parameter-2-3> = void; _Tp = cv::gapi::fluid::BufferStorage; _Dp = std::default_delete<cv::gapi::fluid::BufferStorage>]'
unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:355:12: error: cannot bind 'std::unique_ptr<cv::gapi::fluid::BufferStorageWithoutBorder>' lvalue to 'std::unique_ptr<cv::gapi::fluid::BufferStorageWithoutBorder>&&'
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<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Up, _Ep>&&) [with _Up = cv::gapi::fluid::BufferStorageWithoutBorder; _Ep = std::default_delete<cv::gapi::fluid::BufferStorageWithoutBorder>; <template-parameter-2-3> = void; _Tp = cv::gapi::fluid::BufferStorage; _Dp = std::default_delete<cv::gapi::fluid::BufferStorage>]'
unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr<cv::gapi::fluid::BufferStorage> cv::gapi::fluid::{anonymous}::createStorage(const cv::gapi::own::Mat&, cv::gapi::own::Rect)':
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp:363:12: error: cannot bind 'std::unique_ptr<cv::gapi::fluid::BufferStorageWithoutBorder>' lvalue to 'std::unique_ptr<cv::gapi::fluid::BufferStorageWithoutBorder>&&'
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<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Up, _Ep>&&) [with _Up = cv::gapi::fluid::BufferStorageWithoutBorder; _Ep = std::default_delete<cv::gapi::fluid::BufferStorageWithoutBorder>; <template-parameter-2-3> = void; _Tp = cv::gapi::fluid::BufferStorage; _Dp = std::default_delete<cv::gapi::fluid::BufferStorage>]'
unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
^
/opencv/modules/gapi/src/backends/fluid/gfluidbuffer.cpp: In function 'std::unique_ptr<cv::gapi::fluid::BufferStorage> 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<cv::gapi::fluid::BufferStorage> cv::gapi::fluid::{anonymous}::createStorage(const cv::gapi::own::Mat&, 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

Steps to reproduce

```
git clone git clone https://github.com/opencv/opencv.git
cd opencv/
mkdir build
cd build
cmake ..
```