Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

copy row from one Mat to another

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.

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.

copy row from one Mat to another

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.

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: instead of push_back I also tried:

    try
    {
        if (iterations == 1)
        {
            indexTemp = Mat(row_count,matonerow.cols,CV_8U);
            matonerow.copyTo(indexTemp);
        }
        else
            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();
    }

and got

0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows /tmp/opencv320160111-57911-i2x9h0/opencv-3.1.0/modules/core/src/matrix.cpp:469: error: (-215) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function Mat

copy row from one Mat to another

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.

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: instead of push_back I also tried:

    try
    {
        if (iterations == 1)
        {
            indexTemp = Mat(row_count,matonerow.cols,CV_8U);
            matonerow.copyTo(indexTemp);
        }
        else
            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 and got

0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows /tmp/opencv320160111-57911-i2x9h0/opencv-3.1.0/modules/core/src/matrix.cpp:469: error: (-215) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function Mat

copy row from one Mat to another

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.

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: instead of ok it works now but only for rows with the same amount of columns, which is no better than push_back I also tried:so I still need another method!

    try
    {
        if (iterations == 1)
        {
            indexTemp = Mat(row_count,matonerow.cols,CV_8U);
            matonerow.copyTo(indexTemp);
        }
        else
             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 and got

0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows /tmp/opencv320160111-57911-i2x9h0/opencv-3.1.0/modules/core/src/matrix.cpp:469: error: (-215) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function Mat

copy row from one Mat to another

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.

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 and got

0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows /tmp/opencv320160111-57911-i2x9h0/opencv-3.1.0/modules/core/src/matrix.cpp:469: error: (-215) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function Mat
1

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

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