Ask Your Question
1

Set Matrix Values with Ranges

asked 2012-08-16 03:51:57 -0500

Ederman gravatar image

Dear all, I am newly learning OpenCV, and now trying to allocate some values to a matrix within some range. My code is like this:

for ( int row = 0, i = 0; row < srcMat.rows; ++row, i ++ )
{
   uchar* p = medianMat.ptr ( row );
   for ( int col = 0, j = 0; col < srcMat.cols; ++ col, j ++ )
   {
   dstMat ( cv::Range::all(), cv::Range ( i * 5 +1, i * 5 + 4 )).setTo ( *p );
   data++;
   }
}

My problem here is, the "dstMat" is all zero outside the for loop. Besides, this code uses about 70-80 ms for each video frame, but I need at most 30 ms. Is there any more efficient way to do this? And how could I let "dstMat" keep those values outside the loop? Many thanks in advance. With regards.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-08-16 03:24:13 -0500

Ice_T02 gravatar image

updated 2016-08-16 03:24:24 -0500

Hello, i am not quite sure what your goal is. However regarding your issues:

1) Declare the matrix outside the for loop. Use something like cout << "Destination Matrix: " << dstMat<< endl; to check the values within the console.

2) Here is a good tutorial about an efficient way to loop trough the image Link

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-08-16 03:51:57 -0500

Seen: 720 times

Last updated: Aug 16 '12