Iterate matrix and copy out [closed]

asked 2014-01-14 03:06:43 -0500

Deus gravatar image

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++)
  <int>(a,b) =<int>(x,y);


But this doesn't works... anyone can help me please?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-26 15:26:24.800420



2 things wrong with your there:

  • it's (y,x) not (x,y)
  • the type inside the braces has to match the Mat type, so either<uchar> or<Vec3b>

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) );

berak gravatar imageberak ( 2014-01-14 03:19:50 -0500 )edit