Filtering operations involve convolutions and the filtered value at position (x,y)
will also depend on the intensities of pixels (x-a,y-b)
with a,b >0
.
So using directly as destination the same image will lead to unexpected behaviors because during calculation I'm taking some already-filtered data instead of original ones.
Does opencv
manage this issue internally in functions like cv::GaussianBlur(.)
, cv::blur
, etc? Is it safe to give a reference to the same Mat
to both src
and dst
parameters?
thanks
Working of Mat () Function in OpenCV Mat is a class in OpenCV consisting of two data parts namely matrix header and a pointer to the matrix. The information like size of the matrix, the method used for storing the matrix, the address at which the matrix must be stored etc. is available in the matrix header.
Scalar &s specifies the value to be stored in the matrix. Mat is a class in OpenCV consisting of two data parts namely matrix header and a pointer to the matrix. The information like size of the matrix, the method used for storing the matrix, the address at which the matrix must be stored etc. is available in the matrix header.
OpenCV program in C++ to create a matrix using Mat function and display the matrix as the output on the screen. In the above program, we are including the necessary headers. Then we are defining the namespaces std and cv.
To tackle this issue OpenCV uses a reference counting system. The idea is that each Mat object has its own header, however a matrix may be shared between two Mat objects by having their matrix pointers point to the same address. Moreover, the copy operators will only copy the headers and the pointer to the large matrix, not the data itself.
Yes, there would not be any problem if you do so. I have done such thing several time. openCV will automatically take care of it.
I tested the following code and it works perfect:
int main(int argc, char* argv[])
{
Mat src;
src = imread("myImage.jpeg", 1);
imshow("src", src); //Original src
cv::blur( src, src, Size(25,25) , Point(-1,-1), BORDER_DEFAULT );
imshow("dst", src); //src after blurring
waitKey(0);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With