Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

copy selected row of a matrix to another

Hi,

Thanks for answering my previous question. I have one more related issue.

I am still a little confused with the at operator for unknown type matrix.

// copy select rows into a new matrix

Mat indices; // n*1 matrix storing the row index, up to index 165600

Mat dst;

Mat src; // n*2 matrix

void copy_matrix(Mat &src, Mat &dst, Mat &indices)

{

for (int i=0; i<indices.rows; i++)

{
    // now copy the row vector
        Mat M1;
    src.row(indices.at<unsigned int>(i,1)).copyTo(M1);
    dst.push_back(M1);
}

}

The above code can pass the debug procedure. However, when I run the code, it gives the following error. The matrix indices has the data type int ( 0 to 4294967295). Therefore, the return type should be correct. I don't know which part goes wrong. I also tried at<int>, at<uchar> or other data types. But the error remains. Much appreciated for your help.

Error: assertion failed, <dims &lt;="2" &amp;&amp;="" data="" &amp;&amp;="" <unsigned=""> i0 << unsigned >size.p[0]

click to hide/show revision 2
improved style

copy selected row of a matrix to another

Hi,

Thanks for answering my previous question. I have one more related issue.

I am still a little confused with the at operator for unknown type matrix.

 // copy select rows into a new matrix

matrix Mat indices; // n*1 matrix storing the row index, up to index 165600

Mat dst;

165600 Mat dst; Mat src; // n*2 matrix

matrix void copy_matrix(Mat &src, Mat &dst, Mat &indices)

{

&indices) {
for (int i=0; i<indices.rows; i++)
i++) {
// now copy the row vector
Mat M1;
src.row(indices.at<unsigned int>(i,1)).copyTo(M1);
dst.push_back(M1);
 }
}

}

The above code can pass the debug procedure. However, when I run the code, it gives the following error. The matrix indices has the data type int ( 0 to 4294967295). Therefore, the return type should be correct. I don't know which part goes wrong. I also tried at<int>, at<uchar> or other data types. But the error remains. Much appreciated for your help.

 Error: assertion failed, <dims &lt;="2" &amp;&amp;="" data="" &amp;&amp;="" <unsigned=""> <=2 && data && <unsigned> i0 << unsigned >size.p[0]

>size.p[0]

copy selected row of a matrix to another

Hi,

Thanks for answering my previous question. I have one more related issue.

I am still a little confused with the at operator for unknown type matrix.

 // copy select rows into a new matrix
 Mat indices; // n*1 matrix storing the row index, up to index 165600
 Mat dst;
 Mat src; // n*2 matrix

  void copy_matrix(Mat &src, Mat &dst, Mat &indices) {
  for (int i=0; i<indices.rows; i++) {
    // now copy the row vector
        Mat M1;
    src.row(indices.at<unsigned int>(i,1)).copyTo(M1);
    dst.push_back(M1);
   }
  }

The above code can pass the debug procedure. However, when I run the code, it gives the following error. The matrix indices has the data type int ( 0 to 4294967295). Therefore, the return type should be correct. I don't know which part goes wrong. I also tried at<int>, at<uchar> or other data types. But the error remains. Much appreciated for your help.

  Error: assertion failed, <dims <=2 && data && <unsigned> i0 << unsigned >size.p[0]

Update:

The error has disappeared. However, the program still crashes in the middle. And the debug shows error in memcpy.asm

UnwindUp2: mov eax,[esi+ecx*4-8] ;U(entry)/V(not) - get dword from source ;V(entry) - spare

What was the underlying reason for this issue?