I have this matrix,
0 1 0
1 0 1
0 1 0
And I want to toggle each 1-valued elements to 0 and vice versa:
1 0 1
0 1 0
1 0 1
If I use the bitwise complement operator i.e. dst = ~src I got this result
255 254 255
254 255 254
255 254 255
Of cource I can get the result I want with some arithmetic and looping. But is there any easy way to achieve the matrix I want in OpenCV? Thanks.
Update:
Here is the code snippet:
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
int main()
{
cv::Mat a = (cv::Mat_<uchar>(3,3) << 0, 1, 0,
1, 0, 1,
0, 1, 0 );
cv::Mat b = ~a;
std::cout << b << std::endl;
return 0;
}
If you have only ones and zeros, you can do this:
cv::Mat b = 1 - a;
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