How to make Mat as new whenever the function called again? [closed]
.
Mat rowPaddedImage;
//Row filter
int filter_size = 7;
int h = filter_size / 2;
int top, bottom, left, right;
top = bottom = left = right = h;
Scalar value(0, 0, 0);
copyMakeBorder(double_src, rowPaddedImage, 0, 0, left, right, BORDER_CONSTANT, value);
for (int i = 0; i < rowPaddedImage.rows; i++) //For img
{
for (int j = h; j < rowPaddedImage.cols - h; j++) //For img
{
for (int l = 0; l < f_size; l++)
{
colPaddedImage.at<Vec3d>(i + h, j - h)[0] += rowPaddedImage.at<Vec3d>(i, j - h + l)[0] * filter[l];
colPaddedImage.at<Vec3d>(i + h, j - h)[1] += rowPaddedImage.at<Vec3d>(i, j - h + l)[1] * filter[l];
colPaddedImage.at<Vec3d>(i + h, j - h)[2] += rowPaddedImage.at<Vec3d>(i, j - h + l)[2] * filter[l];
}
}
}
//The row "rowPaddedImage" is getting bigger and bigger after the row filter function is being called. If I called twice the padded row borders is 6 it is twice, if I call thrice it become three time the padded size.
DON'T write code like that.
Mat.at()
should NEVER be used for a whole image.can you instead try to tell us, what you're trying to achieve with it ? what's the goal / purpose here ? it for surecan bedone easier / safer.
I want to make the separable convolution (row filter and column filter) to a given image. And save the filtered image for the other processing.
I cannot use the filter2D function from OpenCV and have to write manually the convolution process. What is the optimal way to access image pixels? I'm a novice to OpenCV. Please guide me.
again, please try to use seperable filters ,NOT write loops
Can I use the like the following? filter1 is :