I am using the following code for video frames to set matrix values with some range:
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++;
}
}
I need to copy the *p to three consecutive values of dstMat, and left one zero space before and after them. That is, if my dstMat is all zero, and *p values are “1,2,3”, then my goal is to make dstMat look like” “01110 02220 03330”, etc. I hope I made this easy to understand.
My problem here is: it uses about 70 to 80 milliseconds for one frame, which is too slow for my case. I at most have 30 ms for a single frame. Is there any more efficient way for doing this?
Besides, the “dstMat” values are all zero outside the “for” loop. Do you have any ideas? Thank you very much.
somthing like
You can use cv::zeros to init a new cv::mat to zero