Iterate matrix and copy out [closed]
Hi all, Hi all, I have a problem with some matrix operations. I have one matrix MatOriginal and I want copy out into another one, only the range from (0,0) to (300,300). So I try to iterate the original one (MatOriginal) and copy out, my code is:
a = 0; b = 0;
for(int x = 0; x < 300; x++)
{
for(int y = 0; y < 300; y++)
{
MatNew.at<int>(a,b) = MatOriginal.at<int>(x,y);
a++;
}
b++;
}
But this doesn't works... anyone can help me please?
2 things wrong with your mat.at() there:
in the end, you don't need those loops at all, you can just copy one region to another:
MatOriginal.copyTo( MatNew( Rect(0,0,300,300) );