0
正如許多人之前,我有一個assertation錯誤的問題,我不能夠解決這個問題我自己......這是我的代碼 - 片段:斷言失敗,CopyTo從功能(C++)
void tuneParameters(cv::Ptr<cv::ml::KNearest>& classifier, cv::Mat& trainDataMat, cv::Mat& trainLabels, int k[], cv::Mat classes){
//Split Data in 10 random folds to do cross validation
int n = trainDataMat.rows;
std::vector <int> seeds;
for (int cont = 0; cont < n; cont++)
seeds.push_back(cont);
cv::randShuffle(seeds);
int n10 = floor(n/10);
cv::Mat train(n10*9, 3, CV_32F);
trainDataMat.copyTo(train(Rect(0,0,3,n10*9)));
...followed by the parameter tuning step
}
trainDataMat
是該數據類型:
cv::Mat trainDataMat(32505, 3, CV_32F);
當我運行,與.copyTo行我得到的錯誤:
OpenCV Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows)) in create, file /home/aschuett/cppWS/opencv-3.2.0/modules/core/src/matrix.cpp, line 2287
terminate called after throwing an instance of 'cv::Exception'
what(): /home/aschuett/cppWS/opencv-3.2.0/modules/core/src/matrix.cpp:2287: error: (-215) !fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows) in function create
我通過各種論壇條目閱讀,並找不到我的問題的解決方案...我用調試器檢查了我的矩陣的大小,但它們是相應的,trainDataMat有cls:3和行:32505,train has cols: 3和行:29250。
也許別人可以看到我在做什麼錯了嗎?是否可以使用Rect()函數?
非常感謝!乾杯
你嘗試切換行'trainDataMat.copyTo(train(Rect(0,0,3,n10 * 9))); 'to trainDataMat.copyTo(train(Rect(0,0,n10 * 9,3)));'? –
Jap,然後錯誤信息變爲'Assertion failed(0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows)'。所以我想我的尺寸是正確的... – Seastar