Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

copy row from one Mat to another (is it safe to pad descriptors with 0s)

$
0
0
I am putting all the descriptors for multiple images from an ORB detector into one Mat to feed to cv::flann::index->build. Here is the code I am trying. EDIT: I guess the main question right now. Is it safe to pad the descriptors with zeros at the end to make them the same number of columns? while (true) { buffer = indexBuilder.value("descriptors").toString().toStdString(); Mat mat; Mat matonerow; FileStorage fs(buffer,FileStorage::READ | FileStorage::MEMORY | FileStorage::FORMAT_YAML); fs["descriptors"] >> mat; fs.release(); matonerow = mat.reshape(1,1); qDebug() << "matonerow cols" << matonerow.cols << "rows" << matonerow.rows; indexTemp.push_back(matonerow); progress->setValue(iterations); iterations++; if (!indexBuilder.next()) break; } the problem is that some of the descriptors are smaller, so the call to push_back fails with OpenCV Error: Sizes of input arguments do not match () in push_back, file /tmp/opencv320160111-57911-i2x9h0/opencv-3.1.0/modules/core/src/matrix.cpp, line 834 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv320160111-57911-i2x9h0/opencv-3.1.0/modules/core/src/matrix.cpp:834: error: (-209) in function push_back so how do I copy the one row mat to the tempindex mat? NOTE: I am using mat because I intend to convert it to UMat before passing it to build the index so I can take advantage of opencl through TAPI. UPDATE: ok it works now but only for rows with the same amount of columns, which is no better than push_back so I still need another method! try { if (iterations == 1) indexTemp = Mat(row_count,matonerow.cols,CV_8U); matonerow.copyTo(indexTemp.row(iterations - 1)); } catch (Exception e) { qCritical() << "failed to copy row of Mat at loop" << iterations << e.err.c_str() << e.msg.c_str(); } NOTE: iterations starts at 1

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>