So, have you already covered steps 1 and 2 in openCV? If you're just trying to use logical operators, openCV gives you access to raw data that you can work with logical operators. Assuming you are already divided into three channels and a threshold value
r now contains your output. You can also copy it to a new matrix if you do not want to overwrite r.
There are several ways to iterate through cv :: Mat and access all data points, while C ++ provides all the logical operators you might want. As far as I know, openCV does not provide matrix logical operator functions, but you can write your own very easily, as shown above.
Edit As suggested by QuentinGeissmann, you can accomplish the same thing using the bitwise_not and bitwise_and functions. I did not know that they exist. I suspect that using them will be slower due to how many times the data needs to be iterated, but this can be done in less code.
cv::bitwise_not(g,g); cv::bitwise_not(b,b); cv::bitwise_and(b,g,b); cv::bitwise_and(r,b,r);
source share