The result of the bitwise or operation between 2 and 3 is 3. You can check it like this:
cout<<(2|3); // The result will be 3
Also, if you do a bitwise_or
on two matrices that have all pixels 2 and 3 respectively, you should get a matrix with all its pixels set to 3, like in this example:
Mat m1 = Mat(3, 3, CV_8UC1, Scalar(2));
Mat m2 = Mat(3, 3, CV_8UC1, Scalar(3));
Mat r;
bitwise_or(m1, m2, r);
cout<<r;
Result:
[3, 3, 3;
3, 3, 3;
3, 3, 3]
Do you want to add the two images? If this is the case, you can simply use the +
operator, like this:
Mat m1 = Mat(3, 3, CV_8UC1, Scalar(2));
Mat m2 = Mat(3, 3, CV_8UC1, Scalar(3));
Mat r = m1+m2;
cout<<r;
Result:
[5, 5, 5;
5, 5, 5;
5, 5, 5]
In decimal system, the equivalent of the or operation is the maximum operation. (Also, the equivalent of the and operation is the minimum operation).
If this is what you want, OpenCV provides a cv::max()
function that calculates the elementwise maximum from two matrices of the same size. Here is an example:
Mat a = Mat::ones(3, 3, CV_8UC1) * 2;
Mat b = Mat::ones(3, 3, CV_8UC1) * 100;
cout<<a<<endl<<b<<endl;
Mat max = cv::max(a, b);
cout<<max;
The result is:
a=[2, 2, 2;
2, 2, 2;
2, 2, 2]
b=[100, 100, 100;
100, 100, 100;
100, 100, 100]
max=[100, 100, 100;
100, 100, 100;
100, 100, 100]